|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectr01f.reflection.fluent.FluentReflection
public final class FluentReflection
Entry point for the fluent api. Usage example:
// Loads the class 'org.republic.Jedi'
Class> jediType = Reflection.type("org.republic.Jedi").load();
// Loads the class 'org.republic.Jedi' as 'org.republic.Person' (Jedi extends Person)
Class jediType = Reflection.type("org.republic.Jedi").loadAs(Person.class);
// Loads the class 'org.republic.Jedi' using a custom class loader
Class> jediType = Reflection.type("org.republic.Jedi").withClassLoader(myClassLoader).load();
// Gets the inner class 'Master' in the declaring class 'Jedi':
Class> masterClass = Reflection.staticInnerClass("Master").in(Jedi.class).get();
// Equivalent to call 'new Person()'
Person p = Reflection.constructor().in(Person.class).newInstance();
// Equivalent to call 'new Person("Yoda")'
Person p = Reflection.constructor().withParameterTypes(String.class).in(Person.class).newInstance}("Yoda");
// Retrieves the value of the field "name"
String name = Reflection.field("name").ofType(String.class).in(person).get();
// Sets the value of the field "name" to "Yoda"
Reflection.field("name").ofType(String.class).in(person).set("Yoda");
// Retrieves the value of the field "powers"
List powers = Reflection.field("powers").ofType(new TypeRef>() {}).in(jedi).get();
// Equivalent to call 'person.setName("Luke")'
Reflection.method("setName").withParameterTypes(String.class).in(person).invoke("Luke");
// Equivalent to call 'jedi.getPowers()'
List powers = Reflection.method("getPowers").withReturnType(new TypeRef>() {}).in(person).invoke();
// Retrieves the value of the static field "count" in Person.class
int count = Reflection.staticField("count").ofType(int.class).in(Person.class).get();
// Sets the value of the static field "count" to 3 in Person.class
Reflection.staticField("count").ofType(int.class).in(Person.class).set(3);
// Retrieves the value of the static field "commonPowers" in Jedi.class
List commmonPowers = Reflection.staticField("commonPowers").ofType(new TypeRef>() {}).in(Jedi.class).get();
// Equivalent to call 'person.concentrate()'
Reflection.method("concentrate").in(person).invoke();
// Equivalent to call 'person.getName()'
String name = Reflection.method("getName").withReturnType(String.class).in(person).invoke();
// Equivalent to call 'Jedi.setCommonPower("Jump")'
Reflection.staticMethod("setCommonPower").withParameterTypes(String.class).in(Jedi.class).invoke("Jump");
// Equivalent to call 'Jedi.addPadawan()'
Reflection.staticMethod("addPadawan").in(Jedi.class).invoke();
// Equivalent to call 'Jedi.commonPowerCount()'
String name = Reflection.staticMethod("commonPowerCount").withReturnType(String.class).in(Jedi.class).invoke();
// Equivalent to call 'Jedi.getCommonPowers()'
List powers = Reflection.staticMethod("getCommonPowers").withReturnType(new TypeRef>() {}).in(Jedi.class).invoke();
// Retrieves the value of the property "name"
String name = Reflection.property("name").ofType(String.class).in(person).get();
// Sets the value of the property "name" to "Yoda"
Reflection.property("name").ofType(String.class).in(person).set("Yoda");
| Constructor Summary | |
|---|---|
private |
FluentReflection()
Constructor |
| Method Summary | |
|---|---|
static ConstructorReflection |
constructor()
Starting point of the fluent interface for invoking constructors via reflection. |
static FieldReflection |
field(java.lang.String fieldName)
Starting point of the fluent interface for accessing fields via reflection. |
static MethodReflection |
method(java.lang.String methodName)
Starting point of the fluent interface for invoking methods via reflection. |
static PropertyReflection |
property(java.lang.String name)
Starting point of the fluent interface for accessing properties via Bean Instrospection. |
static StaticFieldReflection |
staticField(java.lang.String fieldName)
Starting point of the fluent interface for accessing static fields via reflection. |
static StaticInnerClassReflection |
staticInnerClass(java.lang.String innerClassName)
Starting point of the fluent interface for accessing static inner class via reflection. |
static StaticMethodReflection |
staticMethod(java.lang.String name)
Starting point of the fluent interface for invoking static methods via reflection. |
static TypeReflection |
type(java.lang.String name)
Starting point of the fluent interface for loading a class dynamically. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
private FluentReflection()
| Method Detail |
|---|
public static TypeReflection type(java.lang.String name)
name - the name of the class to load.
java.lang.NullPointerException - if the given name is null.
java.lang.IllegalArgumentException - if the given name is empty.public static StaticInnerClassReflection staticInnerClass(java.lang.String innerClassName)
innerClassName - the name of the static inner class to access.
java.lang.NullPointerException - if the given name is null.
java.lang.IllegalArgumentException - if the given name is empty.public static FieldReflection field(java.lang.String fieldName)
fieldName - the name of the field to access.
java.lang.NullPointerException - if the given name is null.
java.lang.IllegalArgumentException - if the given name is empty.public static StaticFieldReflection staticField(java.lang.String fieldName)
fieldName - the name of the static field to access.
java.lang.NullPointerException - if the given name is null.
java.lang.IllegalArgumentException - if the given name is empty.public static MethodReflection method(java.lang.String methodName)
methodName - the name of the method to invoke.
java.lang.NullPointerException - if the given name is null.
java.lang.IllegalArgumentException - if the given name is empty.public static StaticMethodReflection staticMethod(java.lang.String name)
name - the name of the static method to invoke.
java.lang.NullPointerException - if the given name is null.
java.lang.IllegalArgumentException - if the given name is empty.public static ConstructorReflection constructor()
public static PropertyReflection property(java.lang.String name)
name - the name of the property to access.
java.lang.NullPointerException - if the given name is null.
java.lang.IllegalArgumentException - if the given name is empty.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||