]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/functions/InstanceMethodFunction.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.scl.reflection / src / org / simantics / scl / reflection / functions / InstanceMethodFunction.java
1 package org.simantics.scl.reflection.functions;
2
3 import java.lang.reflect.InvocationTargetException;
4 import java.lang.reflect.Method;
5 import java.util.Arrays;
6
7 import org.simantics.scl.runtime.function.FunctionImplN;
8
9 public class InstanceMethodFunction extends FunctionImplN {
10     Method method;
11
12     public InstanceMethodFunction(Method method) {
13         super(method.getParameterTypes().length+1);
14         this.method = method;
15     }
16     
17     public Method getMethod() {
18         return method;
19     }
20
21     @Override
22     public Object doApply(Object... ps) {
23         try {
24             return method.invoke(ps[0], Arrays.copyOfRange(ps, 1, ps.length));
25         } catch (IllegalArgumentException e) {
26             throw new RuntimeException(e);
27         } catch (IllegalAccessException e) {
28             throw new RuntimeException(e);
29         } catch (InvocationTargetException e) {
30             throw new RuntimeException(e.getCause());
31         }
32     }
33     
34     @Override
35     public String toString() {
36         return method.getName();
37     }
38 }