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