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