]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/functions/ConstructorFunction.java
Merge "Testing SonarQube with Simantics Platform SDK"
[simantics/platform.git] / bundles / org.simantics.scl.reflection / src / org / simantics / scl / reflection / functions / ConstructorFunction.java
1 package org.simantics.scl.reflection.functions;\r
2 \r
3 import java.lang.reflect.Constructor;\r
4 import java.lang.reflect.InvocationTargetException;\r
5 \r
6 import org.simantics.scl.runtime.function.FunctionImplN;\r
7 \r
8 public class ConstructorFunction extends FunctionImplN {\r
9     Constructor<?> constructor;\r
10 \r
11     public ConstructorFunction(Constructor<?> constructor) {\r
12         super(constructor.getParameterTypes().length);\r
13         this.constructor = constructor;\r
14     }\r
15     \r
16     public Constructor<?> getConstructor() {\r
17         return constructor;\r
18     }\r
19 \r
20     @Override\r
21     public Object doApply(Object... ps) {\r
22         try {\r
23             return constructor.newInstance(ps);\r
24         } catch (InstantiationException e) {\r
25             throw new RuntimeException(e);\r
26         } catch (IllegalArgumentException e) {\r
27             throw new RuntimeException(e);\r
28         } catch (IllegalAccessException e) {\r
29             throw new RuntimeException(e);\r
30         } catch (InvocationTargetException e) {\r
31             throw new RuntimeException(e.getCause());\r
32         }\r
33     }\r
34     \r
35     @Override\r
36     public String toString() {\r
37         return constructor.getName();\r
38     }\r
39 }\r