|
TechTrader Bytecode Toolkit | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.techtrader.modules.tools.bytecode.BCEntity | +--com.techtrader.modules.tools.bytecode.BCClass
Start here to understand this package. A BCClass is a representation of a bytecode class. It contains methods to manipulate the class object itself as well as methods to manage the fields and methods of the class. As with most entities in the bytecode framework, there are methods to manipulate the low-level state of the class (constant pool indexes, etc), but these methods can safely be ignored in favor of the available high-level methods.
Constructor Summary | |
BCClass()
Default constructor. |
|
BCClass(BCClass orig)
Create a BCClass that is an exact copy of the given one. |
|
BCClass(Class type)
Create a BCClass for the given Class type. |
|
BCClass(File classFile)
Create a BCClass from the given .class file. |
|
BCClass(InputStream in)
Create a BCClass from the given stream representing a .class file. |
|
BCClass(String name)
Create a new BCClass with the given name. |
Method Summary | |
void |
acceptVisit(BCVisitor visit)
Accept a visit from a BCVisitor, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this object. |
BCMethod |
addDefaultConstructor()
Add a default constructor to this class. |
BCField |
addField()
Add a field to this class. |
BCField |
addField(String name,
Class type)
Add a field to this class. |
BCField |
addField(String name,
String type)
Add a field to this class. |
void |
addInterfaceName(String name)
Add an interface to those implemented by this class. |
void |
addInterfaceType(Class type)
Add a Class to those implemented by this interface. |
BCMethod |
addMethod()
Add a method to this class. |
BCMethod |
addMethod(String name,
Class returnType,
Class[] paramTypes)
Add a method to this class. |
BCMethod |
addMethod(String name,
String returnType,
String[] paramTypes)
Add a method to this class. |
void |
clearFields()
Clear all fields from this class. |
void |
clearInterfaces()
Clear this class of all interface declarations. |
void |
clearMethods()
Remove all methods from this class; note that this includes constructors, static initializers, etc. |
void |
copy(BCClass orig)
Copy all of the data from the given original BCClass to this one, recursing into fields, methods, code, the constant pool, etc. |
int |
getAccessFlags()
Return the access flags for this class as a bit array of ACCESS_XXX constants. |
BCField |
getField(String name)
Get the field with the given name. |
BCField[] |
getFields()
Get all the fields of this class. |
int |
getIndex()
Get the index in the constant pool of the ClassEntry for this class. |
int[] |
getInterfaceIndexes()
Get the list of indexes into the constant pool of the ClassEntrys describing all the interfaces this class implements/extends. |
String[] |
getInterfaceNames()
Get the names of the interfaces for this class, including package names. |
Class[] |
getInterfaceTypes()
Get the Class objects for the interfaces of this class. |
int |
getMagic()
Get the magic number for this .class; if this is a valid class, this should be equal to the VALID_MAGIC constant. |
int |
getMajorVersion()
Get the major version of the bytecode spec used for this class; JVMs are only required to operate with versions that they understand; leaving the default value (45) is safe. |
BCMethod |
getMethod(String name)
Get the method with the given name. |
BCMethod |
getMethod(String name,
Class[] params)
Get the method with the given name and param types. |
BCMethod |
getMethod(String name,
String[] params)
Get the method with the given name and param types. |
BCMethod[] |
getMethods()
Get all the methods of this class. |
BCMethod[] |
getMethods(String name)
Get all methods with the given name. |
int |
getMinorVersion()
Get the minor version of the bytecode spec used for this class; JVMs are only required to operate with versions that they understand; leaving the default value (3) is safe. |
String |
getName()
Get the name of this class, including package name. |
ConstantPool |
getPool()
Return the constant pool for this class. |
int |
getSuperclassIndex()
Get the index in the constant pool of the ClassEntry for the superclass. |
String |
getSuperclassName()
Get the name of the superclass for this class, including package name. |
Class |
getSuperclassType()
Get the Class object for the superclass of this class. |
Class |
getType()
Get the Class object for this class. |
boolean |
implementsInterface(Class type)
Return true if the class declares that it implements the given interface. |
boolean |
implementsInterface(String name)
Return true if the class declares that it implements the given interface. |
BCField |
importField(BCField field)
Import the given field from another class, or, if the field belongs to this class, add a duplicate of it (in this case, it is an error not to change the field name). |
void |
importFields(BCClass other)
Import all fields from another class. |
BCMethod |
importMethod(BCMethod method)
Import the given method from another class, or, if the method belongs to this class, add a duplicate of it (in this case, it is an error not to change the method name or parameter types). |
void |
importMethods(BCClass other)
Import all methods from the given class; note that this includes constructors, static initializers, etc. |
boolean |
isAbstract()
Manipulate the class access flags. |
boolean |
isFinal()
Manipulate the class access flags. |
boolean |
isInterface()
Manipulate the class access flags. |
boolean |
isPackage()
Manipulate the class access flags. |
boolean |
isPublic()
Manipulate the class access flags. |
void |
makePackage()
Manipulate the class access flags. |
void |
makePublic()
Manipulate the class access flags. |
void |
read(Class type)
Read the definition of the given class. |
void |
read(File classFile)
Read the class definition from the given file. |
void |
read(InputStream instream)
Read the class definition from the given stream. |
boolean |
removeField(BCField field)
Removes a field from this class. |
boolean |
removeField(String name)
Removes the field with the given name from this class. |
boolean |
removeInterfaceName(String name)
Remove an interface implmented by this class. |
boolean |
removeInterfaceType(Class type)
Remove an interface implemented by this class. |
boolean |
removeMethod(BCMethod method)
Removes a method from this class. |
boolean |
removeMethod(String name)
Removes the method with the given name from the class. |
boolean |
removeMethod(String name,
Class[] params)
Removes the method with the given signature. |
boolean |
removeMethod(String name,
String[] params)
Removes the method with the given signature. |
void |
setAbstract(boolean on)
Manipulate the class access flags. |
void |
setAccessFlags(int access)
Set the access flags for this class as a bit array of ACCESS_XXX constants. |
void |
setFinal(boolean on)
Manipulate the class access flags. |
void |
setIndex(int index)
Set the constant pool index of the ClassEntry for this class. |
void |
setInterface(boolean on)
Manipulate the class access flags. |
void |
setInterfaceIndexes(int[] interfaceIndexes)
Set the list of indexes into the constant pool of the ClassEntrys describing all the interfaces this class implements/extends; set to null if none. |
void |
setInterfaceNames(String[] interfaces)
Set the interfaces implemented by this class. |
void |
setInterfaceTypes(Class[] interfaces)
Set the interfaces implemented by this class. |
void |
setMagic(int magic)
Set the magic number for this .class; if this is a valid class, this should be equal to the VALID_MAGIC constant (the default value). |
void |
setMajorVersion(int majorVersion)
Set the major version of the bytecode spec used for this class; JVMs are only required to operate with versions that they understand; leaving the default value (45) is safe. |
void |
setMinorVersion(int minorVersion)
Set the minor version of the bytecode spec used for this class; JVMs are only required to operate with versions that they understand; leaving the default value (3) is safe. |
void |
setName(String name)
Set the name of this class. |
void |
setSuperclassIndex(int index)
Set the constant pool index of the ClassEntry for the superclass. |
void |
setSuperclassName(String name)
Set the name of the superclass to this class. |
void |
setSuperclassType(Class type)
Set the Class object for the superclass of this class. |
byte[] |
toByteArray()
Get the contents of this class as a byte array, possibly for use in a custom ClassLoader. |
void |
write()
For existing classes, write the new bytecode to the same .class file the class was laoded from. |
void |
write(File classFile)
Write the class to the specified file. |
void |
write(OutputStream outstream)
Write the class to the specified stream. |
Methods inherited from class com.techtrader.modules.tools.bytecode.BCEntity |
addAttribute,
clearAttributes,
getAttribute,
getAttributes,
getAttributes,
importAttribute,
importAttributes,
readAttributes,
removeAttribute,
removeAttribute,
visitAttributes,
writeAttributes |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public BCClass()
public BCClass(BCClass orig)
public BCClass(Class type) throws IOException
public BCClass(String name)
public BCClass(File classFile) throws IOException
public BCClass(InputStream in) throws IOException
Method Detail |
public void read(File classFile) throws IOException
public void read(InputStream instream) throws IOException
public void read(Class type) throws IOException
public void write() throws IOException
public void write(File classFile) throws IOException
public void write(OutputStream outstream) throws IOException
public byte[] toByteArray() throws IOException
public void copy(BCClass orig)
public int getMagic()
public void setMagic(int magic)
public int getMajorVersion()
public void setMajorVersion(int majorVersion)
public int getMinorVersion()
public void setMinorVersion(int minorVersion)
public int getAccessFlags()
public void setAccessFlags(int access)
public boolean isPublic()
public void makePublic()
public boolean isPackage()
public void makePackage()
public boolean isFinal()
public void setFinal(boolean on)
public boolean isInterface()
public void setInterface(boolean on)
public boolean isAbstract()
public void setAbstract(boolean on)
public int getIndex()
public void setIndex(int index)
public String getName()
public void setName(String name)
public Class getType() throws ClassNotFoundException
public int getSuperclassIndex()
public void setSuperclassIndex(int index)
public String getSuperclassName()
public void setSuperclassName(String name)
public Class getSuperclassType() throws ClassNotFoundException
public void setSuperclassType(Class type)
public int[] getInterfaceIndexes()
public void setInterfaceIndexes(int[] interfaceIndexes)
public String[] getInterfaceNames()
public Class[] getInterfaceTypes() throws ClassNotFoundException
public void setInterfaceNames(String[] interfaces)
public void setInterfaceTypes(Class[] interfaces)
public void clearInterfaces()
public boolean removeInterfaceName(String name)
public boolean removeInterfaceType(Class type)
public void addInterfaceName(String name)
public void addInterfaceType(Class type)
public boolean implementsInterface(String name)
public boolean implementsInterface(Class type)
public BCField[] getFields()
public BCField getField(String name)
public BCField importField(BCField field)
public void importFields(BCClass other)
public BCField addField()
public BCField addField(String name, String type)
public BCField addField(String name, Class type)
public void clearFields()
public boolean removeField(String name)
public boolean removeField(BCField field)
public BCMethod[] getMethods()
public BCMethod getMethod(String name)
public BCMethod[] getMethods(String name)
public BCMethod getMethod(String name, String[] params)
public BCMethod getMethod(String name, Class[] params)
public BCMethod importMethod(BCMethod method)
public void importMethods(BCClass other)
public BCMethod addMethod()
public BCMethod addMethod(String name, String returnType, String[] paramTypes)
public BCMethod addMethod(String name, Class returnType, Class[] paramTypes)
public void clearMethods()
public boolean removeMethod(BCMethod method)
public boolean removeMethod(String name)
public boolean removeMethod(String name, String[] params)
public boolean removeMethod(String name, Class[] params)
public ConstantPool getPool()
public BCMethod addDefaultConstructor()
public void acceptVisit(BCVisitor visit)
|
TechTrader Bytecode Toolkit | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |