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.Object
Extension 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> T
get(java.lang.Object receiver, java.lang.String fieldName)
Retrieves the value of the given accessible field of the given receiver.java.lang.Object
invoke(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.void
set(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.IllegalAccessException
Sets the given value on an the receivers's accessible field with the given name.- Parameters:
receiver
- the receiver, nevernull
fieldName
- the field's name, nevernull
value
- 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.IllegalAccessException
Retrieves the value of the given accessible field of the given receiver.- Parameters:
receiver
- the container of the field, notnull
fieldName
- 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.NoSuchMethodException
Invokes 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, notnull
methodName
- the method name, notnull
args
- the arguments for the method invocation- Returns:
- the result of the method invocation.
null
if 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...)
-
-