|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sofya.base.Handler sofya.base.ByteSourceHandler
public class ByteSourceHandler
The ByteSourceHandler provides routines to retrieve bytecode information from Java binary class files.
ByteSourceViewer
Field Summary |
---|
Fields inherited from class sofya.base.Handler |
---|
HANDLER_EXTENSIONS, LINE_SEP |
Constructor Summary | |
---|---|
ByteSourceHandler()
|
Method Summary | |
---|---|
boolean |
classIsAbstract()
Reports whether the loaded class is an abstract class. |
boolean |
classIsInterface()
Reports whether the loaded class represents an interface. |
boolean |
containsMethod(MethodSignature signature)
Reports whether the classfile contains a given method. |
boolean |
containsMethod(java.lang.String methodName)
Reports whether the classfile contains a given method. |
org.apache.bcel.generic.ConstantPoolGen |
getConstantPool()
Returns an unmodifiable view of the BCEL ConstantPoolGen object for the class file loaded in the handler, which is required to obtain information about certain types of instructions. |
org.apache.bcel.generic.InstructionList |
getInstructionList(MethodSignature signature)
Gets bytecode source for a method as a BCEL InstructionList . |
org.apache.bcel.generic.Instruction[] |
getInstructionList(MethodSignature signature,
int startOffset,
int endOffset)
Gets the bytecode source in a method between two instruction offsets, inclusive. |
org.apache.bcel.generic.InstructionList |
getInstructionList(java.lang.String methodName)
Gets bytecode source for a method as a BCEL InstructionList . |
org.apache.bcel.generic.Instruction[] |
getInstructionList(java.lang.String methodName,
int startOffset,
int endOffset)
Gets the bytecode source in a method between two instruction offsets, inclusive. |
java.lang.String[] |
getInstructions(MethodSignature signature)
Gets bytecode source for a method as a list of string representations of the bytecode instructions. |
java.lang.String[] |
getInstructions(MethodSignature signature,
int startOffset,
int endOffset)
Gets the bytecode source in a method between two instruction offsets, inclusive. |
java.lang.String[] |
getInstructions(java.lang.String methodName)
Gets bytecode source for a method as a list of string representations of the bytecode instructions. |
java.lang.String[] |
getInstructions(java.lang.String methodName,
int startOffset,
int endOffset)
Gets the bytecode source in a method between two instruction offsets, inclusive. |
org.apache.bcel.generic.MethodGen |
getMethod(MethodSignature signature)
Retrieves the BCEL full representation of a method present in the class file. |
org.apache.bcel.generic.MethodGen |
getMethod(java.lang.String methodName)
Retrieves the BCEL full representation of a method present in the class file. |
java.lang.String[] |
getMethodList()
Gets the list of methods read from the class file. |
MethodSignature[] |
getSignatureList()
Gets the list of signatures of methods read from the class file. |
java.lang.String |
getSource(MethodSignature signature)
Gets bytecode source for a method in human-readable form. |
java.lang.String |
getSource(java.lang.String methodName)
Gets bytecode source for a method in human-readable form. |
static void |
main(java.lang.String[] args)
Test driver for ByteSourceHandler. |
void |
readSourceFile(java.lang.String className)
Reads bytecode source from file. |
void |
readSourceFile(java.lang.String location,
java.lang.String className)
Reads bytecode source for a class from a given location. |
Methods inherited from class sofya.base.Handler |
---|
copyFile, createCacheFile, disableParseNumbers, ensureTagExists, formatSignature, isIntAvailable, isStringAvailable, newCache, openCacheFile, openInputFile, openInputFile, openOutputFile, openOutputFile, parseClass, prepareTokenizer, readInt, readIntIgnoreEOL, readJarClasses, readNextLine, readProgFile, readString, readStringIgnoreEOL, readToEOL, readToNextDataLine, toBinary, toHex |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ByteSourceHandler()
Method Detail |
---|
public void readSourceFile(java.lang.String className) throws java.io.IOException
The bytecode source is read from the class file and stored to
internal data structures. This data can then be retrieved via other
accessor functions in this class, such as getInstructions(java.lang.String)
.
className
- Name of Java class file from which bytecode source
data is to be read.
java.io.IOException
- If there is an error reading the class file.public void readSourceFile(java.lang.String location, java.lang.String className) throws java.io.IOException
The location provided to this method may be a directory or jar file. This method will not attempt to load a class from the classpath.
location
- Name of the directory or jar file from which the
class should be loaded.className
- Name of the class which is to be loaded. This
parameter should include any additional path information relative
to the location
parameter that is required to find
the class, using path separator characters (not '.').
java.io.IOException
- If there is an error reading the class file.public java.lang.String[] getMethodList()
public MethodSignature[] getSignatureList()
public boolean containsMethod(java.lang.String methodName)
methodName
- Name of the method which the handler should
check for existence.
true
if a method of the given name exists in
the classfile, false
otherwise.public boolean containsMethod(MethodSignature signature)
signature
- Signature of the method which the handler should
check for existence.
true
if a method with the given signature exists in
the classfile, false
otherwise.public java.lang.String getSource(java.lang.String methodName) throws MethodNotFoundException
methodName
- Name of the method for which the bytecode source is
to be retrieved.
null
if the specified method cannot be found.
MethodNotFoundException
- If the handler has no bytecode listing
associated with a method of the specified name.public java.lang.String getSource(MethodSignature signature) throws MethodNotFoundException
signature
- Signature of the method for which the bytecode source
is to be retrieved.
null
if the specified method cannot be found.
MethodNotFoundException
- If the handler has no bytecode listing
associated with a method with the specified signature.public java.lang.String[] getInstructions(java.lang.String methodName) throws MethodNotFoundException
methodName
- Name of the method for which the bytecode source is
to be retrieved.
abstract
or otherwise contains no instructions.
MethodNotFoundException
- If the handler has no bytecode listing
associated with a method of the specified name.public java.lang.String[] getInstructions(MethodSignature signature) throws MethodNotFoundException
signature
- Signature of the method for which the bytecode source
is to be retrieved.
abstract
or otherwise contains no instructions.
MethodNotFoundException
- If the handler has no bytecode listing
associated with a method with the specified signature.public org.apache.bcel.generic.InstructionList getInstructionList(java.lang.String methodName) throws MethodNotFoundException
InstructionList
.
methodName
- Name of the method for which the bytecode source is
to be retrieved.
InstructionList
object containing the
bytecode instructions that constitute the specified method.
MethodNotFoundException
- If the handler has no bytecode listing
associated with a method of the specified name.public org.apache.bcel.generic.InstructionList getInstructionList(MethodSignature signature) throws MethodNotFoundException
InstructionList
.
signature
- Signature of the method for which the bytecode source
is to be retrieved.
InstructionList
object containing the
bytecode instructions that constitute the specified method.
MethodNotFoundException
- If the handler has no bytecode listing
associated with a method with the specified signature.public java.lang.String[] getInstructions(java.lang.String methodName, int startOffset, int endOffset) throws MethodNotFoundException
methodName
- Name of the method for which the bytecode source is
to be retrieved.startOffset
- Offset to the first instruction to be retrieved.endOffset
- Offset to the last instruction to be retrieved.
abstract
.
MethodNotFoundException
- If the handler has no bytecode listing
associated with a method of the specified name.public java.lang.String[] getInstructions(MethodSignature signature, int startOffset, int endOffset) throws MethodNotFoundException
signature
- Signature of the method for which the bytecode source
is to be retrieved.startOffset
- Offset to the first instruction to be retrieved.endOffset
- Offset to the last instruction to be retrieved.
abstract
.
MethodNotFoundException
- If the handler has no bytecode listing
associated with a method with the specified signature.public org.apache.bcel.generic.Instruction[] getInstructionList(java.lang.String methodName, int startOffset, int endOffset) throws MethodNotFoundException
methodName
- Name of the method for which the bytecode source is
to be retrieved.startOffset
- Offset to the first instruction to be retrieved.endOffset
- Offset to the last instruction to be retrieved.
Instruction
objects representing
the bytecode in the given range.
MethodNotFoundException
- If the handler has no bytecode listing
associated with a method of the specified name.public org.apache.bcel.generic.Instruction[] getInstructionList(MethodSignature signature, int startOffset, int endOffset) throws MethodNotFoundException
signature
- Signature of the method for which the bytecode source
is to be retrieved.startOffset
- Offset to the first instruction to be retrieved.endOffset
- Offset to the last instruction to be retrieved.
Instruction
objects representing
the bytecode in the given range.
MethodNotFoundException
- If the handler has no bytecode listing
associated with a method with the specified signature.public org.apache.bcel.generic.MethodGen getMethod(java.lang.String methodName) throws MethodNotFoundException
methodName
- Name of the method to be retrieved.
MethodNotFoundException
public org.apache.bcel.generic.MethodGen getMethod(MethodSignature signature) throws MethodNotFoundException
signature
- Signature of the method to be retrieved.
MethodNotFoundException
public org.apache.bcel.generic.ConstantPoolGen getConstantPool()
UnsupportedOperationException
being thrown.public boolean classIsInterface()
true
if the class is an interface,
false
otherwise.public boolean classIsAbstract()
true
if the class is abstract,
false
otherwise.public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |