Java Code Examples for com.sun.tools.javac.code.Symbol#isMemberOf()

The following examples show how to use com.sun.tools.javac.code.Symbol#isMemberOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean checkTypeContainsImportableElement(TypeSymbol tsym, TypeSymbol origin, PackageSymbol packge, Name name, Set<Symbol> processed) {
    if (tsym == null || !processed.add(tsym))
        return false;

        // also search through inherited names
    if (checkTypeContainsImportableElement(types.supertype(tsym.type).tsym, origin, packge, name, processed))
        return true;

    for (Type t : types.interfaces(tsym.type))
        if (checkTypeContainsImportableElement(t.tsym, origin, packge, name, processed))
            return true;

    for (Symbol sym : tsym.members().getSymbolsByName(name)) {
        if (sym.isStatic() &&
            importAccessible(sym, packge) &&
            sym.isMemberOf(origin, types)) {
            return true;
        }
    }

    return false;
}
 
Example 2
Source File: LambdaToMethod.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the declaration corresponding to a symbol in the enclosing
 * scope; the depth parameter is used to filter out symbols defined
 * in nested scopes (which do not need to undergo capture).
 */
private JCTree capturedDecl(int depth, Symbol sym) {
    int currentDepth = frameStack.size() - 1;
    for (Frame block : frameStack) {
        switch (block.tree.getTag()) {
            case CLASSDEF:
                ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
                if (sym.isMemberOf(clazz, types)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case VARDEF:
                if (((JCVariableDecl)block.tree).sym == sym &&
                        sym.owner.kind == MTH) { //only locals are captured
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case BLOCK:
            case METHODDEF:
            case LAMBDA:
                if (block.locals != null && block.locals.contains(sym)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            default:
                Assert.error("bad decl kind " + block.tree.getTag());
        }
        currentDepth--;
    }
    return null;
}
 
Example 3
Source File: LambdaToMethod.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the declaration corresponding to a symbol in the enclosing
 * scope; the depth parameter is used to filter out symbols defined
 * in nested scopes (which do not need to undergo capture).
 */
private JCTree capturedDecl(int depth, Symbol sym) {
    int currentDepth = frameStack.size() - 1;
    for (Frame block : frameStack) {
        switch (block.tree.getTag()) {
            case CLASSDEF:
                ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
                if (sym.isMemberOf(clazz, types)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case VARDEF:
                if (((JCVariableDecl)block.tree).sym == sym &&
                        sym.owner.kind == MTH) { //only locals are captured
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case BLOCK:
            case METHODDEF:
            case LAMBDA:
                if (block.locals != null && block.locals.contains(sym)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            default:
                Assert.error("bad decl kind " + block.tree.getTag());
        }
        currentDepth--;
    }
    return null;
}
 
Example 4
Source File: LambdaToMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the declaration corresponding to a symbol in the enclosing
 * scope; the depth parameter is used to filter out symbols defined
 * in nested scopes (which do not need to undergo capture).
 */
private JCTree capturedDecl(int depth, Symbol sym) {
    int currentDepth = frameStack.size() - 1;
    for (Frame block : frameStack) {
        switch (block.tree.getTag()) {
            case CLASSDEF:
                ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
                if (sym.isMemberOf(clazz, types)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case VARDEF:
                if (((JCVariableDecl)block.tree).sym == sym &&
                        sym.owner.kind == MTH) { //only locals are captured
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case BLOCK:
            case METHODDEF:
            case LAMBDA:
                if (block.locals != null && block.locals.contains(sym)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            default:
                Assert.error("bad decl kind " + block.tree.getTag());
        }
        currentDepth--;
    }
    return null;
}
 
Example 5
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Construct a tree that represents the closest outer instance
 *  {@code C.this} such that the given symbol is a member of C.
 *  @param pos           The source code position to be used for the tree.
 *  @param sym           The accessed symbol.
 *  @param preciseMatch  should we accept a type that is a subtype of
 *                       sym's owner, even if it doesn't contain sym
 *                       due to hiding, overriding, or non-inheritance
 *                       due to protection?
 */
JCExpression makeOwnerThis(DiagnosticPosition pos, Symbol sym, boolean preciseMatch) {
    Symbol c = sym.owner;
    if (preciseMatch ? sym.isMemberOf(currentClass, types)
                     : currentClass.isSubClass(sym.owner, types)) {
        // in this case, `this' works fine
        return make.at(pos).This(c.erasure(types));
    } else {
        // need to go via this$n
        return makeOwnerThisN(pos, sym, preciseMatch);
    }
}
 
Example 6
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Similar to makeOwnerThis but will never pick "this".
 */
JCExpression makeOwnerThisN(DiagnosticPosition pos, Symbol sym, boolean preciseMatch) {
    Symbol c = sym.owner;
    List<VarSymbol> ots = outerThisStack;
    if (ots.isEmpty()) {
        log.error(pos, Errors.NoEnclInstanceOfTypeInScope(c));
        Assert.error();
        return makeNull();
    }
    VarSymbol ot = ots.head;
    JCExpression tree = access(make.at(pos).Ident(ot));
    TypeSymbol otc = ot.type.tsym;
    while (!(preciseMatch ? sym.isMemberOf(otc, types) : otc.isSubClass(sym.owner, types))) {
        do {
            ots = ots.tail;
            if (ots.isEmpty()) {
                log.error(pos, Errors.NoEnclInstanceOfTypeInScope(c));
                Assert.error();
                return tree;
            }
            ot = ots.head;
        } while (ot.owner != otc);
        tree = access(make.at(pos).Select(tree, ot));
        otc = ot.type.tsym;
    }
    return tree;
}
 
Example 7
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Return the declaration corresponding to a symbol in the enclosing
 * scope; the depth parameter is used to filter out symbols defined
 * in nested scopes (which do not need to undergo capture).
 */
private JCTree capturedDecl(int depth, Symbol sym) {
    int currentDepth = frameStack.size() - 1;
    for (Frame block : frameStack) {
        switch (block.tree.getTag()) {
            case CLASSDEF:
                ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
                if (clazz.isSubClass(sym, types) || sym.isMemberOf(clazz, types)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case VARDEF:
                if (((JCVariableDecl)block.tree).sym == sym &&
                        sym.owner.kind == MTH) { //only locals are captured
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case BLOCK:
            case METHODDEF:
            case LAMBDA:
                if (block.locals != null && block.locals.contains(sym)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            default:
                Assert.error("bad decl kind " + block.tree.getTag());
        }
        currentDepth--;
    }
    return null;
}
 
Example 8
Source File: LambdaToMethod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the declaration corresponding to a symbol in the enclosing
 * scope; the depth parameter is used to filter out symbols defined
 * in nested scopes (which do not need to undergo capture).
 */
private JCTree capturedDecl(int depth, Symbol sym) {
    int currentDepth = frameStack.size() - 1;
    for (Frame block : frameStack) {
        switch (block.tree.getTag()) {
            case CLASSDEF:
                ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
                if (sym.isMemberOf(clazz, types)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case VARDEF:
                if (((JCVariableDecl)block.tree).sym == sym &&
                        sym.owner.kind == MTH) { //only locals are captured
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case BLOCK:
            case METHODDEF:
            case LAMBDA:
                if (block.locals != null && block.locals.contains(sym)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            default:
                Assert.error("bad decl kind " + block.tree.getTag());
        }
        currentDepth--;
    }
    return null;
}
 
Example 9
Source File: LambdaToMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the declaration corresponding to a symbol in the enclosing
 * scope; the depth parameter is used to filter out symbols defined
 * in nested scopes (which do not need to undergo capture).
 */
private JCTree capturedDecl(int depth, Symbol sym) {
    int currentDepth = frameStack.size() - 1;
    for (Frame block : frameStack) {
        switch (block.tree.getTag()) {
            case CLASSDEF:
                ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
                if (clazz.isSubClass(sym, types) || sym.isMemberOf(clazz, types)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case VARDEF:
                if (((JCVariableDecl)block.tree).sym == sym &&
                        sym.owner.kind == MTH) { //only locals are captured
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case BLOCK:
            case METHODDEF:
            case LAMBDA:
                if (block.locals != null && block.locals.contains(sym)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            default:
                Assert.error("bad decl kind " + block.tree.getTag());
        }
        currentDepth--;
    }
    return null;
}
 
Example 10
Source File: LambdaToMethod.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the declaration corresponding to a symbol in the enclosing
 * scope; the depth parameter is used to filter out symbols defined
 * in nested scopes (which do not need to undergo capture).
 */
private JCTree capturedDecl(int depth, Symbol sym) {
    int currentDepth = frameStack.size() - 1;
    for (Frame block : frameStack) {
        switch (block.tree.getTag()) {
            case CLASSDEF:
                ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
                if (sym.isMemberOf(clazz, types)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case VARDEF:
                if (((JCVariableDecl)block.tree).sym == sym &&
                        sym.owner.kind == MTH) { //only locals are captured
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case BLOCK:
            case METHODDEF:
            case LAMBDA:
                if (block.locals != null && block.locals.contains(sym)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            default:
                Assert.error("bad decl kind " + block.tree.getTag());
        }
        currentDepth--;
    }
    return null;
}
 
Example 11
Source File: LambdaToMethod.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the declaration corresponding to a symbol in the enclosing
 * scope; the depth parameter is used to filter out symbols defined
 * in nested scopes (which do not need to undergo capture).
 */
private JCTree capturedDecl(int depth, Symbol sym) {
    int currentDepth = frameStack.size() - 1;
    for (Frame block : frameStack) {
        switch (block.tree.getTag()) {
            case CLASSDEF:
                ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
                if (sym.isMemberOf(clazz, types)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case VARDEF:
                if (((JCVariableDecl)block.tree).sym == sym &&
                        sym.owner.kind == MTH) { //only locals are captured
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case BLOCK:
            case METHODDEF:
            case LAMBDA:
                if (block.locals != null && block.locals.contains(sym)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            default:
                Assert.error("bad decl kind " + block.tree.getTag());
        }
        currentDepth--;
    }
    return null;
}
 
Example 12
Source File: LambdaToMethod.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the declaration corresponding to a symbol in the enclosing
 * scope; the depth parameter is used to filter out symbols defined
 * in nested scopes (which do not need to undergo capture).
 */
private JCTree capturedDecl(int depth, Symbol sym) {
    int currentDepth = frameStack.size() - 1;
    for (Frame block : frameStack) {
        switch (block.tree.getTag()) {
            case CLASSDEF:
                ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
                if (sym.isMemberOf(clazz, types)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case VARDEF:
                if (((JCVariableDecl)block.tree).sym == sym &&
                        sym.owner.kind == MTH) { //only locals are captured
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case BLOCK:
            case METHODDEF:
            case LAMBDA:
                if (block.locals != null && block.locals.contains(sym)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            default:
                Assert.error("bad decl kind " + block.tree.getTag());
        }
        currentDepth--;
    }
    return null;
}
 
Example 13
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** Add bridge if given symbol is a non-private, non-static member
 *  of the given class, which is either defined in the class or non-final
 *  inherited, and one of the two following conditions holds:
 *  1. The method's type changes in the given class, as compared to the
 *     class where the symbol was defined, (in this case
 *     we have extended a parameterized class with non-trivial parameters).
 *  2. The method has an implementation with a different erased return type.
 *     (in this case we have used co-variant returns).
 *  If a bridge already exists in some other class, no new bridge is added.
 *  Instead, it is checked that the bridge symbol overrides the method symbol.
 *  (Spec ???).
 *  todo: what about bridges for privates???
 *
 *  @param pos     The source code position to be used for the definition.
 *  @param sym     The symbol for which a bridge might have to be added.
 *  @param origin  The class in which the bridge would go.
 *  @param bridges The list buffer to which the bridge would be added.
 */
void addBridgeIfNeeded(DiagnosticPosition pos,
                       Symbol sym,
                       ClassSymbol origin,
                       ListBuffer<JCTree> bridges) {
    if (sym.kind == MTH &&
        sym.name != names.init &&
        (sym.flags() & (PRIVATE | STATIC)) == 0 &&
        (sym.flags() & SYNTHETIC) != SYNTHETIC &&
        sym.isMemberOf(origin, types))
    {
        MethodSymbol meth = (MethodSymbol)sym;
        MethodSymbol bridge = meth.binaryImplementation(origin, types);
        MethodSymbol impl = meth.implementation(origin, types, true);
        if (bridge == null ||
            bridge == meth ||
            (impl != null && !bridge.owner.isSubClass(impl.owner, types))) {
            // No bridge was added yet.
            if (impl != null && isBridgeNeeded(meth, impl, origin.type)) {
                addBridge(pos, meth, impl, origin, bridge==impl, bridges);
            } else if (impl == meth
                       && impl.owner != origin
                       && (impl.flags() & FINAL) == 0
                       && (meth.flags() & (ABSTRACT|PUBLIC)) == PUBLIC
                       && (origin.flags() & PUBLIC) > (impl.owner.flags() & PUBLIC)) {
                // this is to work around a horrible but permanent
                // reflection design error.
                addBridge(pos, meth, impl, origin, false, bridges);
            }
        } else if ((bridge.flags() & SYNTHETIC) == SYNTHETIC) {
            final Pair<MethodSymbol, MethodSymbol> bridgeSpan = bridgeSpans.get(bridge);
            MethodSymbol other = bridgeSpan == null ? null : bridgeSpan.fst;
            if (other != null && other != meth) {
                if (impl == null || !impl.overrides(other, origin, types, true)) {
                    // Is bridge effectively also the bridge for `meth', if so no clash.
                    MethodSymbol target = bridgeSpan == null ? null : bridgeSpan.snd;
                    if (target == null || !target.overrides(meth, origin, types, true, false)) {
                        // Bridge for other symbol pair was added
                        log.error(pos, Errors.NameClashSameErasureNoOverride(
                                other.name, types.memberType(origin.type, other).asMethodType().getParameterTypes(),
                                other.location(origin.type, types),
                                meth.name, types.memberType(origin.type, meth).asMethodType().getParameterTypes(),
                                meth.location(origin.type, types)));
                    }
                }
            }
        } else if (!bridge.overrides(meth, origin, types, true)) {
            // Accidental binary override without source override.
            // Don't diagnose the problem if it would already
            // have been reported in the superclass
            if (bridge.owner == origin ||
                types.asSuper(bridge.owner.type, meth.owner) == null) {
                log.error(pos, Errors.NameClashSameErasureNoOverride(
                        bridge.name, types.memberType(origin.type, bridge).asMethodType().getParameterTypes(),
                        bridge.location(origin.type, types),
                        meth.name, types.memberType(origin.type, meth).asMethodType().getParameterTypes(),
                        meth.location(origin.type, types)));
            }
        }
    }
}