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