Class StringStuff
java.lang.Object
com.ibm.wala.core.util.strings.StringStuff
Some simple utilities used to manipulate Strings
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanclassIsPrimitive(ImmutableByteArray name, int start, int length) static StringTranslate a type from a deployment descriptor string into the type expected for use in a method descriptorstatic Stringdeployment2CanonicalTypeString(String dString) Translate a type from a deployment descriptor string into the internal JVM formatstatic StringdollarToDot(String path) Convert '$' to '.' in names.static StringdotToDollar(String path) Convert '.' to '$' in names.static booleanisTypeCodeChar(ImmutableByteArray name, int i) static StringjvmToBinaryName(String jvmType) Convert a JVM encoded type name to a binary type name.static StringjvmToReadableType(String jvmType) Convert a JVM encoded type name to a readable type name.static MethodReferencemakeMethodReference(Language l, String methodSig) static MethodReferencemakeMethodReference(String methodSig) static voidpadWithSpaces(StringBuilder b, int length) static intparseForArrayDimensionality(ImmutableByteArray b, int start, int length) Parse an array descriptor to obtain number of dimensions in corresponding array type.static ImmutableByteArrayGiven that name[start:start+length] is a Type name in JVM format, strip the package and return the "package-free" class namestatic ImmutableByteArrayparseForClass(ImmutableByteArray name, int start, int length) Given that name[start:start+length] is a Type name in JVM format, strip the package and return the "package-free" class namestatic ImmutableByteArrayParse an array descriptor to obtain number of dimensions in corresponding array type.static ImmutableByteArrayparseForInnermostArrayElementDescriptor(ImmutableByteArray b, int start, int length) Parse an array descriptor to obtain number of dimensions in corresponding array type.static ImmutableByteArrayGiven that name[start:start+length] is a Type name in JVM format, parse it for the packagestatic ImmutableByteArrayparseForPackage(ImmutableByteArray name, int start, int length) Given that name[start:start+length] is a Type name in JVM format, parse it for the packagestatic TypeName[]Parse method descriptor to obtain descriptions of method's parameters.static TypeName[]parseForParameterNames(Language l, String descriptor) static TypeName[]parseForParameterNames(String descriptor) static TypeNameParse method descriptor to obtain description of method's return type.static TypeNameparseForReturnTypeName(Language l, String desc) static TypeNameparseForReturnTypeName(String desc) static StringslashToDot(String path) Convert '/' to '.' in names.static StringtoBasename(String typeName) Return the right position of the string up to '.' or '/' stripping ';'
-
Constructor Details
-
StringStuff
public StringStuff()
-
-
Method Details
-
padWithSpaces
-
deployment2CanonicalTypeString
Translate a type from a deployment descriptor string into the internal JVM formateg. [[java/lang/String
- Throws:
IllegalArgumentException- if dString is null
-
deployment2CanonicalDescriptorTypeString
Translate a type from a deployment descriptor string into the type expected for use in a method descriptoreg. [[Ljava.lang.String;
- Throws:
IllegalArgumentException- if dString is null
-
parseForReturnTypeName
- Throws:
IllegalArgumentException
-
parseForReturnTypeName
public static TypeName parseForReturnTypeName(Language l, String desc) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
parseForReturnTypeName
public static TypeName parseForReturnTypeName(Language l, ImmutableByteArray b) throws IllegalArgumentException Parse method descriptor to obtain description of method's return type. TODO: tune this .. probably combine with parseForParameters.- Parameters:
b- method descriptor - something like "(III)V"- Returns:
- type description
- Throws:
IllegalArgumentException- if b is null
-
parseForParameterNames
- Throws:
IllegalArgumentException
-
parseForParameterNames
public static TypeName[] parseForParameterNames(Language l, String descriptor) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
parseForParameterNames
public static TypeName[] parseForParameterNames(Language l, ImmutableByteArray b) throws IllegalArgumentException Parse method descriptor to obtain descriptions of method's parameters.- Returns:
- parameter descriptions, or null if there are no parameters
- Throws:
IllegalArgumentException- if b is null
-
isTypeCodeChar
-
parseForPackage
public static ImmutableByteArray parseForPackage(ImmutableByteArray name, int start, int length) throws IllegalArgumentException Given that name[start:start+length] is a Type name in JVM format, parse it for the package- Returns:
- an ImmutableByteArray that represents the package, or null if it's the unnamed package
- Throws:
IllegalArgumentException- if name == null
-
parseForPackage
Given that name[start:start+length] is a Type name in JVM format, parse it for the package- Returns:
- an ImmutableByteArray that represents the package, or null if it's the unnamed package
- Throws:
IllegalArgumentException- if name is null
-
parseForClass
public static ImmutableByteArray parseForClass(ImmutableByteArray name, int start, int length) throws IllegalArgumentException Given that name[start:start+length] is a Type name in JVM format, strip the package and return the "package-free" class nameTODO: inefficient; needs tuning.
- Returns:
- an ImmutableByteArray that represents the package, or null if it's the unnamed package
- Throws:
IllegalArgumentException- if name is null or malformed
-
parseForClass
public static ImmutableByteArray parseForClass(ImmutableByteArray name) throws IllegalArgumentException Given that name[start:start+length] is a Type name in JVM format, strip the package and return the "package-free" class name- Returns:
- an ImmutableByteArray that represents the package, or null if it's the unnamed package
- Throws:
IllegalArgumentException- if name is null
-
parseForArrayDimensionality
public static int parseForArrayDimensionality(ImmutableByteArray b, int start, int length) throws IllegalArgumentException, IllegalArgumentException Parse an array descriptor to obtain number of dimensions in corresponding array type. b: descriptor - something like "[Ljava/lang/String;" or "[[I"- Returns:
- dimensionality - something like "1" or "2"
- Throws:
IllegalArgumentException- if b == null
-
parseForInnermostArrayElementDescriptor
public static ImmutableByteArray parseForInnermostArrayElementDescriptor(ImmutableByteArray b, int start, int length) Parse an array descriptor to obtain number of dimensions in corresponding array type. b: descriptor - something like "[Ljava/lang/String;" or "[[I"- Returns:
- dimensionality - something like "Ljava/lang/String;" or "I"
- Throws:
IllegalArgumentException- if b is null
-
parseForInnermostArrayElementDescriptor
Parse an array descriptor to obtain number of dimensions in corresponding array type. b: descriptor - something like "[Ljava/lang/String;" or "[[I"- Returns:
- dimensionality - something like "Ljava/lang/String;" or "I"
- Throws:
IllegalArgumentException- if a is null
-
classIsPrimitive
public static boolean classIsPrimitive(ImmutableByteArray name, int start, int length) throws IllegalArgumentException - Returns:
- true iff the class returned by parseForClass is primitive
- Throws:
IllegalArgumentException- if name is null
-
makeMethodReference
- Parameters:
methodSig- something like "java_cup.lexer.advance()V"- Throws:
IllegalArgumentException- if methodSig is null
-
makeMethodReference
public static MethodReference makeMethodReference(Language l, String methodSig) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
jvmToReadableType
Convert a JVM encoded type name to a readable type name.- Parameters:
jvmType- a String containing a type name in JVM internal format.- Returns:
- the same type name in readable (source code) format.
- Throws:
IllegalArgumentException- if jvmType is null
-
jvmToBinaryName
Convert a JVM encoded type name to a binary type name. This version does not call dollarToDot.- Parameters:
jvmType- a String containing a type name in JVM internal format.- Returns:
- the same type name in readable (source code) format.
- Throws:
IllegalArgumentException- if jvmType is null
-
slashToDot
Convert '/' to '.' in names.- Returns:
- a String object obtained by replacing the forward slashes ('/') in the String passed as argument with ('.').
- Throws:
IllegalArgumentException- if path is null
-
dollarToDot
Convert '$' to '.' in names.- Parameters:
path- a string object in which dollar signs('$') must be converted to dots ('.').- Returns:
- a String object obtained by replacing the dollar signs ('S') in the String passed as argument with ('.').
- Throws:
IllegalArgumentException- if path is null
-
dotToDollar
Convert '.' to '$' in names.- Parameters:
path- String object in which dollar signs('$') must be converted to dots ('.').- Returns:
- a String object obtained by replacing the dollar signs ('S') in the String passed as argument with ('.').
- Throws:
IllegalArgumentException- if path is null
-
toBasename
-