ppt4j 1.0
 
Loading...
Searching...
No Matches
ppt4j.util.StringUtils Class Reference

Static Public Member Functions

static String printSet (Set<?> set)
 
static String printSet (Set<?> set, boolean emphasizeString, boolean printType)
 
static String convertToDescriptor (String type)
 
static boolean isPrimitive (String type)
 
static String convertMethodSignature (String nameAndArgs, String returnType)
 
static String convertQualifiedName (String name, String className)
 
static String convertQualifiedName (String name, String className, boolean retainClassName)
 
static boolean isJavaComment (String line)
 
static boolean isJavaCode (String line)
 
static String trimJavaCodeLine (String codeLine)
 
static Main.Command matchPrefix (String prefix)
 
static byte[] toBytes (List< String > lines)
 
static URL toURL (String path)
 
static String extractClassName (String filePath, String topLevelPrefix)
 
static String buildMethodSignature (MethodInsnNode minsn, BasicValue[] args)
 
static String substringBetween (String str, char c1, char c2)
 
static String toWrapperType (String type)
 
static String resolvePath (String path)
 
static String[] splitArgDesc (String desc)
 
static String joinArgDesc (List< String > descList)
 
static String getDatabasePrepatchSrcPath (Vulnerability vuln)
 
static String getDatabasePostpatchSrcPath (Vulnerability vuln)
 
static String getDatabasePrepatchClassPath (Vulnerability vuln)
 
static String getDatabasePostpatchClassPath (Vulnerability vuln)
 
static String[] getThirdPartySrcDirsFromPrepatch (Vulnerability vuln)
 
static String[] getThirdPartyLibDirsFromPrepatch (Vulnerability vuln)
 
static int extractDatabaseId (String name)
 
static String getJavaSrcTopLevelDir (VulnerabilityInfo info)
 
static String buildNewStringArrayCode (String[] arr)
 
static String getThirdPartySrcDirsString (VulnerabilityInfo info)
 
static String getClassPathToLoad (Vulnerability vuln)
 
static String getThirdPartyLibDirsString (VulnerabilityInfo info)
 

Member Function Documentation

◆ buildMethodSignature()

static String ppt4j.util.StringUtils.buildMethodSignature ( MethodInsnNode minsn,
BasicValue[] args )
static

Builds a method signature based on the given MethodInsnNode and arguments.

This method extracts the return type from the MethodInsnNode and concatenates it with the descriptors of the argument types from the BasicValue array to form the method signature.

Parameters
minsnthe MethodInsnNode representing the method
argsan array of BasicValue representing the argument types
Returns
the method signature as a String

◆ buildNewStringArrayCode()

static String ppt4j.util.StringUtils.buildNewStringArrayCode ( String[] arr)
static

This method takes an array of Strings and builds a new String representation of the array in code format. If the input array is null or empty, it returns "new String[0]". Otherwise, it constructs a code snippet representing the input array in the format "new String[] {"element1", "element2", ...}".

Parameters
arrthe input array of Strings
Returns
a String representing the input array in code format

◆ convertMethodSignature()

static String ppt4j.util.StringUtils.convertMethodSignature ( String nameAndArgs,
String returnType )
static

Converts a method signature from a human-readable format to a JVM descriptor format.

Parameters
nameAndArgsthe method name and arguments in human-readable format
returnTypethe return type of the method in human-readable format
Returns
the method signature in JVM descriptor format

◆ convertQualifiedName() [1/2]

static String ppt4j.util.StringUtils.convertQualifiedName ( String name,
String className )
static

Converts the given name to a qualified name by appending the class name to it.

Parameters
namethe name to convert
classNamethe class name to append
Returns
the qualified name with the class name appended

◆ convertQualifiedName() [2/2]

static String ppt4j.util.StringUtils.convertQualifiedName ( String name,
String className,
boolean retainClassName )
static

Converts a qualified name by separating the class name and the method name. If the class name matches the specified className or is a primitive type, and retainClassName is false, it returns only the method name. Otherwise, it returns the qualified name with the class name converted to bytecode format.

Parameters
namethe qualified name to convert
classNamethe class name to compare with
retainClassNamewhether to retain the class name in the output
Returns
the converted qualified name

◆ convertToDescriptor()

static String ppt4j.util.StringUtils.convertToDescriptor ( String type)
static

Converts a given type name to its corresponding descriptor as per the JVM specification. The descriptor is used in bytecode representation of Java classes.

Parameters
typethe type name to convert
Returns
the descriptor corresponding to the given type name

◆ extractClassName()

static String ppt4j.util.StringUtils.extractClassName ( String filePath,
String topLevelPrefix )
static

Extracts the class name from a file path based on a specified top level prefix.

Parameters
filePaththe file path from which to extract the class name
topLevelPrefixthe top level prefix to remove from the file path
Returns
the extracted class name with '/' replaced by '.'

◆ extractDatabaseId()

static int ppt4j.util.StringUtils.extractDatabaseId ( String name)
static

Extracts the database ID from the provided database name in the format VUL4J-d. The method parses the input string to check if it matches the pattern VUL4J-d, where d is a numerical value. If the input matches the pattern, it extracts the numerical value and returns it as an integer. If the input does not match the expected pattern, an IllegalStateException is thrown.

Parameters
namethe database name in the format VUL4J-d
Returns
the extracted database ID as an integer
Exceptions
IllegalStateExceptionif the input string does not match the expected pattern

◆ getClassPathToLoad()

static String ppt4j.util.StringUtils.getClassPathToLoad ( Vulnerability vuln)
static

Constructs the classpath needed to load the necessary resources for a given vulnerability. The classpath includes the base CLASSPATH, the database prepatch class path, the database postpatch class path, and the third party library directories from the prepatch.

Parameters
vulnthe vulnerability for which the classpath is being generated
Returns
the classpath as a string

◆ getDatabasePostpatchClassPath()

static String ppt4j.util.StringUtils.getDatabasePostpatchClassPath ( Vulnerability vuln)
static

Constructs a database postpatch class path for a given vulnerability by combining the root directory of the database, the postpatch name, the vulnerability's database ID, and the top-level directory of the vulnerability's classes.

Parameters
vulnthe Vulnerability object for which the database postpatch class path is being generated
Returns
the database postpatch class path for the given vulnerability

◆ getDatabasePostpatchSrcPath()

static String ppt4j.util.StringUtils.getDatabasePostpatchSrcPath ( Vulnerability vuln)
static

Returns the source path for the postpatch of a vulnerability in the database. The source path is constructed using the database root, postpatch name, vulnerability id, and the top level directory of the Java source file related to the vulnerability.

Parameters
vulnthe Vulnerability object representing the vulnerability
Returns
the source path for the postpatch of the vulnerability

◆ getDatabasePrepatchClassPath()

static String ppt4j.util.StringUtils.getDatabasePrepatchClassPath ( Vulnerability vuln)
static

This method constructs the class path for the prepatch classes related to a given vulnerability. The class path is constructed based on the vulnerability's database ID and top-level directory.

Parameters
vulnthe Vulnerability object for which to construct the class path
Returns
the class path for the prepatch classes related to the given vulnerability

◆ getDatabasePrepatchSrcPath()

static String ppt4j.util.StringUtils.getDatabasePrepatchSrcPath ( Vulnerability vuln)
static

Constructs the source path for the prepatch of a given vulnerability in the database. The source path is formed by concatenating the root database path, prepatch name, vulnerability id, and the inner path of the Java source top level directory of the vulnerability.

Parameters
vulnthe Vulnerability object representing the vulnerability
Returns
the source path for the prepatch of the vulnerability in the database

◆ getJavaSrcTopLevelDir()

static String ppt4j.util.StringUtils.getJavaSrcTopLevelDir ( VulnerabilityInfo info)
static

This method determines the top level source directory based on the information provided in the VulnerabilityInfo object. If the src_top_level_dir is specified in the object, it is returned. Otherwise, it determines the top level directory based on the build system specified in the object (Maven or Gradle) and the src_classes_dir information. For Maven projects, it checks the target directory to determine the source directory. For Gradle projects, it checks the target directory to determine the source directory. If the build system is not Maven or Gradle, it throws an IllegalStateException.

Parameters
infothe VulnerabilityInfo object containing the information needed to determine the top level source directory
Returns
the top level source directory based on the provided information

◆ getThirdPartyLibDirsFromPrepatch()

static String[] ppt4j.util.StringUtils.getThirdPartyLibDirsFromPrepatch ( Vulnerability vuln)
static

Retrieves the directories of third-party libraries associated with a given vulnerability from the prepatch directory structure. The method appends the prepatch root, prepatch name, vulnerability database ID, and third-party library directory to each directory path. It then resolves the full path of each directory before returning an array of strings containing the updated directory paths.

Parameters
vulnthe Vulnerability object for which to retrieve third-party library directories
Returns
an array of strings representing the full paths of third-party library directories

◆ getThirdPartyLibDirsString()

static String ppt4j.util.StringUtils.getThirdPartyLibDirsString ( VulnerabilityInfo info)
static

Returns a string representation of the third party library directories from the given VulnerabilityInfo object.

Parameters
infothe VulnerabilityInfo object containing the third party library directories
Returns
a string representation of the third party library directories

◆ getThirdPartySrcDirsFromPrepatch()

static String[] ppt4j.util.StringUtils.getThirdPartySrcDirsFromPrepatch ( Vulnerability vuln)
static

Retrieves the third party source directories related to a given vulnerability from the prepatch database. The method constructs the full path for each directory using the database root, prepatch name, vulnerability id, and the directory name. It then resolves the full path to ensure proper formatting before returning an array of the third party source directories.

Parameters
vulnthe Vulnerability object representing the vulnerability
Returns
an array of strings containing the full paths of the third party source directories

◆ getThirdPartySrcDirsString()

static String ppt4j.util.StringUtils.getThirdPartySrcDirsString ( VulnerabilityInfo info)
static

This method takes a VulnerabilityInfo object as input and retrieves the third party source directories stored in it. It then calls the buildNewStringArrayCode method to convert the array of directories into a string representation.

Parameters
infothe VulnerabilityInfo object containing the third party source directories
Returns
a string representation of the third party source directories

◆ isJavaCode()

static boolean ppt4j.util.StringUtils.isJavaCode ( String line)
static

Checks if the provided line of text is valid Java code by analyzing its content. Returns true if the line contains valid Java code, and false otherwise.

Parameters
linethe line of text to check
Returns
true if the line contains valid Java code, false otherwise

◆ isJavaComment()

static boolean ppt4j.util.StringUtils.isJavaComment ( String line)
static

Checks if a given line is a Java comment. A Java comment can be either a single line comment starting with "//" or a multi-line comment enclosed in /* * /.

Parameters
linethe input line to check
Returns
true if the line is a Java comment, false otherwise

◆ isPrimitive()

static boolean ppt4j.util.StringUtils.isPrimitive ( String type)
static

Determines if the given type is a primitive data type in Java.

Parameters
typethe type to check
Returns
true if the type is a primitive data type, false otherwise

◆ joinArgDesc()

static String ppt4j.util.StringUtils.joinArgDesc ( List< String > descList)
static

Concatenates a list of strings to form a single description with parentheses

Parameters
descListthe list of strings to be concatenated
Returns
a string containing all the descriptions in the list enclosed in parentheses

◆ matchPrefix()

static Main.Command ppt4j.util.StringUtils.matchPrefix ( String prefix)
static

Matches a command enum based on the given prefix string. If multiple commands are found with the same prefix, it prints an error message and exits the program. If no commands are found with the prefix, it prints an error message and exits the program.

Parameters
prefixthe prefix to match the command enum
Returns
the matched command enum

◆ printSet() [1/2]

static String ppt4j.util.StringUtils.printSet ( Set<?> set)
static

This method takes a Set of unknown type elements and returns a String representation of the elements. If the second parameter is set to true, the elements will be printed in a sorted order. If the third parameter is set to true, the elements will be printed in a reversed order.

Parameters
setthe Set of elements to be printed
Returns
a String representation of the elements in the Set

◆ printSet() [2/2]

static String ppt4j.util.StringUtils.printSet ( Set<?> set,
boolean emphasizeString,
boolean printType )
static

This method takes a Set and options to emphasize strings and print types, and returns a formatted string representation of the elements in the set. If set is empty, it returns "[]". If emphasizeString is true, strings in the set are enclosed in double quotes. If printType is true, the class name of each element is appended after the value.

Parameters
setthe Set to be printed
emphasizeStringwhether to emphasize strings with double quotes
printTypewhether to print the class name of each element
Returns
a formatted string representation of the elements in the set

◆ resolvePath()

static String ppt4j.util.StringUtils.resolvePath ( String path)
static

Resolves the given path by replacing the "~" symbol with the user's home directory.

Parameters
paththe path to be resolved
Returns
the resolved path with the "~" symbol replaced by the home directory

◆ splitArgDesc()

static String[] ppt4j.util.StringUtils.splitArgDesc ( String desc)
static

Splits the argument descriptor of a method description into individual argument descriptors.

Parameters
descthe method description containing the argument descriptor
Returns
an array of individual argument descriptors

◆ substringBetween()

static String ppt4j.util.StringUtils.substringBetween ( String str,
char c1,
char c2 )
static

Returns the substring of a given string that is between two specified characters.

Parameters
strthe input string
c1the starting character
c2the ending character
Returns
the substring between the two specified characters, or null if either character is not found

◆ toBytes()

static byte[] ppt4j.util.StringUtils.toBytes ( List< String > lines)
static

Converts a list of strings into a byte array. Each string in the list is joined with a newline character ('
') and then converted into bytes.

Parameters
linesthe list of strings to convert
Returns
a byte array representing the joined strings

◆ toURL()

static URL ppt4j.util.StringUtils.toURL ( String path)
static

Converts a given file path or URL string to a URL object. If the path starts with "http://" or "https://", it creates a URL object. Otherwise, it creates a URL object from a File object representing the path.

Parameters
paththe file path or URL string to convert
Returns
a URL object representing the given path

◆ toWrapperType()

static String ppt4j.util.StringUtils.toWrapperType ( String type)
static

Converts a primitive type to its corresponding wrapper class type.

Parameters
typethe primitive type to convert
Returns
the wrapper class type

◆ trimJavaCodeLine()

static String ppt4j.util.StringUtils.trimJavaCodeLine ( String codeLine)
static

Trims a line of Java code by removing comments, leading and trailing whitespace, and removing the opening curly brace if it is the last character.

Parameters
codeLinethe line of Java code to be trimmed
Returns
the trimmed version of the input code line

The documentation for this class was generated from the following file: