1 package org.simantics.scl.reflection.functions;
3 import java.lang.reflect.Constructor;
4 import java.lang.reflect.InvocationTargetException;
6 import org.simantics.scl.runtime.function.FunctionImplN;
8 public class ConstructorFunction extends FunctionImplN {
9 Constructor<?> constructor;
11 public ConstructorFunction(Constructor<?> constructor) {
12 super(constructor.getParameterTypes().length);
13 this.constructor = constructor;
16 public Constructor<?> getConstructor() {
21 public Object doApply(Object... ps) {
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());
36 public String toString() {
37 return constructor.getName();