Search in sources :

Example 1 with CeylonFileObject

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

the class CeyloncFileManager method list.

public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
    Iterable<JavaFileObject> result = super.list(location, packageName, kinds, recurse);
    ListBuffer<JavaFileObject> buf = new ListBuffer<JavaFileObject>();
    for (JavaFileObject f : result) {
        if (f.getName().endsWith(".ceylon")) {
            buf.add(new CeylonFileObject(f));
        } else {
            buf.add(f);
        }
    }
    return buf.toList();
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) CeylonFileObject(org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)

Example 2 with CeylonFileObject

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

the class CeyloncFileManager method getJavaFileObjectsFromFiles.

public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
    Iterable<? extends JavaFileObject> theCollection = super.getJavaFileObjectsFromFiles(files);
    ArrayList<JavaFileObject> result = new ArrayList<JavaFileObject>();
    for (JavaFileObject file : theCollection) {
        if (file.getName().endsWith(".ceylon")) {
            result.add(new CeylonFileObject(file));
        } else {
            result.add(file);
        }
    }
    return result;
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) ArrayList(java.util.ArrayList) CeylonFileObject(org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)

Example 3 with CeylonFileObject

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

the class CeylonLog method report.

@Override
public void report(JCDiagnostic diagnostic) {
    String messageKey = diagnostic.getCode();
    if (messageKey != null) {
        if (messageKey.startsWith("compiler.err.ceylon.codegen.exception")) {
            numCeylonCodegenException++;
        } else if (messageKey.startsWith("compiler.err.ceylon.codegen.erroneous")) {
            numCeylonCodegenErroneous++;
        } else if (messageKey.startsWith("compiler.err.ceylon")) {
            numCeylonAnalysisErrors++;
        } else if (sourceLanguage.isCeylon()) {
            numCeylonCodegenGarbage++;
        } else {
            numNonCeylonErrors++;
        }
    } else if (sourceLanguage.isCeylon()) {
        numCeylonCodegenGarbage++;
    } else {
        numNonCeylonErrors++;
    }
    DiagnosticSource source = diagnostic.getDiagnosticSource();
    if (source != null) {
        JavaFileObject file = source.getFile();
        if (file instanceof CeylonFileObject && diagnostic.getType() == DiagnosticType.ERROR) {
            ((CeylonFileObject) file).addError(diagnostic);
        }
    }
    super.report(diagnostic);
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) DiagnosticSource(org.eclipse.ceylon.langtools.tools.javac.util.DiagnosticSource) CeylonFileObject(org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)

Example 4 with CeylonFileObject

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

the class LanguageCompiler method genCodeUnlessError.

private JavaFileObject genCodeUnlessError(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
    CeylonFileObject sourcefile = (CeylonFileObject) env.toplevel.sourcefile;
    try {
        // do not look at the global number of errors but only those for this file
        if (super.gen.genClass(env, cdef)) {
            String packageName = cdef.sym.packge().getQualifiedName().toString();
            Package pkg = modelLoader.findPackage(packageName);
            if (pkg == null)
                throw new RuntimeException("Failed to find package: " + packageName);
            Module module = pkg.getModule();
            if (!module.isDefaultModule()) {
                String moduleName = module.getNameAsString();
                CeylonFileObject moduleFileObject = moduleNamesToFileObjects.get(moduleName);
                // if there's no module source file object it means the module descriptor had parse errors
                if (moduleFileObject == null || moduleFileObject.hasError()) {
                    // we do not produce any class files for modules with errors
                    if (options.get(Option.VERBOSE) != null) {
                        log.printRawLines(WriterKind.NOTICE, "[Not writing class " + cdef.sym.className() + " because its module has errors: " + moduleName + "]");
                    }
                    return null;
                }
            }
            return writer.writeClass(cdef.sym);
        }
    } catch (ClassWriter.PoolOverflow ex) {
        log.error(cdef.pos(), "limit.pool");
    } catch (ClassWriter.StringOverflow ex) {
        log.error(cdef.pos(), "limit.string.overflow", ex.value.substring(0, 20));
    } catch (CompletionFailure ex) {
        chk.completionError(cdef.pos(), ex);
    } catch (AssertionError e) {
        throw new RuntimeException("Error generating bytecode for " + sourcefile.getName(), e);
    }
    return null;
}
Also used : CompletionFailure(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure) CeylonFileObject(org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) ClassWriter(org.eclipse.ceylon.langtools.tools.javac.jvm.ClassWriter) CeylonClassWriter(org.eclipse.ceylon.compiler.java.codegen.CeylonClassWriter)

Example 5 with CeylonFileObject

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

the class LanguageCompiler method loadCompiledModules.

private List<JCCompilationUnit> loadCompiledModules(List<JCCompilationUnit> trees, LinkedList<JCCompilationUnit> moduleTrees) {
    compilerDelegate.visitModules(phasedUnits);
    Modules modules = ceylonContext.getModules();
    // now make sure the phase units have their modules and packages set correctly
    for (PhasedUnit pu : phasedUnits.getPhasedUnits()) {
        Package pkg = pu.getPackage();
        loadModuleFromSource(pkg, modules, moduleTrees, trees);
    }
    // also make sure we have packages and modules set up for every Java file we compile
    for (JCCompilationUnit cu : trees) {
        // skip Ceylon CUs
        if (cu instanceof CeylonCompilationUnit)
            continue;
        String packageName = "";
        if (cu.pid != null)
            packageName = TreeInfo.fullName(cu.pid).toString();
        /*
             * Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
             */
        Package pkg = modelLoader.findOrCreateModulelessPackage(packageName);
        loadModuleFromSource(pkg, modules, moduleTrees, trees);
    }
    for (PhasedUnit phasedUnit : phasedUnits.getPhasedUnits()) {
        if (!phasedUnit.getCompilationUnit().getModuleDescriptors().isEmpty()) {
            String name = phasedUnit.getPackage().getNameAsString();
            CeylonPhasedUnit cpu = (CeylonPhasedUnit) phasedUnit;
            CeylonFileObject cfo = (CeylonFileObject) cpu.getFileObject();
            moduleNamesToFileObjects.put(name, cfo);
        }
    }
    if (addModuleTrees) {
        for (JCCompilationUnit moduleTree : moduleTrees) {
            trees = trees.append(moduleTree);
        }
    }
    return trees;
}
Also used : JCCompilationUnit(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit) CeylonCompilationUnit(org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit) Modules(org.eclipse.ceylon.model.typechecker.model.Modules) Package(org.eclipse.ceylon.model.typechecker.model.Package) CeylonFileObject(org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Aggregations

CeylonFileObject (org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)6 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)4 Package (org.eclipse.ceylon.model.typechecker.model.Package)2 ArrayList (java.util.ArrayList)1 CeylonClassWriter (org.eclipse.ceylon.compiler.java.codegen.CeylonClassWriter)1 CeylonCompilationUnit (org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit)1 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)1 CompletionFailure (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure)1 ClassWriter (org.eclipse.ceylon.langtools.tools.javac.jvm.ClassWriter)1 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)1 DiagnosticSource (org.eclipse.ceylon.langtools.tools.javac.util.DiagnosticSource)1 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)1 Module (org.eclipse.ceylon.model.typechecker.model.Module)1 Modules (org.eclipse.ceylon.model.typechecker.model.Modules)1