Search in sources :

Example 1 with CeylonFileObject

use of com.redhat.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon-compiler by ceylon.

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(javax.tools.JavaFileObject) DiagnosticSource(com.sun.tools.javac.util.DiagnosticSource) CeylonFileObject(com.redhat.ceylon.compiler.java.codegen.CeylonFileObject)

Example 2 with CeylonFileObject

use of com.redhat.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon-compiler by ceylon.

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(javax.tools.JavaFileObject) ArrayList(java.util.ArrayList) CeylonFileObject(com.redhat.ceylon.compiler.java.codegen.CeylonFileObject)

Example 3 with CeylonFileObject

use of com.redhat.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon-compiler by ceylon.

the class CeyloncFileManager method getJavaFileForInput.

@Override
public JavaFileObject getJavaFileForInput(Location location, String className, JavaFileObject.Kind kind) throws IOException {
    nullCheck(location);
    // validateClassName(className);
    nullCheck(className);
    nullCheck(kind);
    if (!sourceOrClass.contains(kind))
        throw new IllegalArgumentException("Invalid kind " + kind);
    JavaFileObject file = getFileForInput(location, forClass(className, kind));
    if (file != null && file.getName().endsWith(".ceylon")) {
        return new CeylonFileObject(file);
    } else {
        return file;
    }
}
Also used : JavaFileObject(javax.tools.JavaFileObject) CeylonFileObject(com.redhat.ceylon.compiler.java.codegen.CeylonFileObject)

Example 4 with CeylonFileObject

use of com.redhat.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon-compiler by ceylon.

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(javax.tools.JavaFileObject) ListBuffer(com.sun.tools.javac.util.ListBuffer) CeylonFileObject(com.redhat.ceylon.compiler.java.codegen.CeylonFileObject)

Example 5 with CeylonFileObject

use of com.redhat.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon-compiler by ceylon.

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.isDefault()) {
                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(OptionName.VERBOSE) != null) {
                        Log.printLines(log.noticeWriter, "[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(com.sun.tools.javac.code.Symbol.CompletionFailure) CeylonFileObject(com.redhat.ceylon.compiler.java.codegen.CeylonFileObject) Package(com.redhat.ceylon.model.typechecker.model.Package) Module(com.redhat.ceylon.model.typechecker.model.Module) ImportModule(com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportModule) ClassWriter(com.sun.tools.javac.jvm.ClassWriter) CeylonClassWriter(com.redhat.ceylon.compiler.java.codegen.CeylonClassWriter)

Aggregations

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