/** * no more parameters to pass to this constructor * (mostly used when no parameters at all) * @return the ConstructoBuilder */ ConstructorBuilder endConstructorCall() { return factory // pass the expression for the last param .newValueExpressionBuilder(expressionHandler, new CallConstructorExpression(parameters)) // and go directly from expression to statement as a constructor never returns anything .end(); } }
@Override public void visit(CallConstructorExpression callConstructorExpression) { sb.append("super("); boolean first = true; Iterable<Expression> parameters = callConstructorExpression.getParameters(); for (Expression expression : parameters) { if (first) { first = false; } else { sb.append(", "); } expression.accept(this); } sb.append(")"); }
ImmutableList.<Parameter>empty(), ImmutableList.from(Arrays.<Statement>asList(new CallConstructorStatement(0, new CallConstructorExpression(ImmutableList.<Expression>empty())) )), false)));
@Override public void visit(CallConstructorExpression callConstructorExpression) { methodByteCodeContext.incIndent("call super constructor"); methodByteCodeContext.loadThis(); Method constructor = methodContext.getType().getSuperConstructor(callConstructorExpression.getParameters().size()); if (constructor == null) { throw new RuntimeException( "can't find constructor with " + callConstructorExpression.getParameters().size() + " parameters in " + methodContext.getType().getExtending() + " parent of " + methodContext.getType()); } loadParameters("<init>", constructor, callConstructorExpression.getParameters()); methodByteCodeContext.addInstruction(new MethodInsnNode(INVOKESPECIAL, methodContext.getType().getExtending().getClassIdentifier(), "<init>", constructor.getSignature()), "super(...)"); methodByteCodeContext.decIndent(); }