use of org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer in project ceylon by eclipse.
the class AnnotationInvocationVisitor method transformConstructorArgument.
public static JCExpression transformConstructorArgument(ExpressionTransformer exprGen, Tree.InvocationExpression invocation, Parameter classParameter, AnnotationArgument argument, org.eclipse.ceylon.langtools.tools.javac.util.List<AnnotationFieldName> fieldPath) {
AnnotationInvocation anno = annoCtorModel(invocation);
AnnotationInvocationVisitor visitor = new AnnotationInvocationVisitor(exprGen, invocation, anno);
visitor.parameter = classParameter;
AnnotationTerm term = argument.getTerm();
if (term instanceof ParameterAnnotationTerm) {
ParameterAnnotationTerm parameterArgument = (ParameterAnnotationTerm) term;
Parameter sp = parameterArgument.getSourceParameter();
int argumentIndex = ((Functional) sp.getDeclaration()).getFirstParameterList().getParameters().indexOf(sp);
if (invocation.getPositionalArgumentList() != null) {
java.util.List<Tree.PositionalArgument> positionalArguments = invocation.getPositionalArgumentList().getPositionalArguments();
if (parameterArgument.isSpread()) {
visitor.transformSpreadArgument(positionalArguments.subList(argumentIndex, positionalArguments.size()), classParameter);
} else {
if (0 <= argumentIndex && argumentIndex < positionalArguments.size()) {
Tree.PositionalArgument pargument = positionalArguments.get(argumentIndex);
if (pargument.getParameter().isSequenced()) {
visitor.transformVarargs(argumentIndex, positionalArguments);
} else {
visitor.transformArgument(pargument);
}
} else if (sp.isDefaulted()) {
visitor.makeDefaultExpr(invocation, parameterArgument, sp);
} else if (sp.isSequenced()) {
visitor.appendBuiltArray(visitor.startArray());
}
}
} else if (invocation.getNamedArgumentList() != null) {
boolean found = false;
for (Tree.NamedArgument na : invocation.getNamedArgumentList().getNamedArguments()) {
Parameter parameter = na.getParameter();
int parameterIndex = anno.indexOfConstructorParameter(parameter);
if (parameterIndex == argumentIndex) {
visitor.transformArgument(na);
found = true;
break;
}
}
Tree.SequencedArgument sa = invocation.getNamedArgumentList().getSequencedArgument();
if (sa != null) {
Parameter parameter = sa.getParameter();
int parameterIndex = anno.indexOfConstructorParameter(parameter);
if (parameterIndex == argumentIndex) {
ListBuffer<JCExpression> prevArray = visitor.startArray();
for (Tree.PositionalArgument pa : sa.getPositionalArguments()) {
if (pa instanceof Tree.ListedArgument) {
visitor.transformArgument(pa);
} else if (pa instanceof Tree.SpreadArgument) {
ListBuffer<JCExpression> listed = visitor.arrayExprs;
visitor.arrayExprs = null;
((Tree.SpreadArgument) pa).getExpression().visit(visitor);
listed.addAll(((JCNewArray) visitor.argumentExpr).elems);
visitor.argumentExpr = null;
visitor.arrayExprs = listed;
}
}
visitor.appendBuiltArray(prevArray);
found = true;
}
}
if (!found) {
if (sp.isDefaulted()) {
visitor.makeDefaultExpr(invocation, parameterArgument, sp);
} else if (sp.isSequenced()) {
visitor.appendBuiltArray(visitor.startArray());
} else {
visitor.append(exprGen.makeErroneous(invocation, "Unable to find argument"));
}
}
}
} else if (term instanceof LiteralAnnotationTerm) {
visitor.append(term.makeAnnotationArgumentValue(visitor.exprGen, visitor.anno, fieldPath.append(argument)));
} else if (term instanceof InvocationAnnotationTerm) {
AnnotationInvocation instantiation = ((InvocationAnnotationTerm) term).getInstantiation();
visitor.append(transformConstructor(visitor.exprGen, invocation, instantiation, fieldPath.append(argument)));
} else {
visitor.append(visitor.exprGen.makeErroneous(invocation, "Unable to find argument"));
}
return visitor.getExpression();
}
use of org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer in project ceylon by eclipse.
the class AnnotationInvocationVisitor method transformInstantiation.
private static JCAnnotation transformInstantiation(ExpressionTransformer exprGen, Tree.InvocationExpression invocation) {
AnnotationInvocation ai = annoCtorModel(invocation);
AnnotationInvocationVisitor visitor = new AnnotationInvocationVisitor(exprGen, invocation, annoCtorModel(invocation));
ListBuffer<JCExpression> annotationArguments = new ListBuffer<JCExpression>();
if (invocation.getPositionalArgumentList() != null) {
for (Tree.PositionalArgument arg : invocation.getPositionalArgumentList().getPositionalArguments()) {
visitor.parameter = arg.getParameter();
arg.visit(visitor);
annotationArguments.append(makeArgument(exprGen, invocation, visitor.parameter, visitor.getExpression()));
}
}
if (invocation.getNamedArgumentList() != null) {
for (Tree.NamedArgument arg : invocation.getNamedArgumentList().getNamedArguments()) {
visitor.parameter = arg.getParameter();
arg.visit(visitor);
annotationArguments.append(makeArgument(exprGen, invocation, visitor.parameter, visitor.getExpression()));
}
}
return exprGen.at(invocation).Annotation(ai.makeAnnotationType(exprGen), annotationArguments.toList());
}
Aggregations