Search in sources :

Example 66 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

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(org.eclipse.ceylon.model.typechecker.model.Package)

Example 67 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

the class ExpressionTransformer method makeTopLevelValueOrFunctionDeclarationLiteral.

private JCExpression makeTopLevelValueOrFunctionDeclarationLiteral(Declaration declaration) {
    // toplevel method or attribute: we need to fetch them from their module/package
    Package pkg = ModelUtil.getPackageContainer(declaration.getContainer());
    // get the package
    JCExpression packageCall = makePackageLiteralCall(pkg);
    // now get the toplevel
    String getter = Decl.isMethod(declaration) ? "getFunction" : "getValue";
    JCExpression toplevelCall = make().Apply(null, makeSelect(packageCall, getter), List.<JCExpression>of(ceylonLiteral(declaration.getName())));
    return toplevelCall;
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 68 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

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(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Package(org.eclipse.ceylon.model.typechecker.model.Package) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 69 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

the class Decl method getToplevelDeclarationContainer.

public static Declaration getToplevelDeclarationContainer(Declaration decl) {
    while (decl != null) {
        Scope container = decl.getContainer();
        if (container instanceof Package || container instanceof ModuleImportList) {
            return decl;
        }
        decl = getDeclarationScope(container);
    }
    return decl;
}
Also used : ModuleImportList(org.eclipse.ceylon.model.typechecker.model.ModuleImportList) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 70 with Package

use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.

the class CeylonDocTool method getObjectFile.

private File getObjectFile(Object modPgkOrDecl) throws IOException {
    final File file;
    if (modPgkOrDecl instanceof TypeDeclaration) {
        TypeDeclaration type = (TypeDeclaration) modPgkOrDecl;
        String filename = getFileName(type);
        file = new File(getFolder(type), filename);
    } else if (modPgkOrDecl instanceof Module) {
        String filename = "index.html";
        file = new File(getApiOutputFolder((Module) modPgkOrDecl), filename);
    } else if (modPgkOrDecl instanceof Package) {
        String filename = "index.html";
        file = new File(getFolder((Package) modPgkOrDecl), filename);
    } else {
        throw new RuntimeException(CeylondMessages.msg("error.unexpected", modPgkOrDecl));
    }
    return file.getCanonicalFile();
}
Also used : Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) File(java.io.File) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

Package (org.eclipse.ceylon.model.typechecker.model.Package)84 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)31 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)31 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)27 Module (org.eclipse.ceylon.model.typechecker.model.Module)26 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)21 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)14 ArrayList (java.util.ArrayList)13 LazyPackage (org.eclipse.ceylon.model.loader.model.LazyPackage)11 Class (org.eclipse.ceylon.model.typechecker.model.Class)11 Function (org.eclipse.ceylon.model.typechecker.model.Function)9 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)9 Value (org.eclipse.ceylon.model.typechecker.model.Value)9 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)8 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)8 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)8 HashSet (java.util.HashSet)7 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)7 ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)7 Type (org.eclipse.ceylon.model.typechecker.model.Type)7