Class StringStuff

java.lang.Object
com.ibm.wala.core.util.strings.StringStuff

public class StringStuff extends Object
Some simple utilities used to manipulate Strings
  • Constructor Details

    • StringStuff

      public StringStuff()
  • Method Details

    • padWithSpaces

      public static void padWithSpaces(StringBuilder b, int length)
    • deployment2CanonicalTypeString

      public static String deployment2CanonicalTypeString(String dString)
      Translate a type from a deployment descriptor string into the internal JVM format

      eg. [[java/lang/String

      Throws:
      IllegalArgumentException - if dString is null
    • deployment2CanonicalDescriptorTypeString

      public static String deployment2CanonicalDescriptorTypeString(String dString)
      Translate a type from a deployment descriptor string into the type expected for use in a method descriptor

      eg. [[Ljava.lang.String;

      Throws:
      IllegalArgumentException - if dString is null
    • parseForReturnTypeName

      public static final TypeName parseForReturnTypeName(String desc) throws IllegalArgumentException
      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

      public static boolean isTypeCodeChar(ImmutableByteArray name, int i)
    • 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

      public static ImmutableByteArray parseForPackage(ImmutableByteArray name)
      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 name

      TODO: 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

      public static ImmutableByteArray parseForInnermostArrayElementDescriptor(Atom a)
      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

      public static MethodReference makeMethodReference(String methodSig) throws IllegalArgumentException
      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

      public static String jvmToReadableType(String jvmType) throws IllegalArgumentException
      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

      public static String jvmToBinaryName(String jvmType) throws IllegalArgumentException
      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

      public static String slashToDot(String path)
      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

      public static String dollarToDot(String path)
      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

      public static String dotToDollar(String path)
      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

      public static String toBasename(String typeName)
      Return the right position of the string up to '.' or '/' stripping ';'