|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectserp.bytecode.Attributes
serp.bytecode.Annotated
serp.bytecode.BCClass
public class BCClass
The BCClass represents a class object in the bytecode framework, in many
ways mirroring the Class
class of Java reflection. The represented
class might be a primitive, array, existing object type, or some new user-
defined type. As with most entities in the bytecode framework, the BCClass
contains methods to manipulate the low-level state of the class (constant
pool indexes, etc), but these can and should be ignored in
favor of the available high-level methods.
A BCClass instance is loaded from a Project
and remains
attached to that project for its lifetime. If a BCClass is removed from
its project, the result of any further operations on the class are
undefined.
Note that if a BCClass represents a primitive or array type, all of the
available mutator methods and any methods that access the constant pool
will throw UnsupportedOperationException
s.
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 one. |
BCMethod |
addDefaultConstructor()
Convenience method to add a default constructor to this class. |
void |
clearDeclaredFields()
Clear all fields from this class. |
void |
clearDeclaredInterfaces()
Clear this class of all interface declarations. |
void |
clearDeclaredMethods()
Clear all declared methods from this class. |
BCField |
declareField(BCField field)
Import the information from given field as a new field in this class. |
BCField |
declareField(String name,
BCClass type)
Add a field to this class. |
BCField |
declareField(String name,
Class type)
Add a field to this class. |
BCField |
declareField(String name,
String type)
Add a field to this class. |
void |
declareInterface(BCClass type)
Add an interface to those declared by this class. |
void |
declareInterface(Class type)
Add an interface to those declared by this class. |
void |
declareInterface(String name)
Add an interface to those declared by this class. |
BCMethod |
declareMethod(BCMethod method)
Import the information in the given method as a new method of this class. |
BCMethod |
declareMethod(String name,
BCClass returnType,
BCClass[] paramTypes)
Add a method to this class. |
BCMethod |
declareMethod(String name,
Class returnType,
Class[] paramTypes)
Add a method to this class. |
BCMethod |
declareMethod(String name,
String returnType,
String[] paramTypes)
Add a method to this class. |
int |
getAccessFlags()
Return the access flags for this class as a bit array of ACCESS_XXX constants from Constants . |
ClassLoader |
getClassLoader()
Return the class loader to use when loading related classes. |
String |
getClassName()
Return the name of the class only, without package. |
BCClass |
getComponentBC()
Return the component type of this class, or null if not an array. |
String |
getComponentName()
Return the component type name of this class, or null if not an array. |
Class |
getComponentType()
Return the component type of this class, or null if not an array. |
BCField |
getDeclaredField(String name)
Return the declared field with the given name, or null if none. |
BCField[] |
getDeclaredFields()
Return all the declared fields of this class, or an empty array if none. |
BCClass[] |
getDeclaredInterfaceBCs()
Return the bytecode for the declared interfaces of this class, or an empty array if none. |
int[] |
getDeclaredInterfaceIndexes()
Return the list of ConstantPool indexes of the
ClassEntry s describing all the interfaces this class declares
that it implements/extends. |
String[] |
getDeclaredInterfaceNames()
Return the names of the interfaces declared for this class, including package names, or an empty array if none. |
Class[] |
getDeclaredInterfaceTypes()
Return the Class objects for the declared interfaces of this
class, or an empty array if none. |
BCMethod |
getDeclaredMethod(String name)
Return the declared method with the given name, or null if none. |
BCMethod |
getDeclaredMethod(String name,
BCClass[] paramTypes)
Return the declared method with the given name and parameter types, or null if none. |
BCMethod |
getDeclaredMethod(String name,
BCClass returnType,
BCClass[] paramTypes)
Return the declared method with the given name and signature, or null if none. |
BCMethod |
getDeclaredMethod(String name,
Class[] paramTypes)
Return the declared method with the given name and parameter types, or null if none. |
BCMethod |
getDeclaredMethod(String name,
Class returnType,
Class[] paramTypes)
Return the declared method with the given name and signature, or null if none. |
BCMethod |
getDeclaredMethod(String name,
String[] paramTypes)
Return the declared method with the given name and parameter types, or null if none. |
BCMethod |
getDeclaredMethod(String name,
String returnType,
String[] paramTypes)
Return the declared method with the given name and signature, or null if none. |
BCMethod[] |
getDeclaredMethods()
Return all methods declared by this class. |
BCMethod[] |
getDeclaredMethods(String name)
Return all the declared methods with the given name, or an empty array if none. |
BCMethod[] |
getDeclaredMethods(String name,
BCClass[] paramTypes)
Return all declared methods with the given name and parameter types. |
BCMethod[] |
getDeclaredMethods(String name,
Class[] paramTypes)
Return all declared methods with the given name and parameter types. |
BCMethod[] |
getDeclaredMethods(String name,
String[] paramTypes)
Return all declared methods with the given name and parameter types. |
BCField[] |
getFields()
Return all the fields of this class, including those of all superclasses, or an empty array if none. |
BCField[] |
getFields(String name)
Return all fields with the given name, including those of all superclasses, or an empty array if none. |
int |
getIndex()
Return the ConstantPool index of the
ClassEntry for this class. |
InnerClasses |
getInnerClasses(boolean add)
Return inner classes information for the class. |
BCClass[] |
getInterfaceBCs()
Return the bytecode of all unique interfaces implemented by this class, including those of all superclasses. |
String[] |
getInterfaceNames()
Return the names of all unique interfaces implemented by this class, including those of all superclasses. |
Class[] |
getInterfaceTypes()
Return the Class objects of all unique interfaces implemented
by this class, including those of all superclasses. |
int |
getMagic()
Return the magic number for this class; if this is a valid type, this should be equal to Constants.VALID_MAGIC (the default value). |
int |
getMajorVersion()
Return the major version of the bytecode spec used for this class. |
BCMethod[] |
getMethods()
Return the methods of this class, including those of all superclasses, or an empty array if none. |
BCMethod[] |
getMethods(String name)
Return the methods with the given name, including those of all superclasses, or an empty array if none. |
BCMethod[] |
getMethods(String name,
BCClass[] paramTypes)
Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none. |
BCMethod[] |
getMethods(String name,
Class[] paramTypes)
Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none. |
BCMethod[] |
getMethods(String name,
String[] paramTypes)
Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none. |
int |
getMinorVersion()
Get the minor version of the bytecode spec used for this class. |
String |
getName()
Return the name of this class, including package name. |
String |
getPackageName()
Return the package name only, without class, or null if none. |
ConstantPool |
getPool()
Return the constant pool of the current class. |
Project |
getProject()
Return the project of the current class. |
SourceFile |
getSourceFile(boolean add)
Return source file information for the class. |
BCClass |
getSuperclassBC()
Return the bytecode of the superclass of this class, or null for types without superclasses. |
int |
getSuperclassIndex()
Return the ConstantPool index of the
ClassEntry for the superclass of this class. |
String |
getSuperclassName()
Return the name of the superclass for this class, including package name. |
Class |
getSuperclassType()
Return the Class object for the superclass of this class, if it
is loadable. |
Class |
getType()
Return the Class object for this class, if it is loadable. |
boolean |
isAbstract()
Manipulate the class access flags. |
boolean |
isAnnotation()
Manipulate the class access flags. |
boolean |
isArray()
Return true if this class is an array type. |
boolean |
isDeprecated()
Convenience method to return deprecation information for the class. |
boolean |
isEnum()
Manipulate the class access flags. |
boolean |
isFinal()
Manipulate the class access flags. |
boolean |
isInstanceOf(BCClass type)
Return true if this class or any of its superclasses implement/extend the given interface/class. |
boolean |
isInstanceOf(Class type)
Return true if this class or any of its superclasses implement/extend the given interface/class. |
boolean |
isInstanceOf(String name)
Return true if this class or any of its superclasses implement/extend the given interface/class. |
boolean |
isInterface()
Manipulate the class access flags. |
boolean |
isPackage()
Manipulate the class access flags. |
boolean |
isPrimitive()
Return true if this class is a primitive type. |
boolean |
isPublic()
Manipulate the class access flags. |
boolean |
isSynthetic()
Manipulate the class access flags. |
boolean |
isValid()
Return false if this entity has been removed from its parent; in this case the results of any operations on the entity are undefined. |
void |
makePackage()
Manipulate the class access flags. |
void |
makePublic()
Manipulate the class access flags. |
void |
moveDeclaredField(int fromIdx,
int toIdx)
Rearrange declared field order. |
void |
moveDeclaredInterface(int fromIdx,
int toIdx)
Rearrange declared interface order. |
void |
moveDeclaredMethod(int fromIdx,
int toIdx)
Rearrange method order. |
boolean |
removeDeclaredField(BCField field)
Remove a field from this class. |
boolean |
removeDeclaredField(String name)
Remove a field from this class. |
boolean |
removeDeclaredInterface(BCClass type)
Remove an interface declared by this class. |
boolean |
removeDeclaredInterface(Class type)
Remove an interface declared by this class. |
boolean |
removeDeclaredInterface(String name)
Remove an interface declared by this class. |
boolean |
removeDeclaredMethod(BCMethod method)
Removes a method from this class. |
boolean |
removeDeclaredMethod(String name)
Remove a method from this class. |
boolean |
removeDeclaredMethod(String name,
BCClass[] paramTypes)
Removes a method from this class. |
boolean |
removeDeclaredMethod(String name,
Class[] paramTypes)
Removes a method from this class. |
boolean |
removeDeclaredMethod(String name,
String[] paramTypes)
Removes a method from this class. |
boolean |
removeInnerClasses()
Remove the inner classes attribute for the class. |
boolean |
removeSourceFile()
Remove the source file attribute for the class. |
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 from Constants . |
void |
setAnnotation(boolean on)
Manipulate the class access flags. |
void |
setDeclaredFields(BCField[] fields)
Set the fields for this class; this method is useful for importing all fields from another class. |
void |
setDeclaredInterfaceIndexes(int[] interfaceIndexes)
Set the list of ConstantPool indexes of the
ClassEntry s describing all the interfaces this class declares
it implements/extends; set to null or an empty array if none. |
void |
setDeclaredInterfaces(BCClass[] interfaces)
Set the interfaces declared implemented/extended by this class; set to null or an empty array if none. |
void |
setDeclaredInterfaces(Class[] interfaces)
Set the interfaces declared implemented/extended by this class; set to null or an empty array if none. |
void |
setDeclaredInterfaces(String[] interfaces)
Set the interfaces declared implemented/extended by this class; set to null or an empty array if none. |
void |
setDeclaredMethods(BCMethod[] methods)
Set the methods for this class; this method is useful for importing all methods from another class. |
void |
setDeprecated(boolean on)
Convenience method to set whether this class should be considered deprecated. |
void |
setEnum(boolean on)
Manipulate the class access flags. |
void |
setFinal(boolean on)
Manipulate the class access flags. |
void |
setIndex(int index)
Set the ConstantPool index of the ClassEntry for this
class. |
void |
setInterface(boolean on)
Manipulate the class access flags. |
void |
setMagic(int magic)
Set the magic number for this class; if this is a valid type, this should be equal to Constants.VALID_MAGIC (the default value). |
void |
setMajorVersion(int majorVersion)
Set the major version of the bytecode spec used for this class. |
void |
setMinorVersion(int minorVersion)
Set the minor version of the bytecode spec used for this class. |
void |
setName(String name)
Set the name of this class, including package name. |
void |
setSuperclass(BCClass type)
Set the superclass of this class. |
void |
setSuperclass(Class type)
Set the superclass of this class. |
void |
setSuperclass(String name)
Set the superclass of this class. |
void |
setSuperclassIndex(int index)
Set the ConstantPool index of the
ClassEntry for the superclass of this class. |
void |
setSynthetic(boolean on)
Manipulate the class access flags. |
byte[] |
toByteArray()
Return the bytecode of this class as a byte array, possibly for use in a custom ClassLoader . |
void |
write()
Write the class bytecode to the .class file in the proper directory of the CLASSPATH. |
void |
write(File classFile)
Write the class bytecode to the specified file. |
void |
write(OutputStream outstream)
Write the class bytecode to the specified stream. |
Methods inherited from class serp.bytecode.Annotated |
---|
getDeclaredAnnotations, getDeclaredRuntimeAnnotations, removeDeclaredAnnotations, removeDeclaredRuntimeAnnotations |
Methods inherited from class serp.bytecode.Attributes |
---|
addAttribute, addAttribute, clearAttributes, getAttribute, getAttributes, getAttributes, removeAttribute, removeAttribute, setAttributes |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public void write() throws IOException
IOException
public void write(File classFile) throws IOException
IOException
public void write(OutputStream outstream) throws IOException
IOException
public byte[] toByteArray()
ClassLoader
.
public int getMagic()
Constants.VALID_MAGIC
(the default value).
public void setMagic(int magic)
Constants.VALID_MAGIC
(the default value).
public int getMajorVersion()
Constants.MAJOR_VERSION
is safe.
public void setMajorVersion(int majorVersion)
Constants.MAJOR_VERSION
is safe.
public int getMinorVersion()
Constants.MINOR_VERSION
is safe.
public void setMinorVersion(int minorVersion)
Constants.MINOR_VERSION
is safe.
public int getAccessFlags()
Constants
. This can be used to
transfer access flags between classes without getting/setting each
possible flag.
public void setAccessFlags(int access)
Constants
. This can be used to
transfer access flags between classes without getting/setting each
possible flag.
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 boolean isSynthetic()
public void setSynthetic(boolean on)
public boolean isAnnotation()
public void setAnnotation(boolean on)
public boolean isEnum()
public void setEnum(boolean on)
public boolean isPrimitive()
public boolean isArray()
public int getIndex()
ConstantPool
index of the
ClassEntry
for this class. Returns 0 if the class does not
have a constant pool (such as a primitive or array).
public void setIndex(int index)
ConstantPool
index of the ClassEntry
for this
class. Unlike most other low-level methods, the index
will be checked against the pool immediately;
classes must have a valid name at all times.
public String getName()
Class.forName(java.lang.String)
call.
public String getClassName()
public String getPackageName()
public void setName(String name)
public Class getType()
Class
object for this class, if it is loadable.
public String getComponentName()
Class.forName(java.lang.String)
call.
public Class getComponentType()
public BCClass getComponentBC()
public int getSuperclassIndex()
ConstantPool
index of the
ClassEntry
for the superclass of this class. Returns -1 if
the class does not have a constant pool (such as a primitive or array).
public void setSuperclassIndex(int index)
ConstantPool
index of the
ClassEntry
for the superclass of this class.
public String getSuperclassName()
Class.forName(java.lang.String)
call, or null for types without superclasses.
public Class getSuperclassType()
Class
object for the superclass of this class, if it
is loadable. Returns null for types without superclasses.
public BCClass getSuperclassBC()
public void setSuperclass(String name)
public void setSuperclass(Class type)
public void setSuperclass(BCClass type)
public int[] getDeclaredInterfaceIndexes()
ConstantPool
indexes of the
ClassEntry
s describing all the interfaces this class declares
that it implements/extends.
public void setDeclaredInterfaceIndexes(int[] interfaceIndexes)
ConstantPool
indexes of the
ClassEntry
s describing all the interfaces this class declares
it implements/extends; set to null or an empty array if none.
public String[] getDeclaredInterfaceNames()
Class.forName(java.lang.String)
call.
public Class[] getDeclaredInterfaceTypes()
Class
objects for the declared interfaces of this
class, or an empty array if none.
public BCClass[] getDeclaredInterfaceBCs()
public void setDeclaredInterfaces(String[] interfaces)
public void setDeclaredInterfaces(Class[] interfaces)
public void setDeclaredInterfaces(BCClass[] interfaces)
public String[] getInterfaceNames()
Class.forName(java.lang.String)
call.
This method does not recurse into interfaces-of-interfaces.
public Class[] getInterfaceTypes()
Class
objects of all unique interfaces implemented
by this class, including those of all superclasses.
This method does not recurse into interfaces-of-interfaces.
public BCClass[] getInterfaceBCs()
public void clearDeclaredInterfaces()
public boolean removeDeclaredInterface(String name)
public boolean removeDeclaredInterface(Class type)
public boolean removeDeclaredInterface(BCClass type)
public void moveDeclaredInterface(int fromIdx, int toIdx)
public void declareInterface(String name)
public void declareInterface(Class type)
public void declareInterface(BCClass type)
public boolean isInstanceOf(String name)
public boolean isInstanceOf(Class type)
public boolean isInstanceOf(BCClass type)
public BCField[] getDeclaredFields()
public BCField getDeclaredField(String name)
public BCField[] getFields()
public BCField[] getFields(String name)
public void setDeclaredFields(BCField[] fields)
public BCField declareField(BCField field)
public BCField declareField(String name, String type)
public BCField declareField(String name, Class type)
public BCField declareField(String name, BCClass type)
public void clearDeclaredFields()
public boolean removeDeclaredField(String name)
public boolean removeDeclaredField(BCField field)
public void moveDeclaredField(int fromIdx, int toIdx)
public BCMethod[] getDeclaredMethods()
public BCMethod getDeclaredMethod(String name)
<init>
and static initializers are named <clinit>
.
public BCMethod[] getDeclaredMethods(String name)
<init>
and static initializers are named <clinit>
.
public BCMethod getDeclaredMethod(String name, String[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod getDeclaredMethod(String name, Class[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod getDeclaredMethod(String name, BCClass[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod[] getDeclaredMethods(String name, String[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod[] getDeclaredMethods(String name, Class[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod[] getDeclaredMethods(String name, BCClass[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod getDeclaredMethod(String name, String returnType, String[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod getDeclaredMethod(String name, Class returnType, Class[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod getDeclaredMethod(String name, BCClass returnType, BCClass[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod[] getMethods()
Object
.
public BCMethod[] getMethods(String name)
<init>
and static initializers are named <clinit>
.
public BCMethod[] getMethods(String name, String[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod[] getMethods(String name, Class[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod[] getMethods(String name, BCClass[] paramTypes)
<init>
and static initializers are named <clinit>
.
public void setDeclaredMethods(BCMethod[] methods)
public BCMethod declareMethod(BCMethod method)
public BCMethod declareMethod(String name, String returnType, String[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod declareMethod(String name, Class returnType, Class[] paramTypes)
<init>
and static initializers are named <clinit>
.
public BCMethod declareMethod(String name, BCClass returnType, BCClass[] paramTypes)
<init>
and static initializers are named <clinit>
.
public void clearDeclaredMethods()
public boolean removeDeclaredMethod(String name)
<init>
and static initializers are named <clinit>
.
public boolean removeDeclaredMethod(BCMethod method)
public boolean removeDeclaredMethod(String name, String[] paramTypes)
<init>
and static initializers are named <clinit>
.
public boolean removeDeclaredMethod(String name, Class[] paramTypes)
<init>
and static initializers are named <clinit>
.
public boolean removeDeclaredMethod(String name, BCClass[] paramTypes)
<init>
and static initializers are named <clinit>
.
public void moveDeclaredMethod(int fromIdx, int toIdx)
public BCMethod addDefaultConstructor()
public SourceFile getSourceFile(boolean add)
Attributes
interface.
add
- if true, a new source file attribute will be added
if not already present
add
param is set to falsepublic boolean removeSourceFile()
Attributes
interface.
public InnerClasses getInnerClasses(boolean add)
Attributes
interface.
add
- if true, a new inner classes attribute will be added
if not already present
add
param is set to falsepublic boolean removeInnerClasses()
Attributes
interface.
public boolean isDeprecated()
Attributes
interface.
public void setDeprecated(boolean on)
Attributes
interface.
public void acceptVisit(BCVisitor visit)
VisitAcceptor
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 one.
acceptVisit
in interface VisitAcceptor
public Project getProject()
BCEntity
getProject
in interface BCEntity
public ConstantPool getPool()
BCEntity
getPool
in interface BCEntity
public ClassLoader getClassLoader()
BCEntity
getClassLoader
in interface BCEntity
public boolean isValid()
BCEntity
isValid
in interface BCEntity
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |