1 package org.simantics.scl.reflection.functions;
\r
3 import java.lang.reflect.InvocationTargetException;
\r
4 import java.lang.reflect.Method;
\r
5 import java.util.Arrays;
\r
7 import org.simantics.scl.runtime.function.FunctionImplN;
\r
9 public class InstanceMethodFunction extends FunctionImplN {
\r
12 public InstanceMethodFunction(Method method) {
\r
13 super(method.getParameterTypes().length+1);
\r
14 this.method = method;
\r
17 public Method getMethod() {
\r
22 public Object doApply(Object... ps) {
\r
24 return method.invoke(ps[0], Arrays.copyOfRange(ps, 1, ps.length));
\r
25 } catch (IllegalArgumentException e) {
\r
26 throw new RuntimeException(e);
\r
27 } catch (IllegalAccessException e) {
\r
28 throw new RuntimeException(e);
\r
29 } catch (InvocationTargetException e) {
\r
30 throw new RuntimeException(e);
\r
35 public String toString() {
\r
36 return method.getName();
\r