Search in sources :

Example 1 with Entry

use of com.sun.tools.javac.code.Scope.Entry in project ceylon-compiler by ceylon.

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 : Type(com.sun.tools.javac.code.Type) UnknownType(com.redhat.ceylon.model.typechecker.model.UnknownType) Entry(com.sun.tools.javac.code.Scope.Entry) CompletionFailure(com.sun.tools.javac.code.Symbol.CompletionFailure) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) CompletionFailure(com.sun.tools.javac.code.Symbol.CompletionFailure) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol)

Aggregations

UnknownType (com.redhat.ceylon.model.typechecker.model.UnknownType)1 Entry (com.sun.tools.javac.code.Scope.Entry)1 Symbol (com.sun.tools.javac.code.Symbol)1 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)1 CompletionFailure (com.sun.tools.javac.code.Symbol.CompletionFailure)1 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)1 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)1 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)1 Type (com.sun.tools.javac.code.Type)1