Top Description Inners Fields Constructors Methods
org.aspectj.apache.bcel.classfile

public abstract Class Utility

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .DataOutputStream, .IOException, java.util.ArrayList, .Collection, .List, org.aspectj.apache.bcel.Constants, org.aspectj.apache.bcel.classfile.annotation.AnnotationGen, .RuntimeAnnos, .RuntimeInvisAnnos, .RuntimeInvisParamAnnos, .RuntimeParamAnnos, .RuntimeVisAnnos, .RuntimeVisParamAnnos, org.aspectj.apache.bcel.generic.Type, org.aspectj.apache.bcel.util.ByteSequence

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private static boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static final String

Returns:

String representation of flags
accessToString
(int
Access flags
access_flags
)

Convert bit field of flags into string such as 'static final'.

public static final String

Returns:

String representation of flags
accessToString
(int
Access flags
access_flags
,
boolean
access flags are for class qualifiers ?
for_class
)

Convert bit field of flags into string such as 'static final'.

private static final short
byteToShort(byte b)

Convert (signed) byte to (unsigned) short value, i.e., all negative values become positive.

public static final String

Returns:

"class" or "interface", depending on the ACC_INTERFACE flag
classOrInterface
(int access_flags)

public static final String

Returns:

String representation of byte codes
codeToString
(byte[]
byte code array
code
,
ConstantPool
Array of constants
constant_pool
,
int
offset in `code' array (number of opcodes, not bytes!)
index
,
int
number of opcodes to decompile, -1 for all
length
,
boolean
be verbose, e.g. print constant pool index
verbose
)

Disassemble a byte array of JVM byte codes starting from code line 'index' and return the disassembled string representation.

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.

public static final String
codeToString(ByteSequence bytes, ConstantPool constant_pool)

public static final String

Returns:

String representation of byte code
codeToString
(ByteSequence
stream of bytes
bytes
,
ConstantPool
Array of constants
constant_pool
,
boolean
be verbose, e.g. print constant pool index
verbose
)

Disassemble a stream of byte codes and return the string representation.

public static final String

Returns:

Compacted class name
compactClassName
(String
The long class name
str
)

Shorten long class names, java/lang/String becomes String.

public static final String

Returns:

Compacted class name
compactClassName
(String
The long class name
str
,
String
The prefix the get rid off
prefix
,
boolean
Flag that determines whether chopping is executed or not
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.

public static final String

Returns:

Compacted class name
compactClassName
(String
The long class name
str
,
boolean
Flag that determines whether chopping is executed or not
chopit
)

Shorten long class names, java/lang/String becomes java.lang.String, e.g..

public static final String
convertString(String label)

Escape all occurences of newline chars '\n', quotes \", etc.

public static final String

Returns:

formatted string
fillup
(String
string to format
str
,
int
length of desired string
length
,
boolean
format left or right
left_justify
,
char
fill character
fill
)

Fillup char with up to length characters with char `fill' and justify it left or right.

public static final String

Returns:

formatted int
format
(int
integer to format
i
,
int
length of desired string
length
,
boolean
format left or right
left_justify
,
char
fill character
fill
)

Return a string for an integer justified left or right and filled up with 'fill' characters if necessary.

public static Collection<RuntimeAnnos>
getAnnotationAttributes(ConstantPool
The constant pool gen where we can create the necessary name refs
cp
,
List<AnnotationGen>
A list of AnnotationGen objects
annotations
)

Converts a list of AnnotationGen objects into a set of attributes that can be attached to the class file.

public static Attribute[]
getParameterAnnotationAttributes(ConstantPool cp, List<AnnotationGen>[] vec)

Annotations against a class are stored in one of four attribute kinds: - RuntimeVisibleParameterAnnotations - RuntimeInvisibleParameterAnnotations

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

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

public 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.

private static final int
pow2(int n)

public static final String

Returns:

new String object
replace
(String
String to permute
str
,
String
String to be replaced
old
,
String
Replacement string
new_
)

Replace all occurences of old in str with new.

public static final String

Returns:

Human readable signature
signatureToString
(String
to convert
signature
)

Converts signature to string with all class names compacted.

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

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.

public static final String

Returns:

bytes as hexidecimal string, e.g. 00 FA 12 ...
toHexString
(byte[] bytes)

Convert bytes into hexidecimal string

public static String

Returns:

method signature for given type(s).
toMethodSignature
(Type
what the method returns
returnType
,
Type[]
what are the argument types
argTypes
)

Convert type to Java method signature, e.g. int[] f(java.lang.String x) becomes (Ljava/lang/String;)[I

public static final byte

Returns:

type of method signature
typeOfMethodSignature
(String
in format described above
signature
)

Return type of method signature as a byte value as defined in Constants

public static final byte

Returns:

type of signature
typeOfSignature
(String
in format described above
signature
)

Return type of signature as a byte value as defined in Constants

public static final byte
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

wideback to summary
private static boolean wide

Constructor Detail

Utilityback to summary
public Utility()

Method Detail

accessToStringback to summary
public static final String accessToString(int access_flags)

Convert bit field of flags into string such as 'static final'.

Parameters
access_flags:int

Access flags

Returns:String

String representation of flags

accessToStringback to summary
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'.

Parameters
access_flags:int

Access flags

for_class:boolean

access flags are for class qualifiers ?

Returns:String

String representation of flags

byteToShortback to summary
private static final short byteToShort(byte b)

Convert (signed) byte to (unsigned) short value, i.e., all negative values become positive.

classOrInterfaceback to summary
public static final String classOrInterface(int access_flags)
Returns:String

"class" or "interface", depending on the ACC_INTERFACE flag

codeToStringback to summary
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.

Parameters
code:byte[]

byte code array

constant_pool:ConstantPool

Array of constants

index:int

offset in `code' array (number of opcodes, not bytes!)

length:int

number of opcodes to decompile, -1 for all

verbose:boolean

be verbose, e.g. print constant pool index

Returns:String

String representation of byte codes

codeToStringback to summary
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.

codeToStringback to summary
public static final String codeToString(ByteSequence bytes, ConstantPool constant_pool) throws IOException
codeToStringback to summary
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.

Parameters
bytes:ByteSequence

stream of bytes

constant_pool:ConstantPool

Array of constants

verbose:boolean

be verbose, e.g. print constant pool index

Returns:String

String representation of byte code

compactClassNameback to summary
public static final String compactClassName(String str)

Shorten long class names, java/lang/String becomes String.

Parameters
str:String

The long class name

Returns:String

Compacted class name

compactClassNameback to summary
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 ..

Parameters
str:String

The long class name

prefix:String

The prefix the get rid off

chopit:boolean

Flag that determines whether chopping is executed or not

Returns:String

Compacted class name

compactClassNameback to summary
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.

Parameters
str:String

The long class name

chopit:boolean

Flag that determines whether chopping is executed or not

Returns:String

Compacted class name

convertStringback to summary
public static final String convertString(String label)

Escape all occurences of newline chars '\n', quotes \", etc.

fillupback to summary
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.

Parameters
str:String

string to format

length:int

length of desired string

left_justify:boolean

format left or right

fill:char

fill character

Returns:String

formatted string

formatback to summary
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.

Parameters
i:int

integer to format

length:int

length of desired string

left_justify:boolean

format left or right

fill:char

fill character

Returns:String

formatted int

getAnnotationAttributesback to summary
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.

Parameters
cp:ConstantPool

The constant pool gen where we can create the necessary name refs

annotations:List<AnnotationGen>

A list of AnnotationGen objects

getParameterAnnotationAttributesback to summary
public static Attribute[] getParameterAnnotationAttributes(ConstantPool cp, List<AnnotationGen>[] vec)

Annotations against a class are stored in one of four attribute kinds: - RuntimeVisibleParameterAnnotations - RuntimeInvisibleParameterAnnotations

methodSignatureToStringback to summary
public static final String methodSignatureToString(String signature, String name, String access)
methodSignatureToStringback to summary
public static final String methodSignatureToString(String signature, String name, String access, boolean chopit)
methodSignatureToStringback to summary
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.

pow2back to summary
private static final int pow2(int n)
replaceback to summary
public static final String replace(String str, String old, String new_)

Replace all occurences of old in str with new.

Parameters
str:String

String to permute

old:String

String to be replaced

new_:String

Replacement string

Returns:String

new String object

signatureToStringback to summary
public static final String signatureToString(String signature)

Converts signature to string with all class names compacted.

Parameters
signature:String

to convert

Returns:String

Human readable signature

signatureToStringback to summary
public static final String signatureToString(String signature, boolean chopit)
signatureToStringInternalback to summary
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.

toHexStringback to summary
public static final String toHexString(byte[] bytes)

Convert bytes into hexidecimal string

Returns:String

bytes as hexidecimal string, e.g. 00 FA 12 ...

toMethodSignatureback to summary
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

Parameters
returnType:Type

what the method returns

argTypes:Type[]

what are the argument types

Returns:String

method signature for given type(s).

typeOfMethodSignatureback to summary
public static final byte typeOfMethodSignature(String signature) throws ClassFormatException

Return type of method signature as a byte value as defined in Constants

Parameters
signature:String

in format described above

Returns:byte

type of method signature

See Also
Constants
typeOfSignatureback to summary
public static final byte typeOfSignature(String signature) throws ClassFormatException

Return type of signature as a byte value as defined in Constants

Parameters
signature:String

in format described above

Returns:byte

type of signature

See Also
Constants
typeOfSignatureback to summary
public static final byte typeOfSignature(char c) throws ClassFormatException
org.aspectj.apache.bcel.classfile back to summary

public Class Utility.ResultHolder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Utility.ResultHolder
public static final Utility.ResultHolder
public static final Utility.ResultHolder
private int
public static final Utility.ResultHolder
public static final Utility.ResultHolder
public static final Utility.ResultHolder
public static final Utility.ResultHolder
private String
public static final Utility.ResultHolder
public static final Utility.ResultHolder

Constructor Summary

AccessConstructor and Description
public
ResultHolder(String s, int c)

Method Summary

Modifier and TypeMethod and Description
public int
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BOOLEANback to summary
public static final Utility.ResultHolder BOOLEAN
BYTEback to summary
public static final Utility.ResultHolder BYTE
CHARback to summary
public static final Utility.ResultHolder CHAR
consumedback to summary
private int consumed
DOUBLEback to summary
public static final Utility.ResultHolder DOUBLE
FLOATback to summary
public static final Utility.ResultHolder FLOAT
INTback to summary
public static final Utility.ResultHolder INT
LONGback to summary
public static final Utility.ResultHolder LONG
resultback to summary
private String result
SHORTback to summary
public static final Utility.ResultHolder SHORT
VOIDback to summary
public static final Utility.ResultHolder VOID

Constructor Detail

ResultHolderback to summary
public ResultHolder(String s, int c)

Method Detail

getConsumedCharsback to summary
public int getConsumedChars()
getResultback to summary
public String getResult()