Search in sources :

Example 31 with JCExpression

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.

the class CallableBuilder method makeCallableVaryParam.

private ParameterDefinitionBuilder makeCallableVaryParam(long flags, int ii) {
    Type iteratedType = gen.typeFact().getIteratedType(parameterTypes.get(parameterTypes.size() - 1));
    // $call$var()'s variadic parameter is *always* erasred to Sequential
    // even if it's a Variadic+ parameter
    JCExpression type = gen.makeJavaType(gen.typeFact().getSequentialType(iteratedType), AbstractTransformer.JT_RAW);
    ParameterDefinitionBuilder pdb = ParameterDefinitionBuilder.systemParameter(gen, getParamName(ii));
    pdb.modifiers(Flags.FINAL | flags);
    pdb.type(new TransformedType(type, null, gen.makeAtNonNull()));
    return pdb;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)

Example 32 with JCExpression

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.

the class AnnotationInvocation method makeAnnotation.

public JCExpression makeAnnotation(ExpressionTransformer exprGen, AnnotationInvocation ai, org.eclipse.ceylon.langtools.tools.javac.util.List<AnnotationFieldName> parameterPath) {
    ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
    for (AnnotationArgument aa : getAnnotationArguments()) {
        Parameter name = aa.getParameter();
        if (!isInstantiation()) {
            AnnotationInvocation annotationInvocation = (AnnotationInvocation) getConstructorDeclaration().getAnnotationConstructor();
            for (AnnotationArgument a2 : annotationInvocation.getAnnotationArguments()) {
                if (a2.getTerm() instanceof ParameterAnnotationTerm) {
                    if (((ParameterAnnotationTerm) a2.getTerm()).getSourceParameter().equals(aa.getParameter())) {
                        name = a2.getParameter();
                        break;
                    }
                }
            }
        }
        args.append(makeAnnotationArgument(exprGen, ai, name, parameterPath.append(aa), aa.getTerm()));
    }
    return exprGen.make().Annotation(makeAnnotationType(exprGen), args.toList());
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter)

Example 33 with JCExpression

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.

the class AnnotationInvocationVisitor method makeDefaultExpr.

private void makeDefaultExpr(Tree.InvocationExpression invocation, ParameterAnnotationTerm parameterArgument, Parameter sp) {
    AnnotationConstructorParameter defaultedCtorParam = anno.findConstructorParameter(parameterArgument.getSourceParameter());
    if (defaultedCtorParam == null) {
        append(exprGen.makeErroneous(invocation, "compiler bug: defaulted parameter " + anno.getConstructorDeclaration().getName() + " could not be found"));
        return;
    }
    // Use the default parameter from the constructor
    if (defaultedCtorParam.getDefaultArgument() instanceof LiteralAnnotationTerm) {
        JCExpression expr = ((LiteralAnnotationTerm) defaultedCtorParam.getDefaultArgument()).makeLiteral(exprGen);
        append(expr);
    } else if (Decl.isAnnotationClass(sp.getType().getDeclaration())) {
        InvocationAnnotationTerm defaultedInvocation = (InvocationAnnotationTerm) defaultedCtorParam.getDefaultArgument();
        append(transformConstructor(exprGen, invocation, defaultedInvocation.getInstantiation(), org.eclipse.ceylon.langtools.tools.javac.util.List.<AnnotationFieldName>of(defaultedCtorParam)));
    }
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)

Example 34 with JCExpression

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.

the class AnnotationInvocationVisitor method transformConstructor.

private static JCAnnotation transformConstructor(ExpressionTransformer exprGen, Tree.InvocationExpression invocation, AnnotationInvocation ai, org.eclipse.ceylon.langtools.tools.javac.util.List<AnnotationFieldName> fieldPath) {
    Map<Parameter, ListBuffer<JCExpression>> args = new LinkedHashMap<Parameter, ListBuffer<JCExpression>>();
    List<Parameter> classParameters = ai.getClassParameters();
    // The class parameter's we've not yet figured out the value for
    ArrayList<Parameter> unbound = new ArrayList<Parameter>(classParameters);
    for (Parameter classParameter : classParameters) {
        for (AnnotationArgument argument : ai.findAnnotationArgumentForClassParameter(invocation, new HashSet<Function>(), classParameter)) {
            JCExpression expr = transformConstructorArgument(exprGen, invocation, classParameter, argument, fieldPath);
            appendArgument(args, classParameter, expr);
            unbound.remove(classParameter);
        }
    }
    outer: for (Parameter classParameter : new ArrayList<>(unbound)) {
        // Defaulted argument
        if (ai.isInstantiation()) {
            if (classParameter.isDefaulted()) {
                // That's OK, we'll pick up the default argument from
                // the Java Annotation type
                unbound.remove(classParameter);
                continue outer;
            }
        } else {
            Function ac2 = (Function) ai.getPrimary();
            AnnotationInvocation i = (AnnotationInvocation) ac2.getAnnotationConstructor();
            for (AnnotationArgument aa : i.getAnnotationArguments()) {
                if (aa.getParameter().equals(classParameter)) {
                    appendArgument(args, classParameter, aa.getTerm().makeAnnotationArgumentValue(exprGen, i, org.eclipse.ceylon.langtools.tools.javac.util.List.<AnnotationFieldName>of(aa)));
                    unbound.remove(classParameter);
                    continue outer;
                }
            }
        }
        if (Strategy.hasEmptyDefaultArgument(classParameter)) {
            appendArgument(args, classParameter, exprGen.make().NewArray(null, null, org.eclipse.ceylon.langtools.tools.javac.util.List.<JCExpression>nil()));
            unbound.remove(classParameter);
            continue outer;
        }
    }
    for (Parameter classParameter : unbound) {
        appendArgument(args, classParameter, exprGen.makeErroneous(invocation, "compiler bug: unbound annotation class parameter " + classParameter.getName()));
    }
    ListBuffer<JCExpression> assignments = new ListBuffer<JCExpression>();
    for (Map.Entry<Parameter, ListBuffer<JCExpression>> entry : args.entrySet()) {
        ListBuffer<JCExpression> exprs = entry.getValue();
        if (exprs.size() == 1) {
            assignments.append(makeArgument(exprGen, invocation, entry.getKey(), exprs.first()));
        } else {
            assignments.append(makeArgument(exprGen, invocation, entry.getKey(), exprGen.make().NewArray(null, null, exprs.toList())));
        }
    }
    JCAnnotation annotation = exprGen.at(invocation).Annotation(ai.makeAnnotationType(exprGen), assignments.toList());
    return annotation;
}
Also used : ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Function(org.eclipse.ceylon.model.typechecker.model.Function) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation)

Example 35 with JCExpression

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.

the class AnnotationInvocationVisitor method transformSpreadArgument.

private void transformSpreadArgument(java.util.List<Tree.PositionalArgument> arguments, Parameter classParameter) {
    boolean varargs = classParameter.isSequenced() && arguments.size() > 1 || arguments.size() == 0;
    ListBuffer<JCExpression> prevCollect = varargs ? startArray() : null;
    try {
        for (Tree.PositionalArgument arg : arguments) {
            exprGen.at(arg);
            arg.visit(this);
        }
    } finally {
        if (varargs) {
            appendBuiltArray(prevCollect);
        }
    }
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument)

Aggregations

JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)224 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)95 Type (org.eclipse.ceylon.model.typechecker.model.Type)95 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)74 JCStatement (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)53 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)53 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)45 SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)41 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)39 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)38 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)33 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)32 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)30 JCVariableDecl (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl)28 Function (org.eclipse.ceylon.model.typechecker.model.Function)26 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)22 Value (org.eclipse.ceylon.model.typechecker.model.Value)22 JCNewClass (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass)21 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)21 Class (org.eclipse.ceylon.model.typechecker.model.Class)17