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 theClassclass 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
Projectand 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
UnsupportedOperationExceptions.- Author:
- Abe White
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacceptVisit(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.BCMethodaddDefaultConstructor()Convenience method to add a default constructor to this class.voidclearDeclaredFields()Clear all fields from this class.voidclearDeclaredInterfaces()Clear this class of all interface declarations.voidclearDeclaredMethods()Clear all declared methods from this class.BCFielddeclareField(java.lang.String name, java.lang.Class type)Add a field to this class.BCFielddeclareField(java.lang.String name, java.lang.String type)Add a field to this class.BCFielddeclareField(java.lang.String name, BCClass type)Add a field to this class.BCFielddeclareField(BCField field)Import the information from given field as a new field in this class.voiddeclareInterface(java.lang.Class type)Add an interface to those declared by this class.voiddeclareInterface(java.lang.String name)Add an interface to those declared by this class.voiddeclareInterface(BCClass type)Add an interface to those declared by this class.BCMethoddeclareMethod(java.lang.String name, java.lang.Class returnType, java.lang.Class[] paramTypes)Add a method to this class.BCMethoddeclareMethod(java.lang.String name, java.lang.String returnType, java.lang.String[] paramTypes)Add a method to this class.BCMethoddeclareMethod(java.lang.String name, BCClass returnType, BCClass[] paramTypes)Add a method to this class.BCMethoddeclareMethod(BCMethod method)Import the information in the given method as a new method of this class.intgetAccessFlags()Return the access flags for this class as a bit array of ACCESS_XXX constants fromConstants.java.lang.ClassLoadergetClassLoader()Return the class loader to use when loading related classes.java.lang.StringgetClassName()Return the name of the class only, without package.BCClassgetComponentBC()Return the component type of this class, or null if not an array.java.lang.StringgetComponentName()Return the component type name of this class, or null if not an array.java.lang.ClassgetComponentType()Return the component type of this class, or null if not an array.BCFieldgetDeclaredField(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 ofConstantPoolindexes of theClassEntrys 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 theClassobjects for the declared interfaces of this class, or an empty array if none.BCMethodgetDeclaredMethod(java.lang.String name)Return the declared method with the given name, or null if none.BCMethodgetDeclaredMethod(java.lang.String name, java.lang.Class[] paramTypes)Return the declared method with the given name and parameter types, or null if none.BCMethodgetDeclaredMethod(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.BCMethodgetDeclaredMethod(java.lang.String name, java.lang.String[] paramTypes)Return the declared method with the given name and parameter types, or null if none.BCMethodgetDeclaredMethod(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.BCMethodgetDeclaredMethod(java.lang.String name, BCClass[] paramTypes)Return the declared method with the given name and parameter types, or null if none.BCMethodgetDeclaredMethod(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.intgetIndex()Return theConstantPoolindex of theClassEntryfor this class.InnerClassesgetInnerClasses(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 theClassobjects of all unique interfaces implemented by this class, including those of all superclasses.intgetMagic()Return the magic number for this class; if this is a valid type, this should be equal toConstants.VALID_MAGIC(the default value).intgetMajorVersion()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.intgetMinorVersion()Get the minor version of the bytecode spec used for this class.java.lang.StringgetName()Return the name of this class, including package name.java.lang.StringgetPackageName()Return the package name only, without class, or null if none.ConstantPoolgetPool()Return the constant pool of the current class.ProjectgetProject()Return the project of the current class.SourceFilegetSourceFile(boolean add)Return source file information for the class.BCClassgetSuperclassBC()Return the bytecode of the superclass of this class, or null for types without superclasses.intgetSuperclassIndex()Return theConstantPoolindex of theClassEntryfor the superclass of this class.java.lang.StringgetSuperclassName()Return the name of the superclass for this class, including package name.java.lang.ClassgetSuperclassType()Return theClassobject for the superclass of this class, if it is loadable.java.lang.ClassgetType()Return theClassobject for this class, if it is loadable.booleanisAbstract()Manipulate the class access flags.booleanisAnnotation()Manipulate the class access flags.booleanisArray()Return true if this class is an array type.booleanisDeprecated()Convenience method to return deprecation information for the class.booleanisEnum()Manipulate the class access flags.booleanisFinal()Manipulate the class access flags.booleanisInstanceOf(java.lang.Class type)Return true if this class or any of its superclasses implement/extend the given interface/class.booleanisInstanceOf(java.lang.String name)Return true if this class or any of its superclasses implement/extend the given interface/class.booleanisInstanceOf(BCClass type)Return true if this class or any of its superclasses implement/extend the given interface/class.booleanisInterface()Manipulate the class access flags.booleanisPackage()Manipulate the class access flags.booleanisPrimitive()Return true if this class is a primitive type.booleanisPublic()Manipulate the class access flags.booleanisSynthetic()Manipulate the class access flags.booleanisValid()Return false if this entity has been removed from its parent; in this case the results of any operations on the entity are undefined.voidmakePackage()Manipulate the class access flags.voidmakePublic()Manipulate the class access flags.voidmoveDeclaredField(int fromIdx, int toIdx)Rearrange declared field order.voidmoveDeclaredInterface(int fromIdx, int toIdx)Rearrange declared interface order.voidmoveDeclaredMethod(int fromIdx, int toIdx)Rearrange method order.booleanremoveDeclaredField(java.lang.String name)Remove a field from this class.booleanremoveDeclaredField(BCField field)Remove a field from this class.booleanremoveDeclaredInterface(java.lang.Class type)Remove an interface declared by this class.booleanremoveDeclaredInterface(java.lang.String name)Remove an interface declared by this class.booleanremoveDeclaredInterface(BCClass type)Remove an interface declared by this class.booleanremoveDeclaredMethod(java.lang.String name)Remove a method from this class.booleanremoveDeclaredMethod(java.lang.String name, java.lang.Class[] paramTypes)Removes a method from this class.booleanremoveDeclaredMethod(java.lang.String name, java.lang.String[] paramTypes)Removes a method from this class.booleanremoveDeclaredMethod(java.lang.String name, BCClass[] paramTypes)Removes a method from this class.booleanremoveDeclaredMethod(BCMethod method)Removes a method from this class.booleanremoveInnerClasses()Remove the inner classes attribute for the class.booleanremoveSourceFile()Remove the source file attribute for the class.voidsetAbstract(boolean on)Manipulate the class access flags.voidsetAccessFlags(int access)Set the access flags for this class as a bit array of ACCESS_XXX constants fromConstants.voidsetAnnotation(boolean on)Manipulate the class access flags.voidsetDeclaredFields(BCField[] fields)Set the fields for this class; this method is useful for importing all fields from another class.voidsetDeclaredInterfaceIndexes(int[] interfaceIndexes)Set the list ofConstantPoolindexes of theClassEntrys describing all the interfaces this class declares it implements/extends; set to null or an empty array if none.voidsetDeclaredInterfaces(java.lang.Class[] interfaces)Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.voidsetDeclaredInterfaces(java.lang.String[] interfaces)Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.voidsetDeclaredInterfaces(BCClass[] interfaces)Set the interfaces declared implemented/extended by this class; set to null or an empty array if none.voidsetDeclaredMethods(BCMethod[] methods)Set the methods for this class; this method is useful for importing all methods from another class.voidsetDeprecated(boolean on)Convenience method to set whether this class should be considered deprecated.voidsetEnum(boolean on)Manipulate the class access flags.voidsetFinal(boolean on)Manipulate the class access flags.voidsetIndex(int index)Set theConstantPoolindex of theClassEntryfor this class.voidsetInterface(boolean on)Manipulate the class access flags.voidsetMagic(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).voidsetMajorVersion(int majorVersion)Set the major version of the bytecode spec used for this class.voidsetMinorVersion(int minorVersion)Set the minor version of the bytecode spec used for this class.voidsetName(java.lang.String name)Set the name of this class, including package name.voidsetSuperclass(java.lang.Class type)Set the superclass of this class.voidsetSuperclass(java.lang.String name)Set the superclass of this class.voidsetSuperclass(BCClass type)Set the superclass of this class.voidsetSuperclassIndex(int index)Set theConstantPoolindex of theClassEntryfor the superclass of this class.voidsetSynthetic(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.voidwrite()Write the class bytecode to the .class file in the proper directory of the CLASSPATH.voidwrite(java.io.File classFile)Write the class bytecode to the specified file.voidwrite(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.IOExceptionWrite 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.IOExceptionWrite the class bytecode to the specified file.- Throws:
java.io.IOException
-
write
public void write(java.io.OutputStream outstream) throws java.io.IOExceptionWrite 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_VERSIONis 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_VERSIONis 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_VERSIONis 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_VERSIONis 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 theConstantPoolindex of theClassEntryfor 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 theConstantPoolindex of theClassEntryfor 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 theClassobject 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 theConstantPoolindex of theClassEntryfor 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 theConstantPoolindex of theClassEntryfor 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 theClassobject 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 ofConstantPoolindexes of theClassEntrys 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 ofConstantPoolindexes of theClassEntrys 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 theClassobjects 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 theClassobjects 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 theAttributesinterface.- 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
addparam is set to false
-
removeSourceFile
public boolean removeSourceFile()
Remove the source file attribute for the class. Acts internally through theAttributesinterface.- 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 theAttributesinterface.- 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
addparam is set to false
-
removeInnerClasses
public boolean removeInnerClasses()
Remove the inner classes attribute for the class. Acts internally through theAttributesinterface.- 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 theAttributesinterface.
-
setDeprecated
public void setDeprecated(boolean on)
Convenience method to set whether this class should be considered deprecated. Acts internally through theAttributesinterface.
-
acceptVisit
public void acceptVisit(BCVisitor visit)
Description copied from interface:VisitAcceptorAccept 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:
acceptVisitin interfaceVisitAcceptor
-
getProject
public Project getProject()
Description copied from interface:BCEntityReturn the project of the current class.- Specified by:
getProjectin interfaceBCEntity
-
getPool
public ConstantPool getPool()
Description copied from interface:BCEntityReturn the constant pool of the current class.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Description copied from interface:BCEntityReturn the class loader to use when loading related classes.- Specified by:
getClassLoaderin interfaceBCEntity
-
-