]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/functions/ClassMethodFunction.java
Sync git svn branch with SVN repository r33144.
[simantics/platform.git] / bundles / org.simantics.scl.reflection / src / org / simantics / scl / reflection / functions / ClassMethodFunction.java
1 package org.simantics.scl.reflection.functions;\r
2 \r
3 import java.lang.reflect.InvocationTargetException;\r
4 import java.lang.reflect.Method;\r
5 \r
6 import org.simantics.scl.runtime.function.FunctionImplN;\r
7 \r
8 public class ClassMethodFunction extends FunctionImplN {\r
9     Method method;\r
10 \r
11     public ClassMethodFunction(Method method) {\r
12         super(method.getParameterTypes().length);\r
13         this.method = method;\r
14     }\r
15     \r
16     public Method getMethod() {\r
17         return method;\r
18     }\r
19 \r
20     @Override\r
21     public Object doApply(Object... ps) {\r
22         try {\r
23             return method.invoke(null, ps);\r
24         } catch (IllegalArgumentException e) {\r
25             throw new RuntimeException(e);\r
26         } catch (IllegalAccessException e) {\r
27             throw new RuntimeException(e);\r
28         } catch (InvocationTargetException e) {\r
29             throw new RuntimeException(e.getCause());\r
30         }\r
31     }\r
32     \r
33     @Override\r
34     public String toString() {\r
35         return method.getName();\r
36     }\r
37 }\r