|
|||||||||
| Home >> All >> com >> techtrader >> modules >> tools >> [ bytecode overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.techtrader.modules.tools.bytecode
Class BCClass

java.lang.Objectcom.techtrader.modules.tools.bytecode.BCEntity
com.techtrader.modules.tools.bytecode.BCClass
- All Implemented Interfaces:
- Constants, com.techtrader.modules.tools.bytecode.visitor.VisitAcceptor
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.
| Field Summary | |
private int |
_access
|
private int |
_classIndex
|
private java.util.List |
_fields
|
private java.util.List |
_interfaceIndexes
|
private int |
_magic
|
private int |
_majorVersion
|
private java.util.List |
_methods
|
private int |
_minorVersion
|
private com.techtrader.modules.tools.bytecode.lowlevel.ConstantPool |
_pool
|
private int |
_superclassIndex
|
| Fields inherited from class com.techtrader.modules.tools.bytecode.BCEntity |
|
| Constructor Summary | |
BCClass()
Default constructor. |
|
BCClass(BCClass orig)
Create a BCClass that is an exact copy of the given one. |
|
BCClass(java.lang.Class type)
Create a BCClass for the given Class type. |
|
BCClass(java.io.File classFile)
Create a BCClass from the given .class file. |
|
BCClass(java.io.InputStream in)
Create a BCClass from the given stream representing a .class file. |
|
BCClass(java.lang.String name)
Create a new BCClass with the given name. |
|
| Method Summary | |
void |
acceptVisit(com.techtrader.modules.tools.bytecode.visitor.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(java.lang.String name,
java.lang.Class type)
Add a field to this class. |
BCField |
addField(java.lang.String name,
java.lang.String type)
Add a field to this class. |
void |
addInterfaceName(java.lang.String name)
Add an interface to those implemented by this class. |
void |
addInterfaceType(java.lang.Class type)
Add a Class to those implemented by this interface. |
BCMethod |
addMethod()
Add a method to this class. |
BCMethod |
addMethod(java.lang.String name,
java.lang.Class returnType,
java.lang.Class[] paramTypes)
Add a method to this class. |
BCMethod |
addMethod(java.lang.String name,
java.lang.String returnType,
java.lang.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(java.lang.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. |
java.lang.String[] |
getInterfaceNames()
Get the names of the interfaces for this class, including package names. |
java.lang.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(java.lang.String name)
Get the method with the given name. |
BCMethod |
getMethod(java.lang.String name,
java.lang.Class[] params)
Get the method with the given name and param types. |
BCMethod |
getMethod(java.lang.String name,
java.lang.String[] params)
Get the method with the given name and param types. |
BCMethod[] |
getMethods()
Get all the methods of this class. |
BCMethod[] |
getMethods(java.lang.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. |
java.lang.String |
getName()
Get the name of this class, including package name. |
com.techtrader.modules.tools.bytecode.lowlevel.ConstantPool |
getPool()
Return the constant pool for this class. |
int |
getSuperclassIndex()
Get the index in the constant pool of the ClassEntry for the superclass. |
java.lang.String |
getSuperclassName()
Get the name of the superclass for this class, including package name. |
java.lang.Class |
getSuperclassType()
Get the Class object for the superclass of this class. |
java.lang.Class |
getType()
Get the Class object for this class. |
boolean |
implementsInterface(java.lang.Class type)
Return true if the class declares that it implements the given interface. |
boolean |
implementsInterface(java.lang.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(java.lang.Class type)
Read the definition of the given class. |
void |
read(java.io.File classFile)
Read the class definition from the given file. |
void |
read(java.io.InputStream instream)
Read the class definition from the given stream. |
boolean |
removeField(BCField field)
Removes a field from this class. |
boolean |
removeField(java.lang.String name)
Removes the field with the given name from this class. |
boolean |
removeInterfaceName(java.lang.String name)
Remove an interface implmented by this class. |
boolean |
removeInterfaceType(java.lang.Class type)
Remove an interface implemented by this class. |
boolean |
removeMethod(BCMethod method)
Removes a method from this class. |
boolean |
removeMethod(java.lang.String name)
Removes the method with the given name from the class. |
boolean |
removeMethod(java.lang.String name,
java.lang.Class[] params)
Removes the method with the given signature. |
boolean |
removeMethod(java.lang.String name,
java.lang.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(java.lang.String[] interfaces)
Set the interfaces implemented by this class. |
void |
setInterfaceTypes(java.lang.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(java.lang.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(java.lang.String name)
Set the name of the superclass to this class. |
void |
setSuperclassType(java.lang.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(java.io.File classFile)
Write the class to the specified file. |
void |
write(java.io.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 |
| Field Detail |
_magic
private int _magic
_minorVersion
private int _minorVersion
_majorVersion
private int _majorVersion
_access
private int _access
_classIndex
private int _classIndex
_superclassIndex
private int _superclassIndex
_pool
private com.techtrader.modules.tools.bytecode.lowlevel.ConstantPool _pool
_interfaceIndexes
private java.util.List _interfaceIndexes
_methods
private java.util.List _methods
_fields
private java.util.List _fields
| Constructor Detail |
BCClass
public BCClass()
- Default constructor. Creates a new empty class.
BCClass
public BCClass(BCClass orig)
- Create a BCClass that is an exact copy of the given one.
BCClass
public BCClass(java.lang.Class type) throws java.io.IOException
- Create a BCClass for the given Class type.
BCClass
public BCClass(java.lang.String name)
- Create a new BCClass with the given name.
BCClass
public BCClass(java.io.File classFile) throws java.io.IOException
- Create a BCClass from the given .class file.
BCClass
public BCClass(java.io.InputStream in) throws java.io.IOException
- Create a BCClass from the given stream representing a .class file.
| Method Detail |
read
public void read(java.io.File classFile) throws java.io.IOException
- Read the class definition from the given file.
This method resets all information in this instance.
read
public void read(java.io.InputStream instream) throws java.io.IOException
- Read the class definition from the given stream.
This method resets all information in this instance.
read
public void read(java.lang.Class type) throws java.io.IOException
- Read the definition of the given class.
This method resets all information in this instance.
write
public void write()
throws java.io.IOException
- For existing classes, write the new bytecode to the same .class file
the class was laoded from.
write
public void write(java.io.File classFile) throws java.io.IOException
- Write the class to the specified file.
write
public void write(java.io.OutputStream outstream) throws java.io.IOException
- Write the class to the specified stream.
toByteArray
public byte[] toByteArray()
throws java.io.IOException
- Get the contents of this class as a byte array, possibly for use
in a custom ClassLoader.
copy
public 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.
getMagic
public int getMagic()
- Get the magic number for this .class; if this is a valid class, this
should be equal to the VALID_MAGIC constant.
setMagic
public 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).
getMajorVersion
public 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.
setMajorVersion
public 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.
getMinorVersion
public 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.
setMinorVersion
public 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.
getAccessFlags
public int getAccessFlags()
- Return the access flags for this class as a bit array of
ACCESS_XXX constants. This can be used to transfer access flags
between classes without getting/setting each possible access flag.
setAccessFlags
public void setAccessFlags(int access)
- Set the access flags for this class as a bit array of
ACCESS_XXX constants. This can be used to transfer access flags
between classes without getting/setting each possible access flag.
isPublic
public boolean isPublic()
- Manipulate the class access flags.
makePublic
public void makePublic()
- Manipulate the class access flags.
isPackage
public boolean isPackage()
- Manipulate the class access flags.
makePackage
public void makePackage()
- Manipulate the class access flags.
isFinal
public boolean isFinal()
- Manipulate the class access flags.
setFinal
public void setFinal(boolean on)
- Manipulate the class access flags.
isInterface
public boolean isInterface()
- Manipulate the class access flags.
setInterface
public void setInterface(boolean on)
- Manipulate the class access flags.
isAbstract
public boolean isAbstract()
- Manipulate the class access flags.
setAbstract
public void setAbstract(boolean on)
- Manipulate the class access flags.
getIndex
public int getIndex()
- Get the index in the constant pool of the ClassEntry for this class.
setIndex
public void setIndex(int index)
- Set the constant pool index of the ClassEntry for this class.
getName
public java.lang.String getName()
- Get the name of this class, including package name.
setName
public void setName(java.lang.String name)
- Set the name of this class.
getType
public java.lang.Class getType() throws java.lang.ClassNotFoundException
- Get the Class object for this class.
getSuperclassIndex
public int getSuperclassIndex()
- Get the index in the constant pool of the ClassEntry for the
superclass.
setSuperclassIndex
public void setSuperclassIndex(int index)
- Set the constant pool index of the ClassEntry for the superclass.
getSuperclassName
public java.lang.String getSuperclassName()
- Get the name of the superclass for this class, including package name.
setSuperclassName
public void setSuperclassName(java.lang.String name)
- Set the name of the superclass to this class.
getSuperclassType
public java.lang.Class getSuperclassType() throws java.lang.ClassNotFoundException
- Get the Class object for the superclass of this class.
setSuperclassType
public void setSuperclassType(java.lang.Class type)
- Set the Class object for the superclass of this class.
getInterfaceIndexes
public int[] getInterfaceIndexes()
- Get the list of indexes into the constant pool of the ClassEntrys
describing all the interfaces this class implements/extends.
setInterfaceIndexes
public 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.
getInterfaceNames
public java.lang.String[] getInterfaceNames()
- Get the names of the interfaces for this class, including package names.
getInterfaceTypes
public java.lang.Class[] getInterfaceTypes() throws java.lang.ClassNotFoundException
- Get the Class objects for the interfaces of this class.
setInterfaceNames
public void setInterfaceNames(java.lang.String[] interfaces)
- Set the interfaces implemented by this class.
setInterfaceTypes
public void setInterfaceTypes(java.lang.Class[] interfaces)
- Set the interfaces implemented by this class.
clearInterfaces
public void clearInterfaces()
- Clear this class of all interface declarations.
removeInterfaceName
public boolean removeInterfaceName(java.lang.String name)
- Remove an interface implmented by this class.
removeInterfaceType
public boolean removeInterfaceType(java.lang.Class type)
- Remove an interface implemented by this class.
addInterfaceName
public void addInterfaceName(java.lang.String name)
- Add an interface to those implemented by this class.
addInterfaceType
public void addInterfaceType(java.lang.Class type)
- Add a Class to those implemented by this interface.
implementsInterface
public boolean implementsInterface(java.lang.String name)
- Return true if the class declares that it implements the given
interface.
implementsInterface
public boolean implementsInterface(java.lang.Class type)
- Return true if the class declares that it implements the given
interface.
getFields
public BCField[] getFields()
- Get all the fields of this class.
getField
public BCField getField(java.lang.String name)
- Get the field with the given name.
importField
public 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).
importFields
public void importFields(BCClass other)
- Import all fields from another class.
addField
public BCField addField()
- Add a field to this class.
addField
public BCField addField(java.lang.String name, java.lang.String type)
- Add a field to this class.
addField
public BCField addField(java.lang.String name, java.lang.Class type)
- Add a field to this class.
clearFields
public void clearFields()
- Clear all fields from this class.
removeField
public boolean removeField(java.lang.String name)
- Removes the field with the given name from this class.
removeField
public boolean removeField(BCField field)
- Removes a field from this class. After this method, the field
will be invalid, and the result of any operations on it is undefined.
getMethods
public BCMethod[] getMethods()
- Get all the methods of this class.
getMethod
public BCMethod getMethod(java.lang.String name)
- Get the method with the given name. If multiple methods in this class
have this name, which is returned is not defined.
getMethods
public BCMethod[] getMethods(java.lang.String name)
- Get all methods with the given name.
getMethod
public BCMethod getMethod(java.lang.String name, java.lang.String[] params)
- Get the method with the given name and param types.
getMethod
public BCMethod getMethod(java.lang.String name, java.lang.Class[] params)
- Get the method with the given name and param types.
importMethod
public 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).
importMethods
public void importMethods(BCClass other)
- Import all methods from the given class; note that this includes
constructors, static initializers, etc.
addMethod
public BCMethod addMethod()
- Add a method to this class.
addMethod
public BCMethod addMethod(java.lang.String name, java.lang.String returnType, java.lang.String[] paramTypes)
- Add a method to this class.
addMethod
public BCMethod addMethod(java.lang.String name, java.lang.Class returnType, java.lang.Class[] paramTypes)
- Add a method to this class.
clearMethods
public void clearMethods()
- Remove all methods from this class; note that this includes
constructors, static initializers, etc.
removeMethod
public boolean removeMethod(BCMethod method)
- Removes a method from this class. After this method, the method
will be invalid, and the result of any operations on it is undefined.
removeMethod
public boolean removeMethod(java.lang.String name)
- Removes the method with the given name from the class. If multiple
methods have the name, they will all be removed.
removeMethod
public boolean removeMethod(java.lang.String name, java.lang.String[] params)
- Removes the method with the given signature.
removeMethod
public boolean removeMethod(java.lang.String name, java.lang.Class[] params)
- Removes the method with the given signature.
getPool
public com.techtrader.modules.tools.bytecode.lowlevel.ConstantPool getPool()
addDefaultConstructor
public BCMethod addDefaultConstructor()
- Add a default constructor to this class. This method can only be
called if the superclass has been set.
acceptVisit
public void acceptVisit(com.techtrader.modules.tools.bytecode.visitor.BCVisitor visit)
- Description copied from interface:
com.techtrader.modules.tools.bytecode.visitor.VisitAcceptor - 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.
- Specified by:
acceptVisitin interfacecom.techtrader.modules.tools.bytecode.visitor.VisitAcceptor
|
|||||||||
| Home >> All >> com >> techtrader >> modules >> tools >> [ bytecode overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC