Package serp.bytecode
Class BCClass
- java.lang.Object
-
- serp.bytecode.Attributes
-
- serp.bytecode.Annotated
-
- serp.bytecode.BCClass
-
- All Implemented Interfaces:
BCEntity
,VisitAcceptor
public class BCClass extends Annotated implements VisitAcceptor
The BCClass represents a class object in the bytecode framework, in many ways mirroring theClass
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.- Author:
- Abe White
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acceptVisit(BCVisitor visit)
Accept a visit from aBCVisitor
, 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(java.lang.String name, java.lang.Class type)
Add a field to this class.BCField
declareField(java.lang.String name, java.lang.String type)
Add a field to this class.BCField
declareField(java.lang.String name, BCClass type)
Add a field to this class.BCField
declareField(BCField field)
Import the information from given field as a new field in this class.void
declareInterface(java.lang.Class type)
Add an interface to those declared by this class.void
declareInterface(java.lang.String name)
Add an interface to those declared by this class.void
declareInterface(BCClass type)
Add an interface to those declared by this class.BCMethod
declareMethod(java.lang.String name, java.lang.Class returnType, java.lang.Class[] paramTypes)
Add a method to this class.BCMethod
declareMethod(java.lang.String name, java.lang.String returnType, java.lang.String[] paramTypes)
Add a method to this class.BCMethod
declareMethod(java.lang.String name, BCClass returnType, BCClass[] paramTypes)
Add a method to this class.BCMethod
declareMethod(BCMethod method)
Import the information in the given method as a new method of this class.int
getAccessFlags()
Return the access flags for this class as a bit array of ACCESS_XXX constants fromConstants
.java.lang.ClassLoader
getClassLoader()
Return the class loader to use when loading related classes.java.lang.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.java.lang.String
getComponentName()
Return the component type name of this class, or null if not an array.java.lang.Class
getComponentType()
Return the component type of this class, or null if not an array.BCField
getDeclaredField(java.lang.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 ofConstantPool
indexes of theClassEntry
s describing all the interfaces this class declares that it implements/extends.java.lang.String[]
getDeclaredInterfaceNames()
Return the names of the interfaces declared for this class, including package names, or an empty array if none.java.lang.Class[]
getDeclaredInterfaceTypes()
Return theClass
objects for the declared interfaces of this class, or an empty array if none.BCMethod
getDeclaredMethod(java.lang.String name)
Return the declared method with the given name, or null if none.BCMethod
getDeclaredMethod(java.lang.String name, java.lang.Class[] paramTypes)
Return the declared method with the given name and parameter types, or null if none.BCMethod
getDeclaredMethod(java.lang.String name, java.lang.Class returnType, java.lang.Class[] paramTypes)
Return the declared method with the given name and signature, or null if none.BCMethod
getDeclaredMethod(java.lang.String name, java.lang.String[] paramTypes)
Return the declared method with the given name and parameter types, or null if none.BCMethod
getDeclaredMethod(java.lang.String name, java.lang.String returnType, java.lang.String[] paramTypes)
Return the declared method with the given name and signature, or null if none.BCMethod
getDeclaredMethod(java.lang.String name, BCClass[] paramTypes)
Return the declared method with the given name and parameter types, or null if none.BCMethod
getDeclaredMethod(java.lang.String name, BCClass returnType, BCClass[] 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(java.lang.String name)
Return all the declared methods with the given name, or an empty array if none.BCMethod[]
getDeclaredMethods(java.lang.String name, java.lang.Class[] paramTypes)
Return all declared methods with the given name and parameter types.BCMethod[]
getDeclaredMethods(java.lang.String name, java.lang.String[] paramTypes)
Return all declared methods with the given name and parameter types.BCMethod[]
getDeclaredMethods(java.lang.String name, BCClass[] 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(java.lang.String name)
Return all fields with the given name, including those of all superclasses, or an empty array if none.int
getIndex()
Return theConstantPool
index of theClassEntry
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.java.lang.String[]
getInterfaceNames()
Return the names of all unique interfaces implemented by this class, including those of all superclasses.java.lang.Class[]
getInterfaceTypes()
Return theClass
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 toConstants.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(java.lang.String name)
Return the methods with the given name, including those of all superclasses, or an empty array if none.BCMethod[]
getMethods(java.lang.String name, java.lang.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(java.lang.String name, java.lang.String[] paramTypes)
Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none.BCMethod[]
getMethods(java.lang.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.int
getMinorVersion()
Get the minor version of the bytecode spec used for this class.java.lang.String
getName()
Return the name of this class, including package name.java.lang.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 theConstantPool
index of theClassEntry
for the superclass of this class.java.lang.String
getSuperclassName()
Return the name of the superclass for this class, including package name.java.lang.Class
getSuperclassType()
Return theClass
object for the superclass of this class, if it is loadable.java.lang.Class
getType()
Return theClass
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(java.lang.Class type)
Return true if this class or any of its superclasses implement/extend the given interface/class.boolean
isInstanceOf(java.lang.String name)
Return true if this class or any of its superclasses implement/extend the given interface/class.boolean
isInstanceOf(BCClass type)
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(java.lang.String name)
Remove a field from this class.boolean
removeDeclaredField(BCField field)
Remove a field from this class.boolean
removeDeclaredInterface(java.lang.Class type)
Remove an interface declared by this class.boolean
removeDeclaredInterface(java.lang.String name)
Remove an interface declared by this class.boolean
removeDeclaredInterface(BCClass type)
Remove an interface declared by this class.boolean
removeDeclaredMethod(java.lang.String name)
Remove a method from this class.boolean
removeDeclaredMethod(java.lang.String name, java.lang.Class[] paramTypes)
Removes a method from this class.boolean
removeDeclaredMethod(java.lang.String name, java.lang.String[] paramTypes)
Removes a method from this class.boolean
removeDeclaredMethod(java.lang.String name, BCClass[] paramTypes)
Removes a method from this class.boolean
removeDeclaredMethod(BCMethod method)
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 fromConstants
.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 ofConstantPool
indexes of theClassEntry
s describing all the interfaces this class declares it implements/extends; set to null or an empty array if none.void
setDeclaredInterfaces(java.lang.Class[] interfaces)
Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.void
setDeclaredInterfaces(java.lang.String[] interfaces)
Set the interfaces declared implemented/extended by this class; 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
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 theConstantPool
index of theClassEntry
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 toConstants.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(java.lang.String name)
Set the name of this class, including package name.void
setSuperclass(java.lang.Class type)
Set the superclass of this class.void
setSuperclass(java.lang.String name)
Set the superclass of this class.void
setSuperclass(BCClass type)
Set the superclass of this class.void
setSuperclassIndex(int index)
Set theConstantPool
index of theClassEntry
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 customClassLoader
.void
write()
Write the class bytecode to the .class file in the proper directory of the CLASSPATH.void
write(java.io.File classFile)
Write the class bytecode to the specified file.void
write(java.io.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
-
-
-
-
Method Detail
-
write
public void write() throws java.io.IOException
Write the class bytecode to the .class file in the proper directory of the CLASSPATH. The file must exist already, so this method only works on existing classes.- Throws:
java.io.IOException
-
write
public void write(java.io.File classFile) throws java.io.IOException
Write the class bytecode to the specified file.- Throws:
java.io.IOException
-
write
public void write(java.io.OutputStream outstream) throws java.io.IOException
Write the class bytecode to the specified stream.- Throws:
java.io.IOException
-
toByteArray
public byte[] toByteArray()
Return the bytecode of this class as a byte array, possibly for use in a customClassLoader
.
-
getMagic
public int getMagic()
Return the magic number for this class; if this is a valid type, this should be equal toConstants.VALID_MAGIC
(the default value).
-
setMagic
public void setMagic(int magic)
Set the magic number for this class; if this is a valid type, this should be equal toConstants.VALID_MAGIC
(the default value).
-
getMajorVersion
public int getMajorVersion()
Return 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 ofConstants.MAJOR_VERSION
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 ofConstants.MAJOR_VERSION
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 ofConstants.MINOR_VERSION
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 ofConstants.MINOR_VERSION
is safe.
-
getAccessFlags
public int getAccessFlags()
Return the access flags for this class as a bit array of ACCESS_XXX constants fromConstants
. This can be used to transfer access flags between classes without getting/setting each possible flag.
-
setAccessFlags
public void setAccessFlags(int access)
Set the access flags for this class as a bit array of ACCESS_XXX constants fromConstants
. This can be used to transfer access flags between classes without getting/setting each possible 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.
-
isSynthetic
public boolean isSynthetic()
Manipulate the class access flags.
-
setSynthetic
public void setSynthetic(boolean on)
Manipulate the class access flags.
-
isAnnotation
public boolean isAnnotation()
Manipulate the class access flags.
-
setAnnotation
public void setAnnotation(boolean on)
Manipulate the class access flags. Setting to true also makes this an interface.
-
isEnum
public boolean isEnum()
Manipulate the class access flags.
-
setEnum
public void setEnum(boolean on)
Manipulate the class access flags.
-
isPrimitive
public boolean isPrimitive()
Return true if this class is a primitive type.
-
isArray
public boolean isArray()
Return true if this class is an array type.
-
getIndex
public int getIndex()
Return theConstantPool
index of theClassEntry
for this class. Returns 0 if the class does not have a constant pool (such as a primitive or array).
-
setIndex
public void setIndex(int index)
Set theConstantPool
index of theClassEntry
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.
-
getName
public java.lang.String getName()
Return the name of this class, including package name. The name will be in a form suitable for aClass.forName(java.lang.String)
call.
-
getClassName
public java.lang.String getClassName()
Return the name of the class only, without package.
-
getPackageName
public java.lang.String getPackageName()
Return the package name only, without class, or null if none.
-
setName
public void setName(java.lang.String name)
Set the name of this class, including package name.
-
getType
public java.lang.Class getType()
Return theClass
object for this class, if it is loadable.
-
getComponentName
public java.lang.String getComponentName()
Return the component type name of this class, or null if not an array. The name will be in a form suitable for aClass.forName(java.lang.String)
call.
-
getComponentType
public java.lang.Class getComponentType()
Return the component type of this class, or null if not an array.
-
getComponentBC
public BCClass getComponentBC()
Return the component type of this class, or null if not an array.
-
getSuperclassIndex
public int getSuperclassIndex()
Return theConstantPool
index of theClassEntry
for the superclass of this class. Returns -1 if the class does not have a constant pool (such as a primitive or array).
-
setSuperclassIndex
public void setSuperclassIndex(int index)
Set theConstantPool
index of theClassEntry
for the superclass of this class.
-
getSuperclassName
public java.lang.String getSuperclassName()
Return the name of the superclass for this class, including package name. The name will be in a form suitable for aClass.forName(java.lang.String)
call, or null for types without superclasses.
-
getSuperclassType
public java.lang.Class getSuperclassType()
Return theClass
object for the superclass of this class, if it is loadable. Returns null for types without superclasses.
-
getSuperclassBC
public BCClass getSuperclassBC()
Return the bytecode of the superclass of this class, or null for types without superclasses.
-
setSuperclass
public void setSuperclass(java.lang.String name)
Set the superclass of this class.
-
setSuperclass
public void setSuperclass(java.lang.Class type)
Set the superclass of this class.
-
setSuperclass
public void setSuperclass(BCClass type)
Set the superclass of this class.
-
getDeclaredInterfaceIndexes
public int[] getDeclaredInterfaceIndexes()
Return the list ofConstantPool
indexes of theClassEntry
s describing all the interfaces this class declares that it implements/extends.- Returns:
- the implmented interfaces, or an empty array if none
-
setDeclaredInterfaceIndexes
public void setDeclaredInterfaceIndexes(int[] interfaceIndexes)
Set the list ofConstantPool
indexes of theClassEntry
s describing all the interfaces this class declares it implements/extends; set to null or an empty array if none.
-
getDeclaredInterfaceNames
public java.lang.String[] getDeclaredInterfaceNames()
Return the names of the interfaces declared for this class, including package names, or an empty array if none. The names will be in a form suitable for aClass.forName(java.lang.String)
call.
-
getDeclaredInterfaceTypes
public java.lang.Class[] getDeclaredInterfaceTypes()
Return theClass
objects for the declared interfaces of this class, or an empty array if none.
-
getDeclaredInterfaceBCs
public BCClass[] getDeclaredInterfaceBCs()
Return the bytecode for the declared interfaces of this class, or an empty array if none.
-
setDeclaredInterfaces
public void setDeclaredInterfaces(java.lang.String[] interfaces)
Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.
-
setDeclaredInterfaces
public void setDeclaredInterfaces(java.lang.Class[] interfaces)
Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.
-
setDeclaredInterfaces
public void setDeclaredInterfaces(BCClass[] interfaces)
Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.
-
getInterfaceNames
public java.lang.String[] getInterfaceNames()
Return the names of all unique interfaces implemented by this class, including those of all superclasses. The names will be returned in a form suitable for aClass.forName(java.lang.String)
call. This method does not recurse into interfaces-of-interfaces.
-
getInterfaceTypes
public java.lang.Class[] getInterfaceTypes()
Return theClass
objects of all unique interfaces implemented by this class, including those of all superclasses. This method does not recurse into interfaces-of-interfaces.
-
getInterfaceBCs
public BCClass[] getInterfaceBCs()
Return the bytecode of all unique interfaces implemented by this class, including those of all superclasses. This method does not recurse into interfaces-of-interfaces.
-
clearDeclaredInterfaces
public void clearDeclaredInterfaces()
Clear this class of all interface declarations.
-
removeDeclaredInterface
public boolean removeDeclaredInterface(java.lang.String name)
Remove an interface declared by this class.- Returns:
- true if the class had the interface, false otherwise
-
removeDeclaredInterface
public boolean removeDeclaredInterface(java.lang.Class type)
Remove an interface declared by this class.- Returns:
- true if the class had the interface, false otherwise
-
removeDeclaredInterface
public boolean removeDeclaredInterface(BCClass type)
Remove an interface declared by this class.- Returns:
- true if the class had the interface, false otherwise
-
moveDeclaredInterface
public void moveDeclaredInterface(int fromIdx, int toIdx)
Rearrange declared interface order.
-
declareInterface
public void declareInterface(java.lang.String name)
Add an interface to those declared by this class.
-
declareInterface
public void declareInterface(java.lang.Class type)
Add an interface to those declared by this class.
-
declareInterface
public void declareInterface(BCClass type)
Add an interface to those declared by this class.
-
isInstanceOf
public boolean isInstanceOf(java.lang.String name)
Return true if this class or any of its superclasses implement/extend the given interface/class. This method does not recurse into interfaces-of-interfaces.
-
isInstanceOf
public boolean isInstanceOf(java.lang.Class type)
Return true if this class or any of its superclasses implement/extend the given interface/class. This method does not recurse into interfaces-of-interfaces.
-
isInstanceOf
public boolean isInstanceOf(BCClass type)
Return true if this class or any of its superclasses implement/extend the given interface/class. This method does not recurse into interfaces-of-interfaces.
-
getDeclaredFields
public BCField[] getDeclaredFields()
Return all the declared fields of this class, or an empty array if none.
-
getDeclaredField
public BCField getDeclaredField(java.lang.String name)
Return the declared field with the given name, or null if none.
-
getFields
public BCField[] getFields()
Return all the fields of this class, including those of all superclasses, or an empty array if none.
-
getFields
public BCField[] getFields(java.lang.String name)
Return all fields with the given name, including those of all superclasses, or an empty array if none.
-
setDeclaredFields
public void setDeclaredFields(BCField[] fields)
Set the fields for this class; this method is useful for importing all fields from another class. Set to null or empty array if none.
-
declareField
public BCField declareField(BCField field)
Import the information from given field as a new field in this class.- Returns:
- the added field
-
declareField
public BCField declareField(java.lang.String name, java.lang.String type)
Add a field to this class.- Returns:
- the added field
-
declareField
public BCField declareField(java.lang.String name, java.lang.Class type)
Add a field to this class.- Returns:
- the added field
-
declareField
public BCField declareField(java.lang.String name, BCClass type)
Add a field to this class.- Returns:
- the added field
-
clearDeclaredFields
public void clearDeclaredFields()
Clear all fields from this class.
-
removeDeclaredField
public boolean removeDeclaredField(java.lang.String name)
Remove a field from this class. After this method, the removed field will be invalid, and the result of any operations on it is undefined.- Returns:
- true if this class contained the field, false otherwise
-
removeDeclaredField
public boolean removeDeclaredField(BCField field)
Remove a field from this class. After this method, the removed field will be invalid, and the result of any operations on it is undefined.- Returns:
- true if this class contained the field, false otherwise
-
moveDeclaredField
public void moveDeclaredField(int fromIdx, int toIdx)
Rearrange declared field order.
-
getDeclaredMethods
public BCMethod[] getDeclaredMethods()
Return all methods declared by this class. Constructors and static initializers are included.
-
getDeclaredMethod
public BCMethod getDeclaredMethod(java.lang.String name)
Return the declared method with the given name, or null if none. If multiple methods are declared with the given name, which is returned is undefined. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getDeclaredMethods
public BCMethod[] getDeclaredMethods(java.lang.String name)
Return all the declared methods with the given name, or an empty array if none. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getDeclaredMethod
public BCMethod getDeclaredMethod(java.lang.String name, java.lang.String[] paramTypes)
Return the declared method with the given name and parameter types, or null if none. If multiple methods are declared with the given name and parameters, which is returned is undefined. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getDeclaredMethod
public BCMethod getDeclaredMethod(java.lang.String name, java.lang.Class[] paramTypes)
Return the declared method with the given name and parameter types, or null if none. If multiple methods are declared with the given name and parameters, which is returned is undefined. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getDeclaredMethod
public BCMethod getDeclaredMethod(java.lang.String name, BCClass[] paramTypes)
Return the declared method with the given name and parameter types, or null if none. If multiple methods are declared with the given name and parameters, which is returned is undefined. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getDeclaredMethods
public BCMethod[] getDeclaredMethods(java.lang.String name, java.lang.String[] paramTypes)
Return all declared methods with the given name and parameter types. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getDeclaredMethods
public BCMethod[] getDeclaredMethods(java.lang.String name, java.lang.Class[] paramTypes)
Return all declared methods with the given name and parameter types. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getDeclaredMethods
public BCMethod[] getDeclaredMethods(java.lang.String name, BCClass[] paramTypes)
Return all declared methods with the given name and parameter types. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getDeclaredMethod
public BCMethod getDeclaredMethod(java.lang.String name, java.lang.String returnType, java.lang.String[] paramTypes)
Return the declared method with the given name and signature, or null if none. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getDeclaredMethod
public BCMethod getDeclaredMethod(java.lang.String name, java.lang.Class returnType, java.lang.Class[] paramTypes)
Return the declared method with the given name and signature, or null if none. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getDeclaredMethod
public BCMethod getDeclaredMethod(java.lang.String name, BCClass returnType, BCClass[] paramTypes)
Return the declared method with the given name and signature, or null if none. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getMethods
public BCMethod[] getMethods()
Return the methods of this class, including those of all superclasses, or an empty array if none. The base version of methods that are overridden will be included, as will all constructors and static initializers. The methods will be ordered from those in the most-specific type up to those inObject
.
-
getMethods
public BCMethod[] getMethods(java.lang.String name)
Return the methods with the given name, including those of all superclasses, or an empty array if none. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getMethods
public BCMethod[] getMethods(java.lang.String name, java.lang.String[] paramTypes)
Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getMethods
public BCMethod[] getMethods(java.lang.String name, java.lang.Class[] paramTypes)
Return the methods with the given name and parameter types, including those of all superclasses, or an empty array if none. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
getMethods
public BCMethod[] getMethods(java.lang.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. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.
-
setDeclaredMethods
public void setDeclaredMethods(BCMethod[] methods)
Set the methods for this class; this method is useful for importing all methods from another class. Set to null or empty array if none.
-
declareMethod
public BCMethod declareMethod(BCMethod method)
Import the information in the given method as a new method of this class.- Returns:
- the added method
-
declareMethod
public BCMethod declareMethod(java.lang.String name, java.lang.String returnType, java.lang.String[] paramTypes)
Add a method to this class. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.- Returns:
- the added method
-
declareMethod
public BCMethod declareMethod(java.lang.String name, java.lang.Class returnType, java.lang.Class[] paramTypes)
Add a method to this class. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.- Returns:
- the added method
-
declareMethod
public BCMethod declareMethod(java.lang.String name, BCClass returnType, BCClass[] paramTypes)
Add a method to this class. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.- Returns:
- the added method
-
clearDeclaredMethods
public void clearDeclaredMethods()
Clear all declared methods from this class.
-
removeDeclaredMethod
public boolean removeDeclaredMethod(java.lang.String name)
Remove a method from this class. After this method, the removed method will be invalid, and the result of any operations on it is undefined. If multiple methods match the given name, which is removed is undefined. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.- Returns:
- true if this class contained the method, false otherwise
-
removeDeclaredMethod
public boolean removeDeclaredMethod(BCMethod method)
Removes a method from this class. After this method, the removed method will be invalid, and the result of any operations on it is undefined.- Returns:
- true if this class contained the method, false otherwise
-
removeDeclaredMethod
public boolean removeDeclaredMethod(java.lang.String name, java.lang.String[] paramTypes)
Removes a method from this class. After this method, the removed method will be invalid, and the result of any operations on it is undefined. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.- Returns:
- true if this class contained the method, false otherwise
-
removeDeclaredMethod
public boolean removeDeclaredMethod(java.lang.String name, java.lang.Class[] paramTypes)
Removes a method from this class. After this method, the removed method will be invalid, and the result of any operations on it is undefined. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.- Returns:
- true if this class contained the method, false otherwise
-
removeDeclaredMethod
public boolean removeDeclaredMethod(java.lang.String name, BCClass[] paramTypes)
Removes a method from this class. After this method, the removed method will be invalid, and the result of any operations on it is undefined. Note that in bytecode, constructors are named<init>
and static initializers are named<clinit>
.- Returns:
- true if this class contained the method, false otherwise
-
moveDeclaredMethod
public void moveDeclaredMethod(int fromIdx, int toIdx)
Rearrange method order.
-
addDefaultConstructor
public BCMethod addDefaultConstructor()
Convenience method to add a default constructor to this class. If a default constructor already exists, this method will return it without modification. This method can only be called if the superclass has been set.- Returns:
- the default constructor
-
getSourceFile
public SourceFile getSourceFile(boolean add)
Return source file information for the class. Acts internally through theAttributes
interface.- Parameters:
add
- if true, a new source file attribute will be added if not already present- Returns:
- the source file information, or null if none and the
add
param is set to false
-
removeSourceFile
public boolean removeSourceFile()
Remove the source file attribute for the class. Acts internally through theAttributes
interface.- Returns:
- true if there was a file to remove
-
getInnerClasses
public InnerClasses getInnerClasses(boolean add)
Return inner classes information for the class. Acts internally through theAttributes
interface.- Parameters:
add
- if true, a new inner classes attribute will be added if not already present- Returns:
- the inner classes information, or null if none and the
add
param is set to false
-
removeInnerClasses
public boolean removeInnerClasses()
Remove the inner classes attribute for the class. Acts internally through theAttributes
interface.- Returns:
- true if there was an attribute to remove
-
isDeprecated
public boolean isDeprecated()
Convenience method to return deprecation information for the class. Acts internally through theAttributes
interface.
-
setDeprecated
public void setDeprecated(boolean on)
Convenience method to set whether this class should be considered deprecated. Acts internally through theAttributes
interface.
-
acceptVisit
public void acceptVisit(BCVisitor visit)
Description copied from interface:VisitAcceptor
Accept a visit from aBCVisitor
, 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.- Specified by:
acceptVisit
in interfaceVisitAcceptor
-
getProject
public Project getProject()
Description copied from interface:BCEntity
Return the project of the current class.- Specified by:
getProject
in interfaceBCEntity
-
getPool
public ConstantPool getPool()
Description copied from interface:BCEntity
Return the constant pool of the current class.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Description copied from interface:BCEntity
Return the class loader to use when loading related classes.- Specified by:
getClassLoader
in interfaceBCEntity
-
-