Search in sources :

Example 1 with CompletionFailure

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure in project ceylon by eclipse.

the class CeylonModelLoader method isOverloadingMethod.

/**
 * Returns true if the given method is overloading an inherited method (from super class or interfaces).
 */
private boolean isOverloadingMethod(final MethodSymbol method) {
    /*
         * Copied from getOverriddenMethod and adapted for overloading
         */
    try {
        // interfaces have a different way to work
        if (method.owner.isInterface())
            return overloaded(method, method.owner.type.tsym, types);
        // so we stop there for it, especially since it does not have any overloading
        if (method.owner.type.tsym.getQualifiedName().toString().equals("ceylon.language.Exception"))
            return false;
        for (Type superType = types.supertype(method.owner.type); superType.tsym != null; superType = types.supertype(superType)) {
            TypeSymbol i = superType.tsym;
            String fqn = i.getQualifiedName().toString();
            // never go above this type since it has no supertype in Ceylon (does in Java though)
            if (fqn.equals("ceylon.language.Anything"))
                break;
            try {
                for (Entry e = i.members().lookup(method.name); e.scope != null; e = e.next()) {
                    // ignore some methods
                    if (isIgnored(e.sym))
                        continue;
                    if (!method.overrides(e.sym, (TypeSymbol) method.owner, types, false)) {
                        return true;
                    }
                }
                // try in the interfaces
                if (overloaded(method, i, types))
                    return true;
            } catch (Symbol.CompletionFailure x) {
            // just ignore unresolved interfaces, error will be logged when we try to add it
            }
            // so we stop there for it, especially since it does not have any overloading
            if (fqn.equals("ceylon.language.Exception"))
                break;
        }
        // try in the interfaces
        if (overloaded(method, method.owner.type.tsym, types))
            return true;
        return false;
    } catch (CompletionFailure x) {
        handleCompletionFailure(method, x);
        return false;
    }
}
Also used : MethodType(org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType) Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ArrayType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType) JavacType(org.eclipse.ceylon.compiler.java.loader.mirror.JavacType) FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) Entry(org.eclipse.ceylon.langtools.tools.javac.code.Scope.Entry) CompletionFailure(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) TypeSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) PackageSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol) CompletionFailure(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure) TypeSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)

Example 2 with CompletionFailure

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure in project ceylon by eclipse.

the class LanguageCompiler method complete.

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

Example 3 with CompletionFailure

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure 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 4 with CompletionFailure

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure in project ceylon by eclipse.

the class CeylonModelLoader method lookupNewClassMirror.

private ClassMirror lookupNewClassMirror(String name) {
    ClassSymbol classSymbol = null;
    String outerName = name;
    /*
         * This madness here tries to look for a class, and if it fails, tries to resolve it 
         * from its parent class. This is required because a.b.C.D (where D is an inner class
         * of C) is not found in symtab.classes but in C's ClassSymbol.enclosedElements.
         */
    // make sure we load the class file, since we no longer complete packages unless we absolutely must
    loadClass(outerName);
    do {
        // we must first try with no postfix, because we can have a valid class foo.bar in Java,
        // when in Ceylon it would be foo.bar_
        classSymbol = symtab.classes.get(names.fromString(Util.quoteJavaKeywords(outerName)));
        // try again with a postfix "_"
        if (classSymbol == null && lastPartHasLowerInitial(outerName) && !outerName.endsWith("_")) {
            classSymbol = symtab.classes.get(names.fromString(Util.quoteJavaKeywords(outerName + "_")));
        }
        if (classSymbol != null) {
            // if we got a source symbol for something non-Java it's a slipery slope
            if (Util.isLoadedFromSource(classSymbol) && !Util.isJavaSource(classSymbol))
                return null;
            if (outerName.length() != name.length()) {
                try {
                    classSymbol = lookupInnerClass(classSymbol, name.substring(outerName.length() + 1).split("\\."));
                } catch (CompletionFailure x) {
                    // something wrong, we will report it properly elsewhere
                    classSymbol = null;
                }
            }
            if (classSymbol != null && classSymbol.classfile == null && classSymbol.sourcefile == null) {
                // try to complete it if that changes anything
                try {
                    classSymbol.complete();
                } catch (CompletionFailure x) {
                // if we can't complete it it doesn't exist, its classfile will remain null
                }
                if (classSymbol.classfile == null) {
                    PackageSymbol pkg = classSymbol.packge();
                    // do not log an error for missing oracle jdk stuff
                    if (pkg == null || !jdkProvider.isImplementationSpecificJDKPackage(pkg.getQualifiedName().toString())) {
                        // do not log an error because it will be logged elsewhere
                        logVerbose("Unable to find required class file for " + name);
                    }
                    return null;
                }
            }
            return classSymbol != null ? new JavacClass(classSymbol) : null;
        }
        int lastDot = outerName.lastIndexOf(".");
        if (lastDot == -1 || lastDot == 0)
            return null;
        outerName = outerName.substring(0, lastDot);
    } while (classSymbol == null);
    return null;
}
Also used : PackageSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol) JavacClass(org.eclipse.ceylon.compiler.java.loader.mirror.JavacClass) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) CompletionFailure(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure)

Example 5 with CompletionFailure

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure in project ceylon by eclipse.

the class JavacUtil method getTypeParameters.

public static List<TypeParameterMirror> getTypeParameters(Symbol symbol) {
    try {
        org.eclipse.ceylon.langtools.tools.javac.util.List<TypeVariableSymbol> typeParameters = symbol.getTypeParameters();
        List<TypeParameterMirror> ret = new ArrayList<TypeParameterMirror>(typeParameters.size());
        for (TypeVariableSymbol typeParameter : typeParameters) ret.add(new JavacTypeParameter(typeParameter));
        return ret;
    } catch (CompletionFailure x) {
        throw new ModelResolutionException("Failed to load type parameters", x);
    }
}
Also used : ModelResolutionException(org.eclipse.ceylon.model.loader.ModelResolutionException) TypeParameterMirror(org.eclipse.ceylon.model.loader.mirror.TypeParameterMirror) CompletionFailure(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure) ArrayList(java.util.ArrayList) TypeVariableSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeVariableSymbol)

Aggregations

CompletionFailure (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure)5 ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)2 PackageSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol)2 ArrayList (java.util.ArrayList)1 CeylonClassWriter (org.eclipse.ceylon.compiler.java.codegen.CeylonClassWriter)1 CeylonFileObject (org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)1 JavacClass (org.eclipse.ceylon.compiler.java.loader.mirror.JavacClass)1 JavacType (org.eclipse.ceylon.compiler.java.loader.mirror.JavacType)1 Entry (org.eclipse.ceylon.langtools.tools.javac.code.Scope.Entry)1 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)1 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)1 TypeSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)1 TypeVariableSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeVariableSymbol)1 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)1 ArrayType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType)1 MethodType (org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType)1 ClassWriter (org.eclipse.ceylon.langtools.tools.javac.jvm.ClassWriter)1 ModelResolutionException (org.eclipse.ceylon.model.loader.ModelResolutionException)1 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)1 TypeParameterMirror (org.eclipse.ceylon.model.loader.mirror.TypeParameterMirror)1