Class StringStuff
java.lang.Object
com.ibm.wala.core.util.strings.StringStuff
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
classIsPrimitive
(ImmutableByteArray name, int start, int length) static String
Translate a type from a deployment descriptor string into the type expected for use in a method descriptorstatic String
deployment2CanonicalTypeString
(String dString) Translate a type from a deployment descriptor string into the internal JVM formatstatic String
dollarToDot
(String path) Convert '$' to '.' in names.static String
dotToDollar
(String path) Convert '.' to '$' in names.static boolean
isTypeCodeChar
(ImmutableByteArray name, int i) static String
jvmToBinaryName
(String jvmType) Convert a JVM encoded type name to a binary type name.static String
jvmToReadableType
(String jvmType) Convert a JVM encoded type name to a readable type name.static MethodReference
makeMethodReference
(Language l, String methodSig) static MethodReference
makeMethodReference
(String methodSig) static void
padWithSpaces
(StringBuilder b, int length) static int
parseForArrayDimensionality
(ImmutableByteArray b, int start, int length) Parse an array descriptor to obtain number of dimensions in corresponding array type.static ImmutableByteArray
Given that name[start:start+length] is a Type name in JVM format, strip the package and return the "package-free" class namestatic ImmutableByteArray
parseForClass
(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 ImmutableByteArray
Parse an array descriptor to obtain number of dimensions in corresponding array type.static ImmutableByteArray
parseForInnermostArrayElementDescriptor
(ImmutableByteArray b, int start, int length) Parse an array descriptor to obtain number of dimensions in corresponding array type.static ImmutableByteArray
Given that name[start:start+length] is a Type name in JVM format, parse it for the packagestatic ImmutableByteArray
parseForPackage
(ImmutableByteArray name, int start, int length) Given that name[start:start+length] is a Type name in JVM format, parse it for the packagestatic final TypeName[]
Parse method descriptor to obtain descriptions of method's parameters.static final TypeName[]
parseForParameterNames
(Language l, String descriptor) static final TypeName[]
parseForParameterNames
(String descriptor) static final TypeName
Parse method descriptor to obtain description of method's return type.static final TypeName
parseForReturnTypeName
(Language l, String desc) static final TypeName
parseForReturnTypeName
(String desc) static String
slashToDot
(String path) Convert '/' to '.' in names.static String
toBasename
(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 final TypeName parseForReturnTypeName(Language l, String desc) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
parseForReturnTypeName
public static final 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
public static final TypeName[] parseForParameterNames(String descriptor) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
parseForParameterNames
public static final TypeName[] parseForParameterNames(Language l, String descriptor) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
parseForParameterNames
public static final 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
-