Search in sources :

Example 1 with SequencedArgument

use of com.redhat.ceylon.compiler.typechecker.tree.Tree.SequencedArgument in project ceylon-compiler by ceylon.

the class NamedArgumentInvocation method buildVars.

/**
 * Constructs the vars used in the Let expression
 */
private void buildVars() {
    if (getPrimaryDeclaration() == null) {
        return;
    }
    boolean prev = gen.expressionGen().withinInvocation(false);
    java.util.List<Tree.NamedArgument> namedArguments = namedArgumentList.getNamedArguments();
    SequencedArgument sequencedArgument = namedArgumentList.getSequencedArgument();
    java.util.List<ParameterList> paramLists = ((Functional) getPrimaryDeclaration()).getParameterLists();
    java.util.List<Parameter> declaredParams = paramLists.get(0).getParameters();
    appendVarsForNamedArguments(namedArguments, declaredParams);
    appendVarsForReifiedTypeArguments();
    if (sequencedArgument != null)
        appendVarsForSequencedArguments(sequencedArgument, declaredParams);
    boolean hasDefaulted = appendVarsForDefaulted(declaredParams);
    if (hasDefaulted && !Strategy.defaultParameterMethodStatic(getPrimaryDeclaration()) && !Strategy.defaultParameterMethodOnOuter(getPrimaryDeclaration())) {
        vars.prepend(makeThis());
    }
    gen.expressionGen().withinInvocation(prev);
}
Also used : Functional(com.redhat.ceylon.model.typechecker.model.Functional) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) SequencedArgument(com.redhat.ceylon.compiler.typechecker.tree.Tree.SequencedArgument)

Example 2 with SequencedArgument

use of com.redhat.ceylon.compiler.typechecker.tree.Tree.SequencedArgument in project ceylon-compiler by ceylon.

the class ClassTransformer method transformAnnotationParameterDefault.

private JCExpression transformAnnotationParameterDefault(Tree.Parameter p) {
    Tree.SpecifierOrInitializerExpression defaultArgument = Decl.getDefaultArgument(p);
    Tree.Expression defaultExpression = defaultArgument.getExpression();
    Tree.Term term = defaultExpression.getTerm();
    JCExpression defaultLiteral = null;
    if (term instanceof Tree.Literal && !(term instanceof Tree.QuotedLiteral)) {
        defaultLiteral = expressionGen().transform((Tree.Literal) term);
    } else if (term instanceof Tree.BaseMemberExpression) {
        Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) term;
        Declaration decl = bme.getDeclaration();
        if (isBooleanTrue(decl)) {
            defaultLiteral = makeBoolean(true);
        } else if (isBooleanFalse(decl)) {
            defaultLiteral = makeBoolean(false);
        } else if (typeFact().isEmptyType(bme.getTypeModel())) {
            defaultLiteral = make().NewArray(null, null, List.<JCExpression>nil());
        } else if (Decl.isAnonCaseOfEnumeratedType(bme)) {
            defaultLiteral = makeClassLiteral(bme.getTypeModel());
        } else {
            defaultLiteral = make().Literal(bme.getDeclaration().getQualifiedNameString());
        }
    } else if (term instanceof Tree.MemberOrTypeExpression) {
        Tree.MemberOrTypeExpression mte = (Tree.MemberOrTypeExpression) term;
        defaultLiteral = make().Literal(mte.getDeclaration().getQualifiedNameString());
    } else if (term instanceof Tree.SequenceEnumeration) {
        Tree.SequenceEnumeration seq = (Tree.SequenceEnumeration) term;
        SequencedArgument sequencedArgument = seq.getSequencedArgument();
        defaultLiteral = makeArrayInitializer(sequencedArgument);
    } else if (term instanceof Tree.Tuple) {
        Tree.Tuple seq = (Tree.Tuple) term;
        SequencedArgument sequencedArgument = seq.getSequencedArgument();
        defaultLiteral = makeArrayInitializer(sequencedArgument);
    } else if (term instanceof Tree.InvocationExpression) {
        // Allow invocations of annotation constructors, so long as they're
        // themselves being invoked with permitted arguments
        Tree.InvocationExpression invocation = (Tree.InvocationExpression) term;
        try {
            defaultLiteral = AnnotationInvocationVisitor.transform(expressionGen(), invocation);
        } catch (BugException e) {
            defaultLiteral = e.makeErroneous(this, invocation);
        }
    } else if (term instanceof Tree.MemberLiteral) {
        defaultLiteral = expressionGen().makeMetaLiteralStringLiteralForAnnotation((Tree.MemberLiteral) term);
    } else if (term instanceof Tree.TypeLiteral) {
        defaultLiteral = expressionGen().makeMetaLiteralStringLiteralForAnnotation((Tree.TypeLiteral) term);
    }
    if (defaultLiteral == null) {
        defaultLiteral = makeErroneous(p, "compiler bug: " + p.getParameterModel().getName() + " has an unsupported defaulted parameter expression");
    }
    return defaultLiteral;
}
Also used : BaseMemberExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression) SpecifierOrInitializerExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.SpecifierOrInitializerExpression) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCPrimitiveTypeTree(com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) BaseMemberExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) MethodDeclaration(com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration) AttributeDeclaration(com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) SequencedArgument(com.redhat.ceylon.compiler.typechecker.tree.Tree.SequencedArgument)

Aggregations

SequencedArgument (com.redhat.ceylon.compiler.typechecker.tree.Tree.SequencedArgument)2 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)1 AttributeDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)1 BaseMemberExpression (com.redhat.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression)1 MethodDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)1 SpecifierOrInitializerExpression (com.redhat.ceylon.compiler.typechecker.tree.Tree.SpecifierOrInitializerExpression)1 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)1 Functional (com.redhat.ceylon.model.typechecker.model.Functional)1 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)1 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)1 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)1 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)1 JCTree (com.sun.tools.javac.tree.JCTree)1 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)1 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)1