]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/functions/InstanceMethodFunction.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.reflection / src / org / simantics / scl / reflection / functions / InstanceMethodFunction.java
diff --git a/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/functions/InstanceMethodFunction.java b/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/functions/InstanceMethodFunction.java
new file mode 100755 (executable)
index 0000000..94294d5
--- /dev/null
@@ -0,0 +1,38 @@
+package org.simantics.scl.reflection.functions;\r
+\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.lang.reflect.Method;\r
+import java.util.Arrays;\r
+\r
+import org.simantics.scl.runtime.function.FunctionImplN;\r
+\r
+public class InstanceMethodFunction extends FunctionImplN {\r
+    Method method;\r
+\r
+    public InstanceMethodFunction(Method method) {\r
+        super(method.getParameterTypes().length+1);\r
+        this.method = method;\r
+    }\r
+    \r
+    public Method getMethod() {\r
+        return method;\r
+    }\r
+\r
+    @Override\r
+    public Object doApply(Object... ps) {\r
+        try {\r
+            return method.invoke(ps[0], Arrays.copyOfRange(ps, 1, ps.length));\r
+        } catch (IllegalArgumentException e) {\r
+            throw new RuntimeException(e);\r
+        } catch (IllegalAccessException e) {\r
+            throw new RuntimeException(e);\r
+        } catch (InvocationTargetException e) {\r
+            throw new RuntimeException(e);\r
+        }\r
+    }\r
+    \r
+    @Override\r
+    public String toString() {\r
+        return method.getName();\r
+    }\r
+}\r