Package org.eclipse.xtext.xbase.lib.util
Class ReflectExtensions
- java.lang.Object
-
- org.eclipse.xtext.xbase.lib.util.ReflectExtensions
-
@Beta public class ReflectExtensions extends java.lang.ObjectExtension methods to simplify reflective invocation of methods and fields.- Since:
- 2.3
-
-
Constructor Summary
Constructors Constructor Description ReflectExtensions()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Tget(java.lang.Object receiver, java.lang.String fieldName)Retrieves the value of the given accessible field of the given receiver.java.lang.Objectinvoke(java.lang.Object receiver, java.lang.String methodName, java.lang.Object... args)Invokes the first accessible method defined on the receiver'c class with the given name and a parameter list compatible to the given arguments.voidset(java.lang.Object receiver, java.lang.String fieldName, java.lang.Object value)Sets the given value on an the receivers's accessible field with the given name.
-
-
-
Method Detail
-
set
public void set(java.lang.Object receiver, java.lang.String fieldName, java.lang.Object value) throws java.lang.SecurityException, java.lang.NoSuchFieldException, java.lang.IllegalArgumentException, java.lang.IllegalAccessExceptionSets the given value on an the receivers's accessible field with the given name.- Parameters:
receiver- the receiver, nevernullfieldName- the field's name, nevernullvalue- the value to set- Throws:
java.lang.NoSuchFieldException- seeClass.getField(String)java.lang.SecurityException- seeClass.getField(String)java.lang.IllegalAccessException- seeField.set(Object, Object)java.lang.IllegalArgumentException- seeField.set(Object, Object)
-
get
public <T> T get(java.lang.Object receiver, java.lang.String fieldName) throws java.lang.SecurityException, java.lang.NoSuchFieldException, java.lang.IllegalArgumentException, java.lang.IllegalAccessExceptionRetrieves the value of the given accessible field of the given receiver.- Parameters:
receiver- the container of the field, notnullfieldName- the field's name, notnull- Returns:
- the value of the field
- Throws:
java.lang.NoSuchFieldException- seeClass.getField(String)java.lang.SecurityException- seeClass.getField(String)java.lang.IllegalAccessException- seeField.get(Object)java.lang.IllegalArgumentException- seeField.get(Object)
-
invoke
public java.lang.Object invoke(java.lang.Object receiver, java.lang.String methodName, java.lang.Object... args) throws java.lang.SecurityException, java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodExceptionInvokes the first accessible method defined on the receiver'c class with the given name and a parameter list compatible to the given arguments.- Parameters:
receiver- the method call receiver, notnullmethodName- the method name, notnullargs- the arguments for the method invocation- Returns:
- the result of the method invocation.
nullif the method was of type void. - Throws:
java.lang.SecurityException- seeClass.getMethod(String, Class...)java.lang.NoSuchMethodException- seeClass.getMethod(String, Class...)java.lang.IllegalAccessException- seeMethod.invoke(Object, Object...)java.lang.IllegalArgumentException- seeMethod.invoke(Object, Object...)java.lang.reflect.InvocationTargetException- seeMethod.invoke(Object, Object...)
-
-