Search in sources :

Example 26 with JCMethodInvocation

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

the class AbstractTransformer method makeTypedDeclarationTypeDescriptorResolved.

private JCExpression makeTypedDeclarationTypeDescriptorResolved(TypedDeclaration declaration) {
    // figure out the method name
    String methodName = declaration.getPrefixedName();
    List<JCExpression> arguments;
    if (declaration instanceof Function)
        arguments = makeReifiedTypeArgumentsResolved(getTypeArguments((Function) declaration), true);
    else
        arguments = List.nil();
    if (declaration.isToplevel()) {
        JCExpression getterClassNameExpr;
        if (declaration instanceof Function) {
            getterClassNameExpr = naming.makeName(declaration, Naming.NA_FQ | Naming.NA_WRAPPER);
        } else {
            String getterClassName = Naming.getAttrClassName(declaration, 0);
            getterClassNameExpr = naming.makeUnquotedIdent(getterClassName);
        }
        arguments = arguments.prepend(makeSelect(getterClassNameExpr, "class"));
    } else
        arguments = arguments.prepend(make().Literal(methodName));
    JCMethodInvocation typedDeclarationDescriptor = make().Apply(null, makeSelect(makeTypeDescriptorType(), "functionOrValue"), arguments);
    // see if the declaration has a container too
    Declaration enclosingDeclaration = getDeclarationContainer(declaration);
    JCExpression containerType = null;
    if (enclosingDeclaration instanceof TypedDeclaration)
        containerType = makeTypedDeclarationTypeDescriptorResolved((TypedDeclaration) enclosingDeclaration);
    else if (enclosingDeclaration instanceof TypeDeclaration) {
        Type qualifyingType = ((TypeDeclaration) enclosingDeclaration).getType();
        containerType = makeReifiedTypeArgumentResolved(qualifyingType, true);
    }
    if (containerType == null) {
        return typedDeclarationDescriptor;
    } else {
        return make().Apply(null, makeSelect(makeTypeDescriptorType(), "member"), List.of(containerType, typedDeclarationDescriptor));
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) JCMethodInvocation(com.sun.tools.javac.tree.JCTree.JCMethodInvocation) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Type(com.redhat.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

JCMethodInvocation (com.sun.tools.javac.tree.JCTree.JCMethodInvocation)26 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)15 JCTree (com.sun.tools.javac.tree.JCTree)10 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)8 JCExpressionStatement (com.sun.tools.javac.tree.JCTree.JCExpressionStatement)7 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)6 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)6 JCFieldAccess (com.sun.tools.javac.tree.JCTree.JCFieldAccess)5 JCMethodDecl (com.sun.tools.javac.tree.JCTree.JCMethodDecl)5 ArrayList (java.util.ArrayList)5 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)4 JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)4 JCIdent (com.sun.tools.javac.tree.JCTree.JCIdent)4 Name (com.sun.tools.javac.util.Name)4 JavacTreeMaker (lombok.javac.JavacTreeMaker)4 ExpressionTree (com.sun.source.tree.ExpressionTree)3 Symbol (com.sun.tools.javac.code.Symbol)3 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)3 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)3 Type (com.sun.tools.javac.code.Type)3