Reflection wrapper formatting

This commit is contained in:
Clisprail
2014-08-05 20:08:40 +02:00
parent be646c5105
commit 44af24194c
6 changed files with 163 additions and 118 deletions
@@ -8,9 +8,9 @@ import java.util.ArrayList;
/** /**
* *
* A RefClass represents a class or an instance of that class, if no instance is * A <code>RefClass</code> represents a class or an instance of that class, if
* provided this class can only get values from static fields and only invoke * no instance is provided this class can only get values from static fields and
* static methods * only invoke static methods
* *
* @author Everel * @author Everel
* *
@@ -34,8 +34,11 @@ public class RefClass extends RefModifiers {
} }
/** /**
* Sets the instance of this class so now non static fields values can be retrieved and non static methods can be invoked * Sets the instance of this class so now non static fields values can be
* @param instance instance of this class. * retrieved and non static methods can be invoked
*
* @param instance
* instance of this class.
*/ */
public void setInstance(Object instance) { public void setInstance(Object instance) {
if (instance == null) { if (instance == null) {
@@ -54,7 +57,8 @@ public class RefClass extends RefModifiers {
/** /**
* Gets the instance of this class * Gets the instance of this class
* *
* @return if an instance of this class is known it will return that instance, otherwise it will return null. * @return if an instance of this class is known it will return that
* instance, otherwise it will return null.
*/ */
public Object getInstance() { public Object getInstance() {
return this.instance; return this.instance;
@@ -83,6 +87,7 @@ public class RefClass extends RefModifiers {
/** /**
* Gets the type of this class * Gets the type of this class
*
* @return type of this class * @return type of this class
*/ */
public org.objectweb.asm.Type getASMType() { public org.objectweb.asm.Type getASMType() {
@@ -91,7 +96,9 @@ public class RefClass extends RefModifiers {
/** /**
* Gets the class' fields * Gets the class' fields
* @return all fields if an instance is provided, otherwise only static fields *
* @return all fields if an instance is provided, otherwise only static
* fields
*/ */
public RefField[] getFields() { public RefField[] getFields() {
ArrayList<RefField> fields = new ArrayList<RefField>(); ArrayList<RefField> fields = new ArrayList<RefField>();
@@ -114,7 +121,9 @@ public class RefClass extends RefModifiers {
/** /**
* Gets field by field name * Gets field by field name
* @param name name of the field *
* @param name
* name of the field
* @return the field if found * @return the field if found
*/ */
public RefField getField(String name) { public RefField getField(String name) {
@@ -123,8 +132,11 @@ public class RefClass extends RefModifiers {
/** /**
* Gets field by field name and desc * Gets field by field name and desc
* @param name name of the field *
* @param desc desc type of the field * @param name
* name of the field
* @param desc
* desc type of the field
* @return the field if found * @return the field if found
*/ */
public RefField getField(String name, String desc) { public RefField getField(String name, String desc) {
@@ -144,7 +156,9 @@ public class RefClass extends RefModifiers {
/** /**
* Determines if this class has a super class * Determines if this class has a super class
* @return <code>true</code> if this class has a super class and which is not the java/lang/Object class, otherwise <code>false.</code> *
* @return <code>true</code> if this class has a super class and which is
* not the java/lang/Object class, otherwise <code>false.</code>
*/ */
public boolean hasSuperclass() { public boolean hasSuperclass() {
return hasSuperclass(true); return hasSuperclass(true);
@@ -152,8 +166,12 @@ public class RefClass extends RefModifiers {
/** /**
* Determines if this class has a super class * Determines if this class has a super class
* @param ignoreObjectClass if you want this method to return false when the superclass is the java/lang/Object class *
* @return <code>true</code> if this class has a superclass, otherwise <code>false</code> * @param ignoreObjectClass
* if you want this method to return false when the superclass is
* the java/lang/Object class
* @return <code>true</code> if this class has a superclass, otherwise
* <code>false</code>
*/ */
public boolean hasSuperclass(boolean ignoreObjectClass) { public boolean hasSuperclass(boolean ignoreObjectClass) {
if (!ignoreObjectClass) { if (!ignoreObjectClass) {
@@ -165,6 +183,7 @@ public class RefClass extends RefModifiers {
/** /**
* Returns a new RefClass representing the superclass of this RefClass * Returns a new RefClass representing the superclass of this RefClass
*
* @return superclass of this RefClass * @return superclass of this RefClass
*/ */
public RefClass getSuperclass() { public RefClass getSuperclass() {
@@ -173,6 +192,7 @@ public class RefClass extends RefModifiers {
/** /**
* Creates a new instance of this class * Creates a new instance of this class
*
* @return a RefClass representing a fresh created instance of that class * @return a RefClass representing a fresh created instance of that class
*/ */
public RefClass newInstance() { public RefClass newInstance() {
@@ -186,6 +206,7 @@ public class RefClass extends RefModifiers {
/** /**
* Gets the empty (without parameters) constructor of this class if any * Gets the empty (without parameters) constructor of this class if any
*
* @return empty constructor if there, otherwise <code>null</code> * @return empty constructor if there, otherwise <code>null</code>
*/ */
public RefConstructor getConstructor() { public RefConstructor getConstructor() {
@@ -194,7 +215,9 @@ public class RefClass extends RefModifiers {
/** /**
* Gets a RefConstructor from this class * Gets a RefConstructor from this class
* @param parameters the constructor it's parameters *
* @param parameters
* the constructor it's parameters
* @return the retrieved constructor * @return the retrieved constructor
*/ */
public RefConstructor getConstructor(Class<?>[] parameters) { public RefConstructor getConstructor(Class<?>[] parameters) {
@@ -208,6 +231,7 @@ public class RefClass extends RefModifiers {
/** /**
* Gets all constructors of this class * Gets all constructors of this class
*
* @return an array with all the constructors in this class * @return an array with all the constructors in this class
*/ */
public RefConstructor[] getConstructors() { public RefConstructor[] getConstructors() {
@@ -221,7 +245,9 @@ public class RefClass extends RefModifiers {
/** /**
* Gets the class' methods * Gets the class' methods
* @return all methods if an instance is provided, otherwise only static methods *
* @return all methods if an instance is provided, otherwise only static
* methods
*/ */
public RefMethod[] getMethods() { public RefMethod[] getMethods() {
ArrayList<RefMethod> methods = new ArrayList<RefMethod>(); ArrayList<RefMethod> methods = new ArrayList<RefMethod>();
@@ -244,7 +270,9 @@ public class RefClass extends RefModifiers {
/** /**
* Finds and returns the first RefMethod match with given method name * Finds and returns the first RefMethod match with given method name
* @param name method its name *
* @param name
* method its name
* @return the first match, or if not found <code>null</code> * @return the first match, or if not found <code>null</code>
*/ */
public RefMethod getMethod(String name) { public RefMethod getMethod(String name) {
@@ -253,8 +281,11 @@ public class RefClass extends RefModifiers {
/** /**
* Finds a RefMethod in this RefClass * Finds a RefMethod in this RefClass
* @param name the method its name *
* @param parameters the method its parameters * @param name
* the method its name
* @param parameters
* the method its parameters
* @return the matched method or if not found null <code>null</code> * @return the matched method or if not found null <code>null</code>
*/ */
public RefMethod getMethod(String name, Class<?>[] parameters) { public RefMethod getMethod(String name, Class<?>[] parameters) {
@@ -277,7 +308,8 @@ public class RefClass extends RefModifiers {
public String toString() { public String toString() {
if (this.instance != null) { if (this.instance != null) {
return new StringBuilder().append(this.instance.toString()).append(" : ").append(this.clazz.toString()).toString(); return new StringBuilder().append(this.instance.toString())
.append(" : ").append(this.clazz.toString()).toString();
} }
return this.clazz.toString(); return this.clazz.toString();
} }
@@ -4,7 +4,8 @@ import java.lang.reflect.Constructor;
/** /**
* *
* A <code>RefConstructor</code> class represent a constructor method of a <code>RefClass</code>. * A <code>RefConstructor</code> class represent a constructor method of a
* <code>RefClass</code>.
* *
* @author Everel * @author Everel
* *
@@ -19,6 +20,7 @@ public class RefConstructor extends RefModifiers {
/** /**
* Creates a new instance of this class by invoking this constructor * Creates a new instance of this class by invoking this constructor
*
* @return the instance of the class * @return the instance of the class
*/ */
public RefClass newInstance() { public RefClass newInstance() {
@@ -27,7 +29,9 @@ public class RefConstructor extends RefModifiers {
/** /**
* Creates a new instance of this class by invoking this constructor * Creates a new instance of this class by invoking this constructor
* @param args the arguments for the constructor *
* @param args
* the arguments for the constructor
* @return the instance of the class * @return the instance of the class
*/ */
public RefClass newInstance(Object... args) { public RefClass newInstance(Object... args) {
@@ -53,11 +57,11 @@ public class RefConstructor extends RefModifiers {
} }
/** /**
* Returns <code>true</code> if this constructor is a synthetic constructor; returns * Returns <code>true</code> if this constructor is a synthetic constructor;
* <code>false</code> otherwise. * returns <code>false</code> otherwise.
* *
* @return <code>true</code> if this constructor is a synthetic constructor; returns * @return <code>true</code> if this constructor is a synthetic constructor;
* <code>false</code> otherwise * returns <code>false</code> otherwise
*/ */
public boolean isSynthetic() { public boolean isSynthetic() {
return constructor.isSynthetic(); return constructor.isSynthetic();
@@ -74,6 +78,7 @@ public class RefConstructor extends RefModifiers {
/** /**
* Returns an array of the parameter types of this constructor * Returns an array of the parameter types of this constructor
*
* @return an array of the parameter types of this constructor * @return an array of the parameter types of this constructor
*/ */
public Class<?>[] getParameterTypes() { public Class<?>[] getParameterTypes() {
@@ -5,7 +5,7 @@ import java.lang.reflect.Type;
/** /**
* *
* A RefField represents a field in a class * A <code>RefField</code> represents a field in a <code>RefClass</code>
* *
* @author Everel * @author Everel
* *
@@ -35,7 +35,8 @@ public class RefMethod extends RefModifiers {
/** /**
* Determines if this method is a bridge method. * Determines if this method is a bridge method.
* *
* @return <code>true</code> if this method is a bridge method, otherwise <code>false</code> * @return <code>true</code> if this method is a bridge method, otherwise
* <code>false</code>
*/ */
public boolean isBridge() { public boolean isBridge() {
return method.isBridge(); return method.isBridge();
@@ -43,7 +44,9 @@ public class RefMethod extends RefModifiers {
/** /**
* Determines if this method can take a variable amount of arguments * Determines if this method can take a variable amount of arguments
* @return <code>true</code> if this method can take a variable amount of arguments *
* @return <code>true</code> if this method can take a variable amount of
* arguments
*/ */
public boolean isVarArgs() { public boolean isVarArgs() {
return method.isVarArgs(); return method.isVarArgs();
@@ -71,6 +74,7 @@ public class RefMethod extends RefModifiers {
/** /**
* Returns an array of the parameter types of this method * Returns an array of the parameter types of this method
*
* @return an array of the parameter types of this method * @return an array of the parameter types of this method
*/ */
public Class<?>[] getParameterTypes() { public Class<?>[] getParameterTypes() {
@@ -79,6 +83,7 @@ public class RefMethod extends RefModifiers {
/** /**
* Gets the return type of this class * Gets the return type of this class
*
* @return return type of this class * @return return type of this class
*/ */
public Class<?> getReturnType() { public Class<?> getReturnType() {
@@ -87,6 +92,7 @@ public class RefMethod extends RefModifiers {
/** /**
* Gets the return type of this class * Gets the return type of this class
*
* @return return type of this class * @return return type of this class
*/ */
public org.objectweb.asm.Type getASMReturnType() { public org.objectweb.asm.Type getASMReturnType() {
@@ -115,12 +121,14 @@ public class RefMethod extends RefModifiers {
* *
* Invokes the method and returns it returned object * Invokes the method and returns it returned object
* *
* @param args arguments for the invokable method * @param args
* arguments for the invokable method
* @return object returned by the method * @return object returned by the method
*/ */
public Object invoke(Object... args) { public Object invoke(Object... args) {
if (!isStatic() && instance == null) { if (!isStatic() && instance == null) {
throw new IllegalStateException("Can not invoke non static method without an instance."); throw new IllegalStateException(
"Can not invoke non static method without an instance.");
} }
try { try {
Object retObject = method.invoke(instance, args); Object retObject = method.invoke(instance, args);