java.lang.Object
org.eclipse.xtext.xbase.lib.util.ReflectExtensions
Extension methods to simplify reflective invocation of methods and fields.
- Since:
- 2.3
- Author:
- Sven Efftinge - Initial contribution and API
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TRetrieves the value of the given accessible field of the given receiver.Invokes the first accessible method defined on the receiver'c class with the given name and a parameter list compatible to the given arguments.voidSets the given value on an the receivers's accessible field with the given name.
-
Constructor Details
-
ReflectExtensions
public ReflectExtensions()
-
-
Method Details
-
set
public void set(Object receiver, String fieldName, Object value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException Sets 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:
NoSuchFieldException- seeClass.getField(String)SecurityException- seeClass.getField(String)IllegalAccessException- seeField.set(Object, Object)IllegalArgumentException- seeField.set(Object, Object)
-
get
public <T> T get(Object receiver, String fieldName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException Retrieves 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:
NoSuchFieldException- seeClass.getField(String)SecurityException- seeClass.getField(String)IllegalAccessException- seeField.get(Object)IllegalArgumentException- seeField.get(Object)
-
invoke
public Object invoke(Object receiver, String methodName, Object... args) throws SecurityException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, 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, 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:
SecurityException- seeClass.getMethod(String, Class...)NoSuchMethodException- seeClass.getMethod(String, Class...)IllegalAccessException- seeMethod.invoke(Object, Object...)IllegalArgumentException- seeMethod.invoke(Object, Object...)InvocationTargetException- seeMethod.invoke(Object, Object...)
-