Top Description Inners Fields Constructors Methods
com.thoughtworks.paranamer

public Class BytecodeReadingParanamer

extends Object
implements Paranamer
Class Inheritance
All Implemented Interfaces
com.thoughtworks.paranamer.Paranamer
Imports
java.io.IOException, .InputStream, java.lang.reflect.AccessibleObject, .Constructor, .Method, .Modifier, java.util.HashMap, .Map

An ASM-based implementation of Paranamer. It relies on debug information compiled with the "-g" javac option to retrieve parameter names.

Portions of this source file are a fork of ASM.

Authors
Guilherme Silveira, Paul Hammant

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
BytecodeReadingParanamer.ClassReader

A Java class parser to make a Class Visitor visit an existing class.

private static class
BytecodeReadingParanamer.MethodCollector

Objects of this class collects information from a specific method.

private static class
private static class
BytecodeReadingParanamer.TypeCollector

The type collector waits for an specific method in order to start a method collector.

Field Summary

Modifier and TypeField and Description
private static final Map<String, String>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private InputStream
private InputStream
getClassAsStream(ClassLoader classLoader, String className)

public String[]
lookupParameterNames(AccessibleObject
the Method or Constructor for which the parameter names are looked up.
methodOrConstructor
)

Implements com.thoughtworks.paranamer.Paranamer.lookupParameterNames.

Lookup the parameter names of a given method.
public String[]
lookupParameterNames(AccessibleObject
the Method or Constructor for which the parameter names are looked up.
methodOrCtor
,
boolean
whether to throw an exception if no Paranamer data found (versus return null).
throwExceptionIfMissing
)

Implements com.thoughtworks.paranamer.Paranamer.lookupParameterNames.

Lookup the parameter names of a given method.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

primitivesback to summary
private static final Map<String, String> primitives

Constructor Detail

BytecodeReadingParanamerback to summary
public BytecodeReadingParanamer()

Method Detail

getClassAsStreamback to summary
private InputStream getClassAsStream(Class<?> clazz)
getClassAsStreamback to summary
private InputStream getClassAsStream(ClassLoader classLoader, String className)
lookupParameterNamesback to summary
public String[] lookupParameterNames(AccessibleObject methodOrConstructor)

Implements com.thoughtworks.paranamer.Paranamer.lookupParameterNames.

Doc from com.thoughtworks.paranamer.Paranamer.lookupParameterNames.

Lookup the parameter names of a given method.

Parameters
methodOrConstructor:AccessibleObject

the Method or Constructor for which the parameter names are looked up.

Returns:String[]

A list of the parameter names.

lookupParameterNamesback to summary
public String[] lookupParameterNames(AccessibleObject methodOrCtor, boolean throwExceptionIfMissing)

Implements com.thoughtworks.paranamer.Paranamer.lookupParameterNames.

Doc from com.thoughtworks.paranamer.Paranamer.lookupParameterNames.

Lookup the parameter names of a given method.

Parameters
methodOrCtor:AccessibleObject

the Method or Constructor for which the parameter names are looked up.

throwExceptionIfMissing:boolean

whether to throw an exception if no Paranamer data found (versus return null).

Returns:String[]

A list of the parameter names.

com.thoughtworks.paranamer back to summary

private Class BytecodeReadingParanamer.ClassReader

extends Object
Class Inheritance
  • java.lang.Object
  • com.thoughtworks.paranamer.BytecodeReadingParanamer.ClassReader

A Java class parser to make a Class Visitor visit an existing class. This class parses a byte array conforming to the Java class file format and calls the appropriate visit methods of a given class visitor for each field, method and bytecode instruction encountered.
Authors
Eric Bruneton, Eugene Kuleshov

Field Summary

Modifier and TypeField and Description
public final byte[]
b

The class to be parsed.

pack-priv static final int
DOUBLE

The type of CONSTANT_Double constant pool items.

pack-priv static final int
FIELD

The type of CONSTANT_Fieldref constant pool items.

pack-priv static final int
FLOAT

The type of CONSTANT_Float constant pool items.

public final int
header

Start index of the class header information (access, name...) in b.

pack-priv static final int
IMETH

The type of CONSTANT_InterfaceMethodref constant pool items.

pack-priv static final int
INT

The type of CONSTANT_Integer constant pool items.

pack-priv static final int
INVOKEDYN

The type of CONSTANT_InvokeDynamic constant pool items.

private final int[]
items

The start index of each constant pool item in b, plus one.

pack-priv static final int
LONG

The type of CONSTANT_Long constant pool items.

private final int
maxStringLength

Maximum length of the strings contained in the constant pool of the class.

pack-priv static final int
METH

The type of CONSTANT_Methodref constant pool items.

pack-priv static final int
MHANDLE

The type of CONSTANT_MethodHandle constant pool items.

pack-priv static final int
NAME_TYPE

The type of CONSTANT_NameAndType constant pool items.

private final String[]
strings

The String objects corresponding to the CONSTANT_Utf8 items.

pack-priv static final int
UTF8

The type of CONSTANT_Utf8 constant pool items.

Constructor Summary

AccessConstructor and Description
private
ClassReader(final byte[]
the bytecode of the class to be read.
b
)

Constructs a new ClassReader object.

private
ClassReader(final byte[]
the bytecode of the class to be read.
b
,
final int
the start offset of the class data.
off
)

Constructs a new ClassReader object.

private
ClassReader(final InputStream
an input stream from which to read the class.
is
)

Constructs a new ClassReader object.

Method Summary

Modifier and TypeMethod and Description
private void
accept(final BytecodeReadingParanamer.TypeCollector
the visitor that must visit this class.
classVisitor
)

Makes the given visitor visit the Java class of this ClassReader.

private static byte[]

Returns:

the bytecode read from the given input stream.
readClass
(final InputStream
an input stream from which to read the class.
is
)

Reads the bytecode of a class.

private int

Returns:

the read value.
readInt
(final int
the start index of the value to be read in b.
index
)

Reads a signed int value in b.

private int
readMethod(BytecodeReadingParanamer.TypeCollector classVisitor, char[] c, int u)

private int

Returns:

the read value.
readUnsignedShort
(final int
the start index of the value to be read in b.
index
)

Reads an unsigned short value in b.

private String

Returns:

the String corresponding to the specified UTF8 string.
readUTF
(int
start offset of the UTF8 string to be read.
index
,
final int
length of the UTF8 string to be read.
utfLen
,
final char[]
buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.
buf
)

Reads UTF8 string in b.

private String

Returns:

the String corresponding to the specified UTF8 item.
readUTF8
(int
the start index of an unsigned short value in b, whose value is the index of an UTF8 constant pool item.
index
,
final char[]
buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.
buf
)

Reads an UTF8 string constant pool item in b.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bback to summary
public final byte[] b

The class to be parsed. The content of this array must not be modified. This field is intended for Attribute sub classes, and is normally not needed by class generators or adapters.

DOUBLEback to summary
pack-priv static final int DOUBLE

The type of CONSTANT_Double constant pool items.

FIELDback to summary
pack-priv static final int FIELD

The type of CONSTANT_Fieldref constant pool items.

FLOATback to summary
pack-priv static final int FLOAT

The type of CONSTANT_Float constant pool items.

headerback to summary
public final int header

Start index of the class header information (access, name...) in b.

IMETHback to summary
pack-priv static final int IMETH

The type of CONSTANT_InterfaceMethodref constant pool items.

INTback to summary
pack-priv static final int INT

The type of CONSTANT_Integer constant pool items.

INVOKEDYNback to summary
pack-priv static final int INVOKEDYN

The type of CONSTANT_InvokeDynamic constant pool items.

itemsback to summary
private final int[] items

The start index of each constant pool item in b, plus one. The one byte offset skips the constant pool item tag that indicates its type.

LONGback to summary
pack-priv static final int LONG

The type of CONSTANT_Long constant pool items.

maxStringLengthback to summary
private final int maxStringLength

Maximum length of the strings contained in the constant pool of the class.

METHback to summary
pack-priv static final int METH

The type of CONSTANT_Methodref constant pool items.

MHANDLEback to summary
pack-priv static final int MHANDLE

The type of CONSTANT_MethodHandle constant pool items.

NAME_TYPEback to summary
pack-priv static final int NAME_TYPE

The type of CONSTANT_NameAndType constant pool items.

stringsback to summary
private final String[] strings

The String objects corresponding to the CONSTANT_Utf8 items. This cache avoids multiple parsing of a given CONSTANT_Utf8 constant pool item, which GREATLY improves performances (by a factor 2 to 3). This caching strategy could be extended to all constant pool items, but its benefit would not be so great for these items (because they are much less expensive to parse than CONSTANT_Utf8 items).

UTF8back to summary
pack-priv static final int UTF8

The type of CONSTANT_Utf8 constant pool items.

Constructor Detail

ClassReaderback to summary
private ClassReader(final byte[] b)

Constructs a new ClassReader object.

Parameters
b:byte[]

the bytecode of the class to be read.

ClassReaderback to summary
private ClassReader(final byte[] b, final int off)

Constructs a new ClassReader object.

Parameters
b:byte[]

the bytecode of the class to be read.

off:int

the start offset of the class data.

ClassReaderback to summary
private ClassReader(final InputStream is) throws IOException

Constructs a new ClassReader object.

Parameters
is:InputStream

an input stream from which to read the class.

Exceptions
IOException:
if a problem occurs during reading.

Method Detail

acceptback to summary
private void accept(final BytecodeReadingParanamer.TypeCollector classVisitor)

Makes the given visitor visit the Java class of this ClassReader. This class is the one specified in the constructor (see ClassReader).

Parameters
classVisitor:BytecodeReadingParanamer.TypeCollector

the visitor that must visit this class.

readClassback to summary
private static byte[] readClass(final InputStream is) throws IOException

Reads the bytecode of a class.

Parameters
is:InputStream

an input stream from which to read the class.

Returns:byte[]

the bytecode read from the given input stream.

Exceptions
IOException:
if a problem occurs during reading.
readIntback to summary
private int readInt(final int index)

Reads a signed int value in b. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.

Parameters
index:int

the start index of the value to be read in b.

Returns:int

the read value.

readMethodback to summary
private int readMethod(BytecodeReadingParanamer.TypeCollector classVisitor, char[] c, int u)
readUnsignedShortback to summary
private int readUnsignedShort(final int index)

Reads an unsigned short value in b. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.

Parameters
index:int

the start index of the value to be read in b.

Returns:int

the read value.

readUTFback to summary
private String readUTF(int index, final int utfLen, final char[] buf)

Reads UTF8 string in b.

Parameters
index:int

start offset of the UTF8 string to be read.

utfLen:int

length of the UTF8 string to be read.

buf:char[]

buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.

Returns:String

the String corresponding to the specified UTF8 string.

readUTF8back to summary
private String readUTF8(int index, final char[] buf)

Reads an UTF8 string constant pool item in b. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.

Parameters
index:int

the start index of an unsigned short value in b, whose value is the index of an UTF8 constant pool item.

buf:char[]

buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.

Returns:String

the String corresponding to the specified UTF8 item.

com.thoughtworks.paranamer back to summary

private Class BytecodeReadingParanamer.MethodCollector

extends Object
Class Inheritance
  • java.lang.Object
  • com.thoughtworks.paranamer.BytecodeReadingParanamer.MethodCollector

Objects of this class collects information from a specific method.
Author
Guilherme Silveira

Field Summary

Modifier and TypeField and Description
private int
private boolean
private final int
private final int
private final StringBuffer

Constructor Summary

AccessConstructor and Description
private
MethodCollector(int ignoreCount, int paramCount)

Method Summary

Modifier and TypeMethod and Description
private String
private boolean
public void
visitLocalVariable(String name, int index)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentParameterback to summary
private int currentParameter
debugInfoPresentback to summary
private boolean debugInfoPresent
ignoreCountback to summary
private final int ignoreCount
paramCountback to summary
private final int paramCount
resultback to summary
private final StringBuffer result

Constructor Detail

MethodCollectorback to summary
private MethodCollector(int ignoreCount, int paramCount)

Method Detail

getResultback to summary
private String getResult()
isDebugInfoPresentback to summary
private boolean isDebugInfoPresent()
visitLocalVariableback to summary
public void visitLocalVariable(String name, int index)
com.thoughtworks.paranamer back to summary

private Class BytecodeReadingParanamer.Type

extends Object
Class Inheritance

A Java type. This class can be used to make it easier to manipulate type and method descriptors.
Authors
Eric Bruneton, Chris Nokleberg

Field Summary

Modifier and TypeField and Description
private static final int
ARRAY

The sort of array reference types.

private static final int
BOOLEAN

The sort of the boolean type.

private static final BytecodeReadingParanamer.Type
BOOLEAN_TYPE

The boolean type.

private char[]
buf

A buffer containing the internal name of this Java type.

private static final int
BYTE

The sort of the byte type.

private static final BytecodeReadingParanamer.Type
BYTE_TYPE

The byte type.

private static final int
CHAR

The sort of the char type.

private static final BytecodeReadingParanamer.Type
CHAR_TYPE

The char type.

private static final int
DOUBLE

The sort of the double type.

private static final BytecodeReadingParanamer.Type
DOUBLE_TYPE

The double type.

private static final int
FLOAT

The sort of the float type.

private static final BytecodeReadingParanamer.Type
FLOAT_TYPE

The float type.

private static final int
INT

The sort of the int type.

private static final BytecodeReadingParanamer.Type
INT_TYPE

The int type.

private final int
len

The length of the internal name of this Java type.

private static final int
LONG

The sort of the long type.

private static final BytecodeReadingParanamer.Type
LONG_TYPE

The long type.

private static final int
OBJECT

The sort of object reference type.

private int
off

The offset of the internal name of this Java type in buf or, for primitive types, the size, descriptor and getOpcode offsets for this type (byte 0 contains the size, byte 1 the descriptor, byte 2 the offset for IALOAD or IASTORE, byte 3 the offset for all other instructions).

private static final int
SHORT

The sort of the short type.

private static final BytecodeReadingParanamer.Type
SHORT_TYPE

The short type.

private final int
sort

The sort of this Java type.

private static final int
VOID

The sort of the void type.

private static final BytecodeReadingParanamer.Type
VOID_TYPE

The void type.

Constructor Summary

AccessConstructor and Description
private
Type(final int
the sort of the primitive type to be constructed.
sort
)

Constructs a primitive type.

private
Type(final int
the sort of the reference type to be constructed.
sort
,
final char[]
a buffer containing the descriptor of the previous type.
buf
,
final int
the offset of this descriptor in the previous buffer.
off
,
final int
the length of this descriptor.
len
)

Constructs a reference type.

Method Summary

Modifier and TypeMethod and Description
private static BytecodeReadingParanamer.Type[]

Returns:

the Java types corresponding to the argument types of the given method descriptor.
getArgumentTypes
(final String
a method descriptor.
methodDescriptor
)

Returns the Java types corresponding to the argument types of the given method descriptor.

private String

Returns:

the fully qualified name of the class corresponding to this type.
getClassName
()

Returns the name of the class corresponding to this type.

private int

Returns:

the number of dimensions of this array type.
getDimensions
()

Returns the number of dimensions of this array type.

private BytecodeReadingParanamer.Type

Returns:

Returns the type of the elements of this array type.
getElementType
()

Returns the type of the elements of this array type.

private static BytecodeReadingParanamer.Type

Returns:

the Java type corresponding to the given type descriptor.
getType
(final char[]
a buffer containing a type descriptor.
buf
,
final int
the offset of this descriptor in the previous buffer.
off
)

Returns the Java type corresponding to the given type descriptor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ARRAYback to summary
private static final int ARRAY

The sort of array reference types.

BOOLEANback to summary
private static final int BOOLEAN

The sort of the boolean type.

BOOLEAN_TYPEback to summary
private static final BytecodeReadingParanamer.Type BOOLEAN_TYPE

The boolean type.

bufback to summary
private char[] buf

A buffer containing the internal name of this Java type. This field is only used for reference types.

BYTEback to summary
private static final int BYTE

The sort of the byte type.

BYTE_TYPEback to summary
private static final BytecodeReadingParanamer.Type BYTE_TYPE

The byte type.

CHARback to summary
private static final int CHAR

The sort of the char type.

CHAR_TYPEback to summary
private static final BytecodeReadingParanamer.Type CHAR_TYPE

The char type.

DOUBLEback to summary
private static final int DOUBLE

The sort of the double type.

DOUBLE_TYPEback to summary
private static final BytecodeReadingParanamer.Type DOUBLE_TYPE

The double type.

FLOATback to summary
private static final int FLOAT

The sort of the float type.

FLOAT_TYPEback to summary
private static final BytecodeReadingParanamer.Type FLOAT_TYPE

The float type.

INTback to summary
private static final int INT

The sort of the int type.

INT_TYPEback to summary
private static final BytecodeReadingParanamer.Type INT_TYPE

The int type.

lenback to summary
private final int len

The length of the internal name of this Java type.

LONGback to summary
private static final int LONG

The sort of the long type.

LONG_TYPEback to summary
private static final BytecodeReadingParanamer.Type LONG_TYPE

The long type.

OBJECTback to summary
private static final int OBJECT

The sort of object reference type.

offback to summary
private int off

The offset of the internal name of this Java type in buf or, for primitive types, the size, descriptor and getOpcode offsets for this type (byte 0 contains the size, byte 1 the descriptor, byte 2 the offset for IALOAD or IASTORE, byte 3 the offset for all other instructions).

SHORTback to summary
private static final int SHORT

The sort of the short type.

SHORT_TYPEback to summary
private static final BytecodeReadingParanamer.Type SHORT_TYPE

The short type.

sortback to summary
private final int sort

The sort of this Java type.

VOIDback to summary
private static final int VOID

The sort of the void type.

VOID_TYPEback to summary
private static final BytecodeReadingParanamer.Type VOID_TYPE

The void type.

Constructor Detail

Typeback to summary
private Type(final int sort)

Constructs a primitive type.

Parameters
sort:int

the sort of the primitive type to be constructed.

Typeback to summary
private Type(final int sort, final char[] buf, final int off, final int len)

Constructs a reference type.

Parameters
sort:int

the sort of the reference type to be constructed.

buf:char[]

a buffer containing the descriptor of the previous type.

off:int

the offset of this descriptor in the previous buffer.

len:int

the length of this descriptor.

Method Detail

getArgumentTypesback to summary
private static BytecodeReadingParanamer.Type[] getArgumentTypes(final String methodDescriptor)

Returns the Java types corresponding to the argument types of the given method descriptor.

Parameters
methodDescriptor:String

a method descriptor.

Returns:BytecodeReadingParanamer.Type[]

the Java types corresponding to the argument types of the given method descriptor.

getClassNameback to summary
private String getClassName()

Returns the name of the class corresponding to this type.

Returns:String

the fully qualified name of the class corresponding to this type.

getDimensionsback to summary
private int getDimensions()

Returns the number of dimensions of this array type. This method should only be used for an array type.

Returns:int

the number of dimensions of this array type.

getElementTypeback to summary
private BytecodeReadingParanamer.Type getElementType()

Returns the type of the elements of this array type. This method should only be used for an array type.

Returns:BytecodeReadingParanamer.Type

Returns the type of the elements of this array type.

getTypeback to summary
private static BytecodeReadingParanamer.Type getType(final char[] buf, final int off)

Returns the Java type corresponding to the given type descriptor.

Parameters
buf:char[]

a buffer containing a type descriptor.

off:int

the offset of this descriptor in the previous buffer.

Returns:BytecodeReadingParanamer.Type

the Java type corresponding to the given type descriptor.

com.thoughtworks.paranamer back to summary

private Class BytecodeReadingParanamer.TypeCollector

extends Object
Class Inheritance
  • java.lang.Object
  • com.thoughtworks.paranamer.BytecodeReadingParanamer.TypeCollector

The type collector waits for an specific method in order to start a method collector.
Author
Guilherme Silveira

Field Summary

Modifier and TypeField and Description
private BytecodeReadingParanamer.MethodCollector
private static final String
private final String
private final Class<?>[]
private final boolean

Constructor Summary

AccessConstructor and Description
private
TypeCollector(String methodName, Class<?>[] parameterTypes, boolean throwExceptionIfMissing)

Method Summary

Modifier and TypeMethod and Description
private String
private String[]
public BytecodeReadingParanamer.MethodCollector
visitMethod(int access, String name, String desc)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

collectorback to summary
private BytecodeReadingParanamer.MethodCollector collector
COMMAback to summary
private static final String COMMA
methodNameback to summary
private final String methodName
parameterTypesback to summary
private final Class<?>[] parameterTypes
throwExceptionIfMissingback to summary
private final boolean throwExceptionIfMissing

Constructor Detail

TypeCollectorback to summary
private TypeCollector(String methodName, Class<?>[] parameterTypes, boolean throwExceptionIfMissing)

Method Detail

correctTypeNameback to summary
private String correctTypeName(BytecodeReadingParanamer.Type[] argumentTypes, int i)
getParameterNamesForMethodback to summary
private String[] getParameterNamesForMethod()
visitMethodback to summary
public BytecodeReadingParanamer.MethodCollector visitMethod(int access, String name, String desc)