Klasse Utility
java.lang.Object
org.aspectj.apache.bcel.classfile.Utility
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
-
Verschachtelte Klassen - Übersicht
-
Konstruktorübersicht
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic final String
accessToString
(int access_flags) Convert bit field of flags into string such as 'static final'.static final String
accessToString
(int access_flags, boolean for_class) Convert bit field of flags into string such as 'static final'.static final String
classOrInterface
(int access_flags) static final String
codeToString
(byte[] code, ConstantPool constant_pool, int index, int length) Disassemble a stream of byte codes and return the string representation.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.static final String
codeToString
(ByteSequence bytes, ConstantPool constant_pool) static final String
codeToString
(ByteSequence bytes, ConstantPool constant_pool, boolean verbose) Disassemble a stream of byte codes and return the string representation.static final String
compactClassName
(String str) Shorten long class names, java/lang/String becomes String.static final String
compactClassName
(String str, boolean chopit) Shorten long class names, java/lang/String becomes java.lang.String, e.g..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.static final String
convertString
(String label) Escape all occurences of newline chars '\n', quotes \", etc.static final String
Fillup char with up to length characters with char `fill' and justify it left or right.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.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.static Attribute[]
Annotations against a class are stored in one of four attribute kinds: - RuntimeVisibleParameterAnnotations - RuntimeInvisibleParameterAnnotationsstatic final String
methodSignatureToString
(String signature, String name, String access) static final String
methodSignatureToString
(String signature, String name, String access, boolean chopit) static final String
methodSignatureToString
(String signature, String name, String access, boolean chopit, LocalVariableTable vars) 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.static final String
Replace all occurences of old in str with new.static final String
signatureToString
(String signature) Converts signature to string with all class names compacted.static final String
signatureToString
(String signature, boolean chopit) 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.static final String
toHexString
(byte[] bytes) Convert bytes into hexidecimal stringstatic String
toMethodSignature
(Type returnType, Type[] argTypes) Convert type to Java method signature, e.g. int[] f(java.lang.String x) becomes (Ljava/lang/String;)[Istatic final byte
typeOfMethodSignature
(String signature) Return type of method signature as a byte value as defined in Constantsstatic final byte
typeOfSignature
(char c) static final byte
typeOfSignature
(String signature) Return type of signature as a byte value as defined in Constants
-
Konstruktordetails
-
Utility
public Utility()
-
-
Methodendetails
-
accessToString
Convert bit field of flags into string such as 'static final'.- Parameter:
access_flags
- Access flags- Gibt zurück:
- String representation of flags
-
accessToString
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 flagsfor_class
- access flags are for class qualifiers ?- Gibt zurück:
- String representation of flags
-
classOrInterface
- 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 arrayconstant_pool
- Array of constantsindex
- offset in `code' array (number of opcodes, not bytes!)length
- number of opcodes to decompile, -1 for allverbose
- 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
Shorten long class names, java/lang/String becomes String.- Parameter:
str
- The long class name- Gibt zurück:
- Compacted class name
-
compactClassName
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 nameprefix
- The prefix the get rid offchopit
- Flag that determines whether chopping is executed or not- Gibt zurück:
- Compacted class name
-
compactClassName
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 namechopit
- Flag that determines whether chopping is executed or not- Gibt zurück:
- Compacted class name
-
methodSignatureToString
-
methodSignatureToString
-
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
Replace all occurences of old in str with new.- Parameter:
str
- String to permuteold
- String to be replacednew
- Replacement string- Gibt zurück:
- new String object
-
signatureToString
Converts signature to string with all class names compacted.- Parameter:
signature
- to convert- Gibt zurück:
- Human readable signature
-
signatureToString
-
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
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
Convert bytes into hexidecimal string- Gibt zurück:
- bytes as hexidecimal string, e.g. 00 FA 12 ...
-
format
Return a string for an integer justified left or right and filled up with 'fill' characters if necessary.- Parameter:
i
- integer to formatlength
- length of desired stringleft_justify
- format left or rightfill
- fill character- Gibt zurück:
- formatted int
-
fillup
Fillup char with up to length characters with char `fill' and justify it left or right.- Parameter:
str
- string to formatlength
- length of desired stringleft_justify
- format left or rightfill
- fill character- Gibt zurück:
- formatted string
-
convertString
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 refsannotations
- 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
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
- 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 bytesconstant_pool
- Array of constantsverbose
- be verbose, e.g. print constant pool index- Gibt zurück:
- String representation of byte code
- Löst aus:
IOException
-
toMethodSignature
Convert type to Java method signature, e.g. int[] f(java.lang.String x) becomes (Ljava/lang/String;)[I- Parameter:
returnType
- what the method returnsargTypes
- what are the argument types- Gibt zurück:
- method signature for given type(s).
-