Search in sources :

Example 46 with Package

use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.

the class ExpressionTransformer method transform.

public JCTree transform(Tree.PackageLiteral expr) {
    at(expr);
    Package pkg = (Package) expr.getImportPath().getModel();
    return makePackageLiteralCall(pkg);
}
Also used : Package(com.redhat.ceylon.model.typechecker.model.Package)

Example 47 with Package

use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.

the class CodegenUtil method getJavaNameOfDeclaration.

/** 
     * <p>Returns the fully qualified name java name of the given declaration, 
     * for example
     * {@code ceylon.language.sum_.sum} or {@code my.package.Outer.Inner}.
     * for any toplevel or externally visible Ceylon declaration.</p>
     * 
     * <p>Used by the IDE to support finding/renaming Ceylon declarations 
     * called from Java.</p>
     * */
public static String getJavaNameOfDeclaration(Declaration decl) {
    Scope s = decl.getScope();
    while (!(s instanceof Package)) {
        if (!(s instanceof TypeDeclaration)) {
            throw new IllegalArgumentException();
        }
        s = s.getContainer();
    }
    String result;
    Naming n = new Naming(null, null);
    if (decl instanceof TypeDeclaration) {
        result = n.makeTypeDeclarationName((TypeDeclaration) decl, DeclNameFlag.QUALIFIED);
        // remove initial .
        result = result.substring(1);
        if (decl.isAnonymous()) {
            result += "." + Unfix.get_.toString();
        }
    } else if (decl instanceof TypedDeclaration) {
        if (decl.isToplevel()) {
            result = n.getName((TypedDeclaration) decl, Naming.NA_FQ | Naming.NA_WRAPPER | Naming.NA_MEMBER);
            // remove initial .
            result = result.substring(1);
        } else {
            Scope container = decl.getContainer();
            if (container instanceof TypeDeclaration) {
                String qualifier = getJavaNameOfDeclaration((TypeDeclaration) container);
                result = qualifier + n.getName((TypedDeclaration) decl, Naming.NA_MEMBER);
            } else {
                throw new IllegalArgumentException();
            }
        }
    } else {
        throw new RuntimeException();
    }
    return result;
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Scope(com.redhat.ceylon.model.typechecker.model.Scope) Package(com.redhat.ceylon.model.typechecker.model.Package) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

Package (com.redhat.ceylon.model.typechecker.model.Package)47 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)18 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)17 Module (com.redhat.ceylon.model.typechecker.model.Module)16 Scope (com.redhat.ceylon.model.typechecker.model.Scope)16 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)14 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)11 ArrayList (java.util.ArrayList)10 Class (com.redhat.ceylon.model.typechecker.model.Class)8 Interface (com.redhat.ceylon.model.typechecker.model.Interface)7 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)6 Value (com.redhat.ceylon.model.typechecker.model.Value)6 PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)5 Function (com.redhat.ceylon.model.typechecker.model.Function)5 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)5 Type (com.redhat.ceylon.model.typechecker.model.Type)4 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)4 CeylonCompilationUnit (com.redhat.ceylon.compiler.java.codegen.CeylonCompilationUnit)3 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)3 File (java.io.File)3