Search in sources :

Example 11 with MethodSymbol

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

the class JavacTrees method searchMethod.

/**
 * @see com.sun.tools.javadoc.ClassDocImpl#searchMethod
 */
private MethodSymbol searchMethod(ClassSymbol tsym, Name methodName, List<Type> paramTypes, Set<ClassSymbol> searched) {
    // do not match constructors
    if (methodName == names.init)
        return null;
    if (searched.contains(tsym))
        return null;
    searched.add(tsym);
    // search current class
    org.eclipse.ceylon.langtools.tools.javac.code.Scope.Entry e = tsym.members().lookup(methodName);
    if (paramTypes == null) {
        // If no parameters specified, we are allowed to return
        // any method with a matching name.  In practice, the old
        // code returned the first method, which is now the last!
        // In order to provide textually identical results, we
        // attempt to emulate the old behavior.
        MethodSymbol lastFound = null;
        for (; e.scope != null; e = e.next()) {
            if (e.sym.kind == Kinds.MTH) {
                if (e.sym.name == methodName) {
                    lastFound = (MethodSymbol) e.sym;
                }
            }
        }
        if (lastFound != null) {
            return lastFound;
        }
    } else {
        for (; e.scope != null; e = e.next()) {
            if (e.sym != null && e.sym.kind == Kinds.MTH) {
                if (hasParameterTypes((MethodSymbol) e.sym, paramTypes)) {
                    return (MethodSymbol) e.sym;
                }
            }
        }
    }
    // ### If we found a MethodSymbol above, but which did not pass
    // ### the modifier filter, we should return failure here!
    // search superclass
    Type superclass = tsym.getSuperclass();
    if (superclass.tsym != null) {
        MethodSymbol msym = searchMethod((ClassSymbol) superclass.tsym, methodName, paramTypes, searched);
        if (msym != null) {
            return msym;
        }
    }
    // search interfaces
    List<Type> intfs = tsym.getInterfaces();
    for (List<Type> l = intfs; l.nonEmpty(); l = l.tail) {
        Type intf = l.head;
        if (intf.isErroneous())
            continue;
        MethodSymbol msym = searchMethod((ClassSymbol) intf.tsym, methodName, paramTypes, searched);
        if (msym != null) {
            return msym;
        }
    }
    // search enclosing class
    ClassSymbol encl = tsym.owner.enclClass();
    if (encl != null) {
        MethodSymbol msym = searchMethod(encl, methodName, paramTypes, searched);
        if (msym != null) {
            return msym;
        }
    }
    return null;
}
Also used : UnionClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.UnionClassType) DeclaredType(org.eclipse.ceylon.javax.lang.model.type.DeclaredType) Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) ErrorType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ErrorType) ArrayType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType) ClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ClassType) Scope(org.eclipse.ceylon.langtools.source.tree.Scope) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)

Aggregations

ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)11 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)11 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)10 TypeSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)8 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)8 MethodType (org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType)8 ArrayType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType)6 JavacType (org.eclipse.ceylon.compiler.java.loader.mirror.JavacType)5 PackageSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol)5 VarSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)5 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)5 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)5 CompletionFailure (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure)4 DynamicMethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.DynamicMethodSymbol)3 FunctionDescriptorLookupError (org.eclipse.ceylon.langtools.tools.javac.code.Types.FunctionDescriptorLookupError)3 LinkedList (java.util.LinkedList)1 JavacClass (org.eclipse.ceylon.compiler.java.loader.mirror.JavacClass)1 JavacMethod (org.eclipse.ceylon.compiler.java.loader.mirror.JavacMethod)1 DeclaredType (org.eclipse.ceylon.javax.lang.model.type.DeclaredType)1 Scope (org.eclipse.ceylon.langtools.source.tree.Scope)1