Search in sources :

Example 11 with CompletionFailure

use of com.sun.tools.javac.code.Symbol.CompletionFailure in project ceylon-compiler by ceylon.

the class LanguageCompiler method complete.

@Override
public void complete(ClassSymbol c) throws CompletionFailure {
    try {
        sourceLanguage.push(Language.JAVA);
        super.complete(c);
    } catch (RunTwiceException e) {
        throw new CompletionFailure(c, e.getLocalizedMessage());
    } finally {
        sourceLanguage.pop();
    }
}
Also used : CompletionFailure(com.sun.tools.javac.code.Symbol.CompletionFailure)

Example 12 with CompletionFailure

use of com.sun.tools.javac.code.Symbol.CompletionFailure 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

CompletionFailure (com.sun.tools.javac.code.Symbol.CompletionFailure)12 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)5 Symbol (com.sun.tools.javac.code.Symbol)4 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)3 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)3 Type (com.sun.tools.javac.code.Type)3 Name (com.sun.tools.javac.util.Name)3 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)2 ArrayType (com.sun.tools.javac.code.Type.ArrayType)2 ClassType (com.sun.tools.javac.code.Type.ClassType)2 JavaCompiler (com.sun.tools.javac.main.JavaCompiler)2 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)2 CeylonClassWriter (com.redhat.ceylon.compiler.java.codegen.CeylonClassWriter)1 CeylonFileObject (com.redhat.ceylon.compiler.java.codegen.CeylonFileObject)1 JavacClass (com.redhat.ceylon.compiler.java.loader.mirror.JavacClass)1 ImportModule (com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportModule)1 ModelResolutionException (com.redhat.ceylon.model.loader.ModelResolutionException)1 TypeParameterMirror (com.redhat.ceylon.model.loader.mirror.TypeParameterMirror)1 Module (com.redhat.ceylon.model.typechecker.model.Module)1 Package (com.redhat.ceylon.model.typechecker.model.Package)1