Search in sources :

Example 66 with JCExpression

use of com.sun.tools.javac.tree.JCTree.JCExpression in project ceylon-compiler by ceylon.

the class AnnotationInvocationVisitor method makeDefaultExpr.

private void makeDefaultExpr(Tree.InvocationExpression invocation, ParameterAnnotationTerm parameterArgument, Parameter sp) {
    AnnotationConstructorParameter defaultedCtorParam = null;
    for (AnnotationConstructorParameter ctorParam : anno.getConstructorParameters()) {
        if (ctorParam.getParameter().equals(parameterArgument.getSourceParameter())) {
            defaultedCtorParam = ctorParam;
            break;
        }
    }
    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(), com.sun.tools.javac.util.List.<AnnotationFieldName>of(defaultedCtorParam)));
    }
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression)

Example 67 with JCExpression

use of com.sun.tools.javac.tree.JCTree.JCExpression in project ceylon-compiler by ceylon.

the class AbstractTransformer method makeAtMember.

JCAnnotation makeAtMember(Type type) {
    JCExpression classAttribute = make().Assign(naming.makeUnquotedIdent("klass"), makeClassLiteral(type));
    List<JCExpression> attributes = List.of(classAttribute);
    return make().Annotation(makeIdent(syms().ceylonAtMemberType), attributes);
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression)

Example 68 with JCExpression

use of com.sun.tools.javac.tree.JCTree.JCExpression in project ceylon-compiler by ceylon.

the class AbstractTransformer method makeAtAnnotations.

List<JCAnnotation> makeAtAnnotations(java.util.List<Annotation> annotations) {
    if (!simpleAnnotationModels || annotations == null || annotations.isEmpty())
        return List.nil();
    long modifiers = 0;
    ListBuffer<JCExpression> array = new ListBuffer<JCTree.JCExpression>();
    for (Annotation annotation : annotations) {
        if (isOmittedModelAnnotation(annotation)) {
            continue;
        }
        Long mask = getModelModifierMask(annotation);
        if (mask != null && mask != 0) {
            modifiers |= mask;
        } else {
            array.append(makeAtAnnotation(annotation));
        }
    }
    if (modifiers == 0 && array.isEmpty()) {
        return List.<JCAnnotation>nil();
    }
    List<JCExpression> annotationsAndMods = List.<JCExpression>nil();
    if (!array.isEmpty()) {
        annotationsAndMods = annotationsAndMods.prepend(make().Assign(naming.makeUnquotedIdent("value"), make().NewArray(null, null, array.toList())));
    }
    if (modifiers != 0L) {
        annotationsAndMods = annotationsAndMods.prepend(make().Assign(naming.makeUnquotedIdent("modifiers"), make().Literal(modifiers)));
    }
    return makeModelAnnotation(syms().ceylonAtAnnotationsType, annotationsAndMods);
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCTree(com.sun.tools.javac.tree.JCTree) LanguageAnnotation(com.redhat.ceylon.model.loader.LanguageAnnotation) Annotation(com.redhat.ceylon.model.typechecker.model.Annotation) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 69 with JCExpression

use of com.sun.tools.javac.tree.JCTree.JCExpression in project ceylon-compiler by ceylon.

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(type, null);
    return pdb;
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression)

Example 70 with JCExpression

use of com.sun.tools.javac.tree.JCTree.JCExpression in project ceylon-compiler by ceylon.

the class CallableBuilder method unboundValueMemberReference.

/**
     * Used for "static" value references. For example:
     * <pre>
     *     value x = Integer.plus;
     *     value y = Foo.method;
     *     value z = Outer.Inner;
     * </pre>
     */
public static CallableBuilder unboundValueMemberReference(CeylonTransformer gen, Tree.QualifiedMemberOrTypeExpression qmte, Type typeModel, final TypedDeclaration value) {
    CallBuilder callBuilder = CallBuilder.instance(gen);
    Type qualifyingType = qmte.getTarget().getQualifyingType();
    JCExpression target = gen.naming.makeUnquotedIdent(Unfix.$instance$);
    target = gen.expressionGen().applyErasureAndBoxing(target, qmte.getPrimary().getTypeModel(), true, BoxingStrategy.BOXED, qualifyingType);
    if (gen.expressionGen().isThrowableMessage(qmte)) {
        callBuilder.invoke(gen.utilInvocation().throwableMessage());
        callBuilder.argument(target);
    } else if (gen.expressionGen().isThrowableSuppressed(qmte)) {
        callBuilder.invoke(gen.utilInvocation().suppressedExceptions());
        callBuilder.argument(target);
    } else {
        JCExpression memberName = gen.naming.makeQualifiedName(target, value, Naming.NA_GETTER | Naming.NA_MEMBER);
        if (value instanceof FieldValue) {
            callBuilder.fieldRead(memberName);
        } else {
            callBuilder.invoke(memberName);
        }
    }
    JCExpression innerInvocation = callBuilder.build();
    // use the return type since the value is actually applied
    Type returnType = gen.getReturnTypeOfCallable(typeModel);
    innerInvocation = gen.expressionGen().applyErasureAndBoxing(innerInvocation, returnType, // expression is a Callable
    qmte.getTypeErased(), !CodegenUtil.isUnBoxed(value), BoxingStrategy.BOXED, returnType, 0);
    ParameterList outerPl = new ParameterList();
    Parameter instanceParameter = new Parameter();
    instanceParameter.setName(Naming.name(Unfix.$instance$));
    Value valueModel = new Value();
    instanceParameter.setModel(valueModel);
    Type accessType = gen.getParameterTypeOfCallable(typeModel, 0);
    ;
    if (!value.isShared()) {
        accessType = Decl.getPrivateAccessType(qmte);
    }
    valueModel.setName(instanceParameter.getName());
    valueModel.setInitializerParameter(instanceParameter);
    valueModel.setType(accessType);
    valueModel.setUnboxed(false);
    outerPl.getParameters().add(instanceParameter);
    CallableBuilder outer = new CallableBuilder(gen, null, typeModel, outerPl);
    outer.parameterTypes = outer.getParameterTypesFromParameterModels();
    List<JCStatement> innerBody = List.<JCStatement>of(gen.make().Return(innerInvocation));
    outer.useDefaultTransformation(innerBody);
    outer.companionAccess = Decl.isPrivateAccessRequiringCompanion(qmte);
    return outer;
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) FieldValue(com.redhat.ceylon.model.loader.model.FieldValue) Value(com.redhat.ceylon.model.typechecker.model.Value) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) FieldValue(com.redhat.ceylon.model.loader.model.FieldValue) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement)

Aggregations

JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)311 JCTree (com.sun.tools.javac.tree.JCTree)95 Type (com.redhat.ceylon.model.typechecker.model.Type)85 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)81 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)67 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)59 ListBuffer (com.sun.tools.javac.util.ListBuffer)54 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)39 Name (com.sun.tools.javac.util.Name)39 SyntheticName (com.redhat.ceylon.compiler.java.codegen.Naming.SyntheticName)37 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)35 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)34 JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)34 JavacTreeMaker (lombok.javac.JavacTreeMaker)33 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)30 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)29 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)27 Function (com.redhat.ceylon.model.typechecker.model.Function)26 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)26 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)26