protected ConstructorExpression(Class<? extends T> type, Class<?>[] paramTypes, ImmutableList<Expression<?>> args) { super(type); try { this.parameterTypes = getConstructorParameters(type, paramTypes).clone(); this.args = args; this.constructor = getConstructor(getType(), parameterTypes); this.transformers = getTransformers(constructor); } catch (NoSuchMethodException e) { throw new IllegalArgumentException(e); } }
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.readObject(); try { Field constructor = ConstructorExpression.class.getDeclaredField("constructor"); constructor.setAccessible(true); constructor.set(this, getConstructor(getType(), parameterTypes)); Field transformers = ConstructorExpression.class.getDeclaredField("transformers"); transformers.setAccessible(true); transformers.set(this, getTransformers(this.constructor)); } catch (Exception e) { throw new RuntimeException(e); } }
private <C> Constructor<C> getConstructor(Class<C> type, Class<?>[] givenTypes) { Constructor<C> rv = null; try { rv = ConstructorUtils.getConstructor(type, givenTypes); } catch (NoSuchMethodException ex) { fail("No constructor found for " + type.toString() + " with parameters: " + Arrays.toString(givenTypes)); } return rv; }
@Test public void getDefaultConstructorParameters() { Class<?>[] args = {Long.class, String.class}; Class<?>[] expected = {Long.TYPE, String.class}; Class<?>[] constructorParameters = getConstructorParameters(ProjectionExample.class, args); assertArrayEquals("Constructorparameters not equal", expected, constructorParameters); }
if (!compatible(parameter, argument)) { continue next_constructor; if (!compatible(parameter, argument)) { continue next_constructor;
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.readObject(); try { Field constructor = ConstructorExpression.class.getDeclaredField("constructor"); constructor.setAccessible(true); constructor.set(this, getConstructor(getType(), parameterTypes)); Field transformers = ConstructorExpression.class.getDeclaredField("transformers"); transformers.setAccessible(true); transformers.set(this, getTransformers(this.constructor)); } catch (Exception e) { throw new RuntimeException(e); } }
if (!compatible(parameter, argument)) { continue next_constructor; if (!compatible(parameter, argument)) { continue next_constructor;
protected ConstructorExpression(Class<? extends T> type, Class<?>[] paramTypes, ImmutableList<Expression<?>> args) { super(type); try { this.parameterTypes = getConstructorParameters(type, paramTypes).clone(); this.args = args; this.constructor = getConstructor(getType(), parameterTypes); this.transformers = getTransformers(constructor); } catch (NoSuchMethodException e) { throw new IllegalArgumentException(e); } }