if (aliasArguments) {
((InvocationTermTransformer)transformer).callBuilder.argumentHandling(
CallBuilder.CB_ALIAS_ARGS, varBaseName);
}
JCNewClass iterableClass;
boolean prevSyntheticClassBody = expressionGen().withinSyntheticClassBody(true);
try {
JCExpression transformedElement = applyErasureAndBoxing(iteratorResultName.makeIdent(), typeFact().getAnythingDeclaration().getType(), CodegenUtil.hasTypeErased(expr.getPrimary()),
true, BoxingStrategy.BOXED,
srcElementType, 0);
transformedElement = transformMemberExpression(expr, transformedElement, transformer);
// This short-circuit is here for spread invocations
// The code has been called recursively and the part after this if-statement will
// be handled by the previous recursion
if (spreadMethodReferenceOuter) {
return make().LetExpr(letStmts.toList(), transformedElement);
}
transformedElement = applyErasureAndBoxing(transformedElement, resultElementType,
// don't trust the erased flag of expr, as it reflects the result type of the overall spread expr,
// not necessarily of the applied member
CodegenUtil.hasTypeErased((TypedDeclaration)expr.getTarget().getDeclaration()),
!CodegenUtil.isUnBoxed(expr), BoxingStrategy.BOXED, resultElementType, 0);
MethodDefinitionBuilder nextMdb = MethodDefinitionBuilder.systemMethod(this, "next");
nextMdb.isOverride(true);
nextMdb.annotationFlags(Annotations.IGNORE);
nextMdb.modifiers(Flags.PUBLIC | Flags.FINAL);
nextMdb.resultType(null, make().Type(syms().objectType));
nextMdb.body(List.of(
makeVar(iteratorResultName,
make().Type(syms().objectType), null),
make().If(
make().Unary(JCTree.NOT,
make().TypeTest(make().Assign(
iteratorResultName.makeIdent(),
make().Apply(null,
naming.makeQualIdent(srcIteratorName.makeIdent(), "next"),
List.<JCExpression>nil())),
make().Type(syms().ceylonFinishedType))),
make().Block(0, List.<JCStatement>of(make().Exec(make().Assign(iteratorResultName.makeIdent(),
transformedElement)))),
null),
make().Return(iteratorResultName.makeIdent())));
JCMethodDecl nextMethod = nextMdb.build();
// new AbstractIterator()
JCNewClass iteratorClass = make().NewClass(null,
null,
make().TypeApply(make().QualIdent(syms().ceylonAbstractIteratorType.tsym),
List.of(makeJavaType(resultElementType, JT_TYPE_ARGUMENT))),
List.of(makeReifiedTypeArgument(resultElementType)),
make().AnonymousClassDef(make().Modifiers(0), List.of(srcIterator, nextMethod)));