Klasse Utility

java.lang.Object
org.aspectj.apache.bcel.classfile.Utility

public abstract class Utility extends Object
Utility functions that do not really belong to any class in particular.
Version:
$Id: Utility.java,v 1.14 2009/09/28 16:39:46 aclement Exp $
Autor:
M. Dahm modified: Andy Clement 2-mar-05 Removed unnecessary static and optimized
  • Konstruktordetails

    • Utility

      public Utility()
  • Methodendetails

    • accessToString

      public static final String accessToString(int access_flags)
      Convert bit field of flags into string such as 'static final'.
      Parameter:
      access_flags - Access flags
      Gibt zurück:
      String representation of flags
    • accessToString

      public static final String accessToString(int access_flags, boolean for_class)
      Convert bit field of flags into string such as 'static final'. Special case: Classes compiled with new compilers and with the 'ACC_SUPER' flag would be said to be "synchronized". This is because SUN used the same value for the flags 'ACC_SUPER' and 'ACC_SYNCHRONIZED'.
      Parameter:
      access_flags - Access flags
      for_class - access flags are for class qualifiers ?
      Gibt zurück:
      String representation of flags
    • classOrInterface

      public static final String classOrInterface(int access_flags)
      Gibt zurück:
      "class" or "interface", depending on the ACC_INTERFACE flag
    • codeToString

      public static final String codeToString(byte[] code, ConstantPool constant_pool, int index, int length, boolean verbose)
      Disassemble a byte array of JVM byte codes starting from code line 'index' and return the disassembled string representation. Decode only 'num' opcodes (including their operands), use -1 if you want to decompile everything.
      Parameter:
      code - byte code array
      constant_pool - Array of constants
      index - offset in `code' array (number of opcodes, not bytes!)
      length - number of opcodes to decompile, -1 for all
      verbose - be verbose, e.g. print constant pool index
      Gibt zurück:
      String representation of byte codes
    • codeToString

      public static final String codeToString(byte[] code, ConstantPool constant_pool, int index, int length)
      Disassemble a stream of byte codes and return the string representation.
    • codeToString

      public static final String codeToString(ByteSequence bytes, ConstantPool constant_pool) throws IOException
      Löst aus:
      IOException
    • compactClassName

      public static final String compactClassName(String str)
      Shorten long class names, java/lang/String becomes String.
      Parameter:
      str - The long class name
      Gibt zurück:
      Compacted class name
    • compactClassName

      public static final String compactClassName(String str, String prefix, boolean chopit)
      Shorten long class name str, i.e., chop off the prefix, if the class name starts with this string and the flag chopit is true. Slashes / are converted to dots ..
      Parameter:
      str - The long class name
      prefix - The prefix the get rid off
      chopit - Flag that determines whether chopping is executed or not
      Gibt zurück:
      Compacted class name
    • compactClassName

      public static final String compactClassName(String str, boolean chopit)
      Shorten long class names, java/lang/String becomes java.lang.String, e.g.. If chopit is true the prefix java.lang is also removed.
      Parameter:
      str - The long class name
      chopit - Flag that determines whether chopping is executed or not
      Gibt zurück:
      Compacted class name
    • methodSignatureToString

      public static final String methodSignatureToString(String signature, String name, String access)
    • methodSignatureToString

      public static final String methodSignatureToString(String signature, String name, String access, boolean chopit)
    • methodSignatureToString

      public static final String methodSignatureToString(String signature, String name, String access, boolean chopit, LocalVariableTable vars) throws ClassFormatException
      This method converts such a string into a Java type declaration like 'void main(String[])' and throws a 'ClassFormatException' when the parsed type is invalid.
      Löst aus:
      ClassFormatException
    • replace

      public static final String replace(String str, String old, String new_)
      Replace all occurences of old in str with new.
      Parameter:
      str - String to permute
      old - String to be replaced
      new - Replacement string
      Gibt zurück:
      new String object
    • signatureToString

      public static final String signatureToString(String signature)
      Converts signature to string with all class names compacted.
      Parameter:
      signature - to convert
      Gibt zurück:
      Human readable signature
    • signatureToString

      public static final String signatureToString(String signature, boolean chopit)
    • signatureToStringInternal

      public static final Utility.ResultHolder signatureToStringInternal(String signature, boolean chopit)
      This method converts this string into a Java type declaration such as 'String[]' and throws a `ClassFormatException' when the parsed type is invalid.
    • typeOfMethodSignature

      public static final byte typeOfMethodSignature(String signature) throws ClassFormatException
      Return type of method signature as a byte value as defined in Constants
      Parameter:
      signature - in format described above
      Gibt zurück:
      type of method signature
      Löst aus:
      ClassFormatException
      Siehe auch:
    • toHexString

      public static final String toHexString(byte[] bytes)
      Convert bytes into hexidecimal string
      Gibt zurück:
      bytes as hexidecimal string, e.g. 00 FA 12 ...
    • format

      public static final String format(int i, int length, boolean left_justify, char fill)
      Return a string for an integer justified left or right and filled up with 'fill' characters if necessary.
      Parameter:
      i - integer to format
      length - length of desired string
      left_justify - format left or right
      fill - fill character
      Gibt zurück:
      formatted int
    • fillup

      public static final String fillup(String str, int length, boolean left_justify, char fill)
      Fillup char with up to length characters with char `fill' and justify it left or right.
      Parameter:
      str - string to format
      length - length of desired string
      left_justify - format left or right
      fill - fill character
      Gibt zurück:
      formatted string
    • convertString

      public static final String convertString(String label)
      Escape all occurences of newline chars '\n', quotes \", etc.
    • getAnnotationAttributes

      public static Collection<RuntimeAnnos> getAnnotationAttributes(ConstantPool cp, List<AnnotationGen> annotations)
      Converts a list of AnnotationGen objects into a set of attributes that can be attached to the class file.
      Parameter:
      cp - The constant pool gen where we can create the necessary name refs
      annotations - A list of AnnotationGen objects
    • getParameterAnnotationAttributes

      public static Attribute[] getParameterAnnotationAttributes(ConstantPool cp, List<AnnotationGen>[] vec)
      Annotations against a class are stored in one of four attribute kinds: - RuntimeVisibleParameterAnnotations - RuntimeInvisibleParameterAnnotations
    • typeOfSignature

      public static final byte typeOfSignature(String signature) throws ClassFormatException
      Return type of signature as a byte value as defined in Constants
      Parameter:
      signature - in format described above
      Gibt zurück:
      type of signature
      Löst aus:
      ClassFormatException
      Siehe auch:
    • typeOfSignature

      public static final byte typeOfSignature(char c) throws ClassFormatException
      Löst aus:
      ClassFormatException
    • codeToString

      public static final String codeToString(ByteSequence bytes, ConstantPool constant_pool, boolean verbose) throws IOException
      Disassemble a stream of byte codes and return the string representation.
      Parameter:
      bytes - stream of bytes
      constant_pool - Array of constants
      verbose - be verbose, e.g. print constant pool index
      Gibt zurück:
      String representation of byte code
      Löst aus:
      IOException
    • toMethodSignature

      public static String toMethodSignature(Type returnType, Type[] argTypes)
      Convert type to Java method signature, e.g. int[] f(java.lang.String x) becomes (Ljava/lang/String;)[I
      Parameter:
      returnType - what the method returns
      argTypes - what are the argument types
      Gibt zurück:
      method signature for given type(s).