--- /dev/null
+package org.simantics.scl.reflection.functions;\r
+\r
+import java.lang.reflect.Constructor;\r
+import java.lang.reflect.InvocationTargetException;\r
+\r
+import org.simantics.scl.runtime.function.FunctionImplN;\r
+\r
+public class ConstructorFunction extends FunctionImplN {\r
+ Constructor<?> constructor;\r
+\r
+ public ConstructorFunction(Constructor<?> constructor) {\r
+ super(constructor.getParameterTypes().length);\r
+ this.constructor = constructor;\r
+ }\r
+ \r
+ public Constructor<?> getConstructor() {\r
+ return constructor;\r
+ }\r
+\r
+ @Override\r
+ public Object doApply(Object... ps) {\r
+ try {\r
+ return constructor.newInstance(ps);\r
+ } catch (InstantiationException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IllegalArgumentException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IllegalAccessException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (InvocationTargetException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return constructor.getName();\r
+ }\r
+}\r