Search in sources :

Example 1 with DeclarationImpl

use of com.sun.tools.apt.mirror.declaration.DeclarationImpl in project ceylon-compiler by ceylon.

the class DeclarationsImpl method hides.

/**
     * {@inheritDoc}
     * See sections 8.3 and 8.4.6 of
     * <cite>The Java&trade; Language Specification</cite>
     */
public boolean hides(MemberDeclaration sub, MemberDeclaration sup) {
    Symbol hider = ((DeclarationImpl) sub).sym;
    Symbol hidee = ((DeclarationImpl) sup).sym;
    // Names must match.  Nothing hides itself (just try it).
    if (hider == hidee || hider.kind != hidee.kind || hider.name != hidee.name) {
        return false;
    }
    // Methods only hide methods with matching signatures.
    if (hider.kind == MTH) {
        if ((hider.flags() & Flags.STATIC) == 0 || !env.jctypes.isSubSignature(hider.type, hidee.type)) {
            return false;
        }
    }
    // Hider must be in a subclass of hidee's class.
    // Note that if M1 hides M2, and M2 hides M3, and M3 is accessible
    // in M1's class, then M1 and M2 both hide M3.
    ClassSymbol hiderClass = hider.owner.enclClass();
    ClassSymbol hideeClass = hidee.owner.enclClass();
    if (hiderClass == null || hideeClass == null || !hiderClass.isSubClass(hideeClass, env.jctypes)) {
        return false;
    }
    // The method isInheritedIn is poorly named:  it checks only access.
    return hidee.isInheritedIn(hiderClass, env.jctypes);
}
Also used : Symbol(com.sun.tools.javac.code.Symbol) MethodDeclarationImpl(com.sun.tools.apt.mirror.declaration.MethodDeclarationImpl) DeclarationImpl(com.sun.tools.apt.mirror.declaration.DeclarationImpl)

Aggregations

DeclarationImpl (com.sun.tools.apt.mirror.declaration.DeclarationImpl)1 MethodDeclarationImpl (com.sun.tools.apt.mirror.declaration.MethodDeclarationImpl)1 Symbol (com.sun.tools.javac.code.Symbol)1