Search in sources :

Example 6 with CeylonCompilationUnit

use of org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit in project ceylon by eclipse.

the class CeylonModelLoader method setupSourceFileObjects.

public static void setupSourceFileObjects(java.util.List<?> treeHolders, final ClassReader reader, final Names names) {
    for (Object treeHolder : treeHolders) {
        if (!(treeHolder instanceof CeylonCompilationUnit)) {
            continue;
        }
        final CeylonCompilationUnit tree = (CeylonCompilationUnit) treeHolder;
        CompilationUnit ceylonTree = tree.ceylonTree;
        final String pkgName = tree.getPackageName() != null ? Util.quoteJavaKeywords(tree.getPackageName().toString()) : "";
        ceylonTree.visit(new SourceDeclarationVisitor() {

            @Override
            public void loadFromSource(Declaration decl) {
                if (!checkNative(decl))
                    return;
                String fqn = Naming.toplevelClassName(pkgName, decl);
                try {
                    reader.enterClass(names.fromString(fqn), tree.getSourceFile());
                    if (Decl.isAnnotationClassNoModel(decl)) {
                        String annotationName = Naming.suffixName(Suffix.$annotation$, fqn);
                        reader.enterClass(names.fromString(annotationName), tree.getSourceFile());
                        if (Decl.isSequencedAnnotationClassNoModel((Tree.AnyClass) decl)) {
                            String annotationsName = Naming.suffixName(Suffix.$annotations$, fqn);
                            reader.enterClass(names.fromString(annotationsName), tree.getSourceFile());
                        }
                    }
                } catch (AssertionError error) {
                // this happens when we have already registered a source file for this decl, hopefully the typechecker
                // will catch this and log an error
                }
            }

            @Override
            public void loadFromSource(ModuleDescriptor that) {
                try {
                    reader.enterClass(names.fromString(pkgName + "." + Naming.MODULE_DESCRIPTOR_CLASS_NAME), tree.getSourceFile());
                } catch (AssertionError error) {
                // this happens when we have already registered a source file for this decl, hopefully the typechecker
                // will catch this and log an error
                }
            }

            @Override
            public void loadFromSource(PackageDescriptor that) {
                try {
                    reader.enterClass(names.fromString(pkgName + "." + Naming.PACKAGE_DESCRIPTOR_CLASS_NAME), tree.getSourceFile());
                } catch (AssertionError error) {
                // this happens when we have already registered a source file for this decl, hopefully the typechecker
                // will catch this and log an error
                }
            }
        });
    }
}
Also used : CeylonCompilationUnit(org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit) CompilationUnit(org.eclipse.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) ModuleDescriptor(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor) CeylonCompilationUnit(org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) Declaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Declaration) PackageDescriptor(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PackageDescriptor)

Aggregations

CeylonCompilationUnit (org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit)6 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)4 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)2 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)2 Package (org.eclipse.ceylon.model.typechecker.model.Package)2 IOException (java.io.IOException)1 CeylonFileObject (org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)1 CeylonPhasedUnit (org.eclipse.ceylon.compiler.java.tools.CeylonPhasedUnit)1 CompilationUnit (org.eclipse.ceylon.compiler.typechecker.tree.Tree.CompilationUnit)1 Declaration (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Declaration)1 ModuleDescriptor (org.eclipse.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor)1 PackageDescriptor (org.eclipse.ceylon.compiler.typechecker.tree.Tree.PackageDescriptor)1 CompilationUnitTree (org.eclipse.ceylon.langtools.source.tree.CompilationUnitTree)1 TaskEvent (org.eclipse.ceylon.langtools.source.util.TaskEvent)1 Timer (org.eclipse.ceylon.model.loader.Timer)1 Module (org.eclipse.ceylon.model.typechecker.model.Module)1 Modules (org.eclipse.ceylon.model.typechecker.model.Modules)1 ModuleManager (org.eclipse.ceylon.model.typechecker.util.ModuleManager)1