public class JiapiClass extends Object
JiapiMethods and JiapiFields.
JiapiClass is an abstract class. Concrete classes are loaded using Loader.
Loader loader = new Loader();
JiapiClass clazz = loader.loadClass(className);
Loader| Constructor and Description |
|---|
JiapiClass(ClassFile classFile)
Constructor for JiapiClass.
|
| Modifier and Type | Method and Description |
|---|---|
JiapiField |
addField(int modifiers,
String type,
String name)
Adds a new Field to this JiapiClass.
|
JiapiField |
addField(String name)
Adds a named Field to this JiapiClass.
|
void |
addInterface(JiapiClass interfaceType)
Adds an interface for a class.
|
void |
addInterface(String interfaceType)
Adds an interface for a class.
|
JiapiMethod |
addMethod(int modifiers,
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(String name)
Create empty JiapiClass.
|
void |
dump(OutputStream out)
Dumps bytecodes of this JiapiClass to OutputStream given.
|
byte[] |
getByteCode()
Get the byte-code of this class.
|
ClassFile |
getClassFile()
Get the ClassFile associated with this JiapiClass.
|
ConstantPool |
getConstantPool()
Get the ConstantPool related to this JiapiClass.
|
JiapiAnnotation[] |
getDeclaredAnnotations()
Get all the declared annotations of this Class.
|
JiapiField |
getDeclaredField(String name)
Get a declared field of a class.
|
JiapiField[] |
getDeclaredFields()
Get all the fields declared by this JiapiClass.
|
JiapiMethod |
getDeclaredMethod(String name,
JiapiClass[] parameterTypes)
Get a specific method from a class.
|
JiapiMethod |
getDeclaredMethod(String name,
String[] parameterTypeNames)
Get a specific method from a class.
|
JiapiMethod[] |
getDeclaredMethods()
Get all the methods of this JiapiClass.
|
JiapiField |
getField(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.
|
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(String name,
JiapiClass[] parameterTypes)
Get a specific method from a class or any of its superclasses.
|
JiapiMethod |
getMethod(String name,
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.
|
String |
getName()
Get name of a class.
|
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 JiapiClass |
newInstance(byte[] bytes)
Creates a new JiapiClass out of byte array given.
|
String |
toString() |
public JiapiClass(ClassFile classFile)
classFile - a ClassFilepublic static JiapiClass createClass(String name)
name - Name of the JiapiClass to createpublic static JiapiClass newInstance(byte[] bytes) throws IOException
bytes - Bytes of the Class, that will be parsed.IOException - if there was problem parsing the classpublic void dump(OutputStream out) throws IOException
out - OutputStream to useIOException - If there was problem dumping the streampublic Loader getLoader()
public String getName()
public ClassFile getClassFile()
public String getPackageName()
public byte[] getByteCode()
public JiapiMethod[] getMethods() throws ClassNotFoundException
ClassNotFoundException - is thrown if superclass could not be loadedgetDeclaredMethods() for further infopublic JiapiMethod[] getDeclaredMethods()
public JiapiMethod getDeclaredMethod(String name, String[] parameterTypeNames) throws 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 parametersNoSuchMethodException - if matching method is not foundpublic JiapiMethod getDeclaredMethod(String name, JiapiClass[] parameterTypes) throws NoSuchMethodException
name - Name of the methodparameterTypes - An array of JiapiClass, where each element represents a
parameter.NoSuchMethodException - if matching method is not foundpublic JiapiMethod getMethod(String name, String[] parameterTypeNames) throws NoSuchMethodException, 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 parametersNoSuchMethodException - if matching method is not foundClassNotFoundException - is thrown if superclass could not be loadedpublic JiapiMethod getMethod(String name, JiapiClass[] parameterTypes) throws NoSuchMethodException, ClassNotFoundException
name - Name of the methodparameterTypes - An array of JiapiClass, where each element represents a
parameter.NoSuchMethodException - if matching method is not foundClassNotFoundException - is thrown if superclass could not be loadedpublic JiapiField[] getFields() throws ClassNotFoundException
ClassNotFoundException - is thrown if superclass could not be loadedgetDeclaredFields() for further infopublic JiapiField[] getDeclaredFields()
public JiapiField getDeclaredField(String name) throws NoSuchFieldException
name - a name of a fieldNoSuchFieldException - if matching field is not foundpublic JiapiField getField(String name) throws NoSuchFieldException, ClassNotFoundException
name - a name of a fieldNoSuchFieldException - if matching field is not foundClassNotFoundException - is thrown if superclass could not be loadedpublic JiapiClass getSuperclass() throws ClassNotFoundException
ClassNotFoundException - is thrown, if superclass could not be loadedpublic int getModifiers()
Modifierpublic JiapiField addField(String name) throws FieldExistsException
public and of type java.lang.Objectname - Name of the field to be addedFieldExistsException - if a field with a same name already existspublic JiapiField addField(int modifiers, String type, 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 addedFieldExistsException - if a field with a same name already existspublic String[] getInterfaceNames()
public JiapiClass[] getInterfaceTypes() throws ClassNotFoundException
ClassNotFoundException - if there was problem loading interfacespublic void addInterface(String interfaceType)
interfaceType - the type of an interfacepublic void addInterface(JiapiClass interfaceType) throws IllegalArgumentException
interfaceType - the type of an interfaceIllegalArgumentException - is thrown, if interfaceType is not an interface.public JiapiMethod addMethod(JiapiMethod m) throws MethodExistsException
m - JiapiMethod to be used as method signatureMethodExistsException - if a method with a same name and parameter signature
already existspublic JiapiMethod addMethod(int modifiers, String methodName, Signature signature) throws MethodExistsException
modifiers - access modifiers of a classmethodName - name of a methodsignature - signature of a methodMethodExistsException - if a method with a same name and parameter signature
already existsModifierpublic JiapiAnnotation[] getDeclaredAnnotations()
public boolean isInterface()
public ConstantPool getConstantPool()
Copyright © 2017. All rights reserved.