|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectalt.jiapi.reflect.JiapiClass
public class JiapiClass
This class represents a bytecode of a Class.
It contains methods to add and remove JiapiMethod
s and
JiapiField
s.
JiapiClass is an abstract class. Concrete classes are loaded using Loader.
Loader loader = new Loader();
JiapiClass clazz = loader.loadClass(className);
Loader
Constructor Summary | |
---|---|
JiapiClass(ClassFile classFile)
|
Method Summary | |
---|---|
JiapiField |
addField(int modifiers,
java.lang.String type,
java.lang.String name)
Adds a new Field to this JiapiClass. |
JiapiField |
addField(java.lang.String name)
Adds a named Field to this JiapiClass. |
void |
addInterface(JiapiClass interfaceType)
Adds an interface for a class. |
void |
addInterface(java.lang.String interfaceType)
Adds an interface for a class. |
JiapiMethod |
addMethod(int modifiers,
java.lang.String methodName,
Signature signature)
Adds a new method to this class. |
JiapiMethod |
addMethod(JiapiMethod m)
Adds a new method to this class. |
static JiapiClass |
createClass(java.lang.String name)
Create empty JiapiClass. |
void |
dump(java.io.OutputStream out)
Dumps bytecodes of this JiapiClass to OutputStream given. |
byte[] |
getByteCode()
Get the byte-code of this class. |
ConstantPool |
getConstantPool()
Get the ConstantPool related to this JiapiClass. |
JiapiAnnotation[] |
getDeclaredAnnotations()
Get all the declared annotations of this Class. |
JiapiField |
getDeclaredField(java.lang.String name)
Get a declared field of a class. |
JiapiField[] |
getDeclaredFields()
Get all the fields declared by this JiapiClass. |
JiapiMethod |
getDeclaredMethod(java.lang.String name,
JiapiClass[] parameterTypes)
Get a specific method from a class. |
JiapiMethod |
getDeclaredMethod(java.lang.String name,
java.lang.String[] parameterTypeNames)
Get a specific method from a class. |
JiapiMethod[] |
getDeclaredMethods()
Get all the methods of this JiapiClass. |
JiapiField |
getField(java.lang.String name)
Get a field from a class or from any of its superclasses. |
JiapiField[] |
getFields()
Get all the Fields of this JiapiClass and its superclasses. |
java.lang.String[] |
getInterfaceNames()
Gets all the interfaces, that this class directly implements. |
JiapiClass[] |
getInterfaceTypes()
Gets all the interfaces, that this class directly implements. |
Loader |
getLoader()
Gets the Loader, that loaded this JiapiClass. |
JiapiMethod |
getMethod(java.lang.String name,
JiapiClass[] parameterTypes)
Get a specific method from a class or any of its superclasses. |
JiapiMethod |
getMethod(java.lang.String name,
java.lang.String[] parameterTypeNames)
Get a specific method from a class or any of its superclasses. |
JiapiMethod[] |
getMethods()
Get all the methods of this JiapiClass and its superclasses. |
int |
getModifiers()
Get modifiers of this JiapiClass. |
java.lang.String |
getName()
Get name of a class. |
java.lang.String |
getPackageName()
Get the package where this class is defined. |
JiapiClass |
getSuperclass()
Gets the super class of this JiapiClass. |
boolean |
isInterface()
Tests, whether this JiapiClass is an interface or not. |
static void |
main(java.lang.String[] args)
|
static JiapiClass |
parseClass(byte[] bytes)
Parses byte[] for a class definition. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public JiapiClass(ClassFile classFile)
Method Detail |
---|
public JiapiField addField(int modifiers, java.lang.String type, java.lang.String name) throws FieldExistsException
modifiers
- Modifiers of the fieldtype
- Type of the field to be added. Type is given in
simple form, like 'java.lang.Object' or 'int'name
- Name of the field to be added
FieldExistsException
- if a field with a same name already
existspublic JiapiField addField(java.lang.String name) throws FieldExistsException
public
and of type java.lang.Object
name
- Name of the field to be added
FieldExistsException
- if a field with a same name already
existspublic void addInterface(JiapiClass interfaceType) throws java.lang.IllegalArgumentException
interfaceType
- the type of an interface
java.lang.IllegalArgumentException
- is thrown, if interfaceType is
not an interface.public void addInterface(java.lang.String interfaceType)
interfaceType
- the type of an interfacepublic JiapiMethod addMethod(int modifiers, java.lang.String methodName, Signature signature) throws MethodExistsException
modifiers
- access modifiers of a classmethodName
- name of a methodsignature
- signature of a method
MethodExistsException
- if a method with a same name and
parameter signature already existsModifier
public JiapiMethod addMethod(JiapiMethod m) throws MethodExistsException
m
- JiapiMethod to be used as method signature
MethodExistsException
- if a method with a same name and
parameter signature already existspublic static JiapiClass createClass(java.lang.String name)
name
- Name of the JiapiClass to create
public void dump(java.io.OutputStream out) throws java.io.IOException
out
- OutputStream to use
java.io.IOException
public byte[] getByteCode()
public ConstantPool getConstantPool()
public JiapiAnnotation[] getDeclaredAnnotations()
public JiapiField getDeclaredField(java.lang.String name) throws java.lang.NoSuchFieldException
name
- a name of a field
java.lang.NoSuchFieldException
- if matching field is not foundpublic JiapiField[] getDeclaredFields()
public JiapiMethod getDeclaredMethod(java.lang.String name, JiapiClass[] parameterTypes) throws java.lang.NoSuchMethodException
parameterTypes
- An array of JiapiClass, where each element
represents a parameter.
java.lang.NoSuchMethodException
- if matching method is not foundpublic JiapiMethod getDeclaredMethod(java.lang.String name, java.lang.String[] parameterTypeNames) throws java.lang.NoSuchMethodException
java.lang.Object
,
int
, int[]
, my.stuff.Thing[]
Example:
JiapiClass clazz = ...; String[] paramTypeNames = new String[] {"java.lang.Object[]", "int"}; JiapiMethod m = clazz.getMethod("foo", paramTypeNames);Would return a method
foo(Object[], int)
name
- Name of the methodparameterTypeNames
- Type names of the parameters
java.lang.NoSuchMethodException
- if matching method is not foundpublic JiapiMethod[] getDeclaredMethods()
public JiapiField getField(java.lang.String name) throws java.lang.NoSuchFieldException, java.lang.ClassNotFoundException
name
- a name of a field
java.lang.NoSuchFieldException
- if matching field is not found
java.lang.ClassNotFoundException
- is thrown if superclass could
not be loadedpublic JiapiField[] getFields() throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
- is thrown if superclass could
not be loadedgetDeclaredFields() for further info
public java.lang.String[] getInterfaceNames()
public JiapiClass[] getInterfaceTypes() throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public Loader getLoader()
public JiapiMethod getMethod(java.lang.String name, JiapiClass[] parameterTypes) throws java.lang.NoSuchMethodException, java.lang.ClassNotFoundException
parameterTypes
- An array of JiapiClass, where each element
represents a parameter.
java.lang.NoSuchMethodException
- if matching method is not found
java.lang.ClassNotFoundException
- is thrown if superclass could
not be loadedpublic JiapiMethod getMethod(java.lang.String name, java.lang.String[] parameterTypeNames) throws java.lang.NoSuchMethodException, java.lang.ClassNotFoundException
java.lang.Object
,
int
, int[]
, my.stuff.Thing[]
Example:
JiapiClass clazz = ...; String[] paramTypeNames = new String[] {"java.lang.Object[]", "int"}; JiapiMethod m = clazz.getMethod("foo", paramTypeNames);Would return a method
foo(Object[], int)
name
- Name of the methodparameterTypeNames
- Type names of the parameters
java.lang.NoSuchMethodException
- if matching method is not found
java.lang.ClassNotFoundException
- is thrown if superclass could
not be loadedpublic JiapiMethod[] getMethods() throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
- is thrown if superclass could
not be loadedgetDeclaredMethods() for further info
public int getModifiers()
Modifier
public java.lang.String getName()
public java.lang.String getPackageName()
public JiapiClass getSuperclass() throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
- is thrown, if superclass could not
be loadedpublic boolean isInterface()
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
public static JiapiClass parseClass(byte[] bytes) throws java.io.IOException
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |