/** Is given protected symbol accessible if it is selected from given site * and the selection takes place in given class? * @param sym The symbol with protected access * @param c The class where the access takes place * @site The type of the qualifier */ private boolean isProtectedAccessible(Symbol sym, ClassSymbol c, Type site) { Type newSite = site.hasTag(TYPEVAR) ? site.getUpperBound() : site; while (c != null && !(c.isSubClass(sym.owner, types) && (c.flags() & INTERFACE) == 0 && // In JLS 2e 6.6.2.1, the subclass restriction applies // only to instance fields and methods -- types are excluded // regardless of whether they are declared 'static' or not. ((sym.flags() & STATIC) != 0 || sym.kind == TYP || newSite.tsym.isSubClass(c, types)))) c = c.owner.enclClass(); return c != null; }
private boolean isSubClass(Type t, final List<Type> ts) { t = t.baseType(); if (t.tag == TYPEVAR) { List<Type> bounds = types.getBounds((TypeVar)t); for (Type s : ts) { if (!types.isSameType(t, s.baseType())) { for (Type bound : bounds) { if (!isSubClass(bound, List.of(s.baseType()))) return false; } } } } else { for (Type s : ts) { if (!t.tsym.isSubClass(s.baseType().tsym, types)) return false; } } return true; }
/** Is given protected symbol accessible if it is selected from given site * and the selection takes place in given class? * @param sym The symbol with protected access * @param c The class where the access takes place * @site The type of the qualifier */ private boolean isProtectedAccessible(Symbol sym, ClassSymbol c, Type site) { while (c != null && !(c.isSubClass(sym.owner, types) && (c.flags() & INTERFACE) == 0 && // In JLS 2e 6.6.2.1, the subclass restriction applies // only to instance fields and methods -- types are excluded // regardless of whether they are declared 'static' or not. ((sym.flags() & STATIC) != 0 || sym.kind == TYP || site.tsym.isSubClass(c, types)))) c = c.owner.enclClass(); return c != null; }
/** Is given protected symbol accessible if it is selected from given site * and the selection takes place in given class? * @param sym The symbol with protected access * @param c The class where the access takes place * @site The type of the qualifier */ private boolean isProtectedAccessible(Symbol sym, ClassSymbol c, Type site) { while (c != null && !(c.isSubClass(sym.owner, types) && (c.flags() & INTERFACE) == 0 && // In JLS 2e 6.6.2.1, the subclass restriction applies // only to instance fields and methods -- types are excluded // regardless of whether they are declared 'static' or not. ((sym.flags() & STATIC) != 0 || sym.kind == TYP || site.tsym.isSubClass(c, types)))) c = c.owner.enclClass(); return c != null; }
/** Is given protected symbol accessible if it is selected from given site * and the selection takes place in given class? * @param sym The symbol with protected access * @param c The class where the access takes place * @site The type of the qualifier */ private boolean isProtectedAccessible(Symbol sym, ClassSymbol c, Type site) { Type newSite = site.hasTag(TYPEVAR) ? site.getUpperBound() : site; while (c != null && !(c.isSubClass(sym.owner, types) && (c.flags() & INTERFACE) == 0 && // In JLS 2e 6.6.2.1, the subclass restriction applies // only to instance fields and methods -- types are excluded // regardless of whether they are declared 'static' or not. ((sym.flags() & STATIC) != 0 || sym.kind == TYP || newSite.tsym.isSubClass(c, types)))) c = c.owner.enclClass(); return c != null; }
public boolean isSubClass(Symbol base, Types types) { if (this == base) { return true; } else if ((base.flags() & INTERFACE) != 0) { for (Type t = type; t.hasTag(CLASS); t = types.supertype(t)) for (List<Type> is = types.interfaces(t); is.nonEmpty(); is = is.tail) if (is.head.tsym.isSubClass(base, types)) return true; } else { for (Type t = type; t.hasTag(CLASS); t = types.supertype(t)) if (t.tsym == base) return true; } return false; }
/** Do we need an access method to reference symbol in other package? */ boolean needsProtectedAccess(Symbol sym, JCTree tree) { if ((sym.flags() & PROTECTED) == 0 || sym.owner.owner == currentClass.owner || // fast special case sym.packge() == currentClass.packge()) return false; if (!currentClass.isSubClass(sym.owner, types)) return true; if ((sym.flags() & STATIC) != 0 || !tree.hasTag(SELECT) || TreeInfo.name(((JCFieldAccess) tree).selected) == names._super) return false; return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types); }
public boolean isSubClass(Symbol base, Types types) { if (this == base) { return true; } else if ((base.flags() & INTERFACE) != 0) { for (Type t = type; t.hasTag(CLASS); t = types.supertype(t)) for (List<Type> is = types.interfaces(t); is.nonEmpty(); is = is.tail) if (is.head.tsym.isSubClass(base, types)) return true; } else { for (Type t = type; t.hasTag(CLASS); t = types.supertype(t)) if (t.tsym == base) return true; } return false; }
/** Do we need an access method to reference symbol in other package? */ boolean needsProtectedAccess(Symbol sym, JCTree tree) { if ((sym.flags() & PROTECTED) == 0 || sym.owner.owner == currentClass.owner || // fast special case sym.packge() == currentClass.packge()) return false; if (!currentClass.isSubClass(sym.owner, types)) return true; if ((sym.flags() & STATIC) != 0 || tree.getTag() != JCTree.SELECT || TreeInfo.name(((JCFieldAccess) tree).selected) == names._super) return false; return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types); }
public boolean isSubClass(Symbol base, Types types) { if (this == base) { return true; } else if ((base.flags() & INTERFACE) != 0) { for (Type t = type; t.tag == CLASS; t = types.supertype(t)) for (List<Type> is = types.interfaces(t); is.nonEmpty(); is = is.tail) if (is.head.tsym.isSubClass(base, types)) return true; } else { for (Type t = type; t.tag == CLASS; t = types.supertype(t)) if (t.tsym == base) return true; } return false; }
public boolean isSubClass(Symbol base, Types types) { if (this == base) { return true; } else if ((base.flags() & INTERFACE) != 0) { for (Type t = type; t.tag == CLASS; t = types.supertype(t)) for (List<Type> is = types.interfaces(t); is.nonEmpty(); is = is.tail) if (is.head.tsym.isSubClass(base, types)) return true; } else { for (Type t = type; t.tag == CLASS; t = types.supertype(t)) if (t.tsym == base) return true; } return false; }
/** Do we need an access method to reference symbol in other package? */ boolean needsProtectedAccess(Symbol sym, JCTree tree) { if ((sym.flags() & PROTECTED) == 0 || sym.owner.owner == currentClass.owner || // fast special case sym.packge() == currentClass.packge()) return false; if (!currentClass.isSubClass(sym.owner, types)) return true; if ((sym.flags() & STATIC) != 0 || !tree.hasTag(SELECT) || TreeInfo.name(((JCFieldAccess) tree).selected) == names._super) return false; return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types); }
/** Do we need an access method to reference symbol in other package? */ boolean needsProtectedAccess(Symbol sym, JCTree tree) { if ((sym.flags() & PROTECTED) == 0 || sym.owner.owner == currentClass.owner || // fast special case sym.packge() == currentClass.packge()) return false; if (!currentClass.isSubClass(sym.owner, types)) return true; if ((sym.flags() & STATIC) != 0 || tree.tag != JCTree.SELECT || TreeInfo.name(((JCFieldAccess) tree).selected) == names._super) return false; return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types); }
private JCExpression makeReceiver(VarSymbol rcvr) { if (rcvr == null) return null; JCExpression rcvrExpr = make.Ident(rcvr); Type rcvrType = tree.ownerAccessible ? tree.sym.enclClass().type : tree.expr.type; if (rcvrType == syms.arrayClass.type) { // Map the receiver type to the actually type, not just "array" rcvrType = tree.getQualifierExpression().type; } if (!rcvr.type.tsym.isSubClass(rcvrType.tsym, types)) { rcvrExpr = make.TypeCast(make.Type(rcvrType), rcvrExpr).setType(rcvrType); } return rcvrExpr; }
/** Fully check membership: hierarchy, protection, and hiding. * Does not exclude methods not inherited due to overriding. */ public boolean isMemberOf(TypeSymbol clazz, Types types) { return owner == clazz || clazz.isSubClass(owner, types) && isInheritedIn(clazz, types) && !hiddenIn((ClassSymbol)clazz, types); }
private JCExpression makeReceiver(VarSymbol rcvr) { if (rcvr == null) return null; JCExpression rcvrExpr = make.Ident(rcvr); Type rcvrType = tree.sym.enclClass().type; if (!rcvr.type.tsym.isSubClass(rcvrType.tsym, types)) { rcvrExpr = make.TypeCast(make.Type(rcvrType), rcvrExpr).setType(rcvrType); } return rcvrExpr; }
/** Fully check membership: hierarchy, protection, and hiding. * Does not exclude methods not inherited due to overriding. */ public boolean isMemberOf(TypeSymbol clazz, Types types) { return owner == clazz || clazz.isSubClass(owner, types) && isInheritedIn(clazz, types) && !hiddenIn((ClassSymbol)clazz, types); }
/** Fully check membership: hierarchy, protection, and hiding. * Does not exclude methods not inherited due to overriding. */ public boolean isMemberOf(TypeSymbol clazz, Types types) { return owner == clazz || clazz.isSubClass(owner, types) && isInheritedIn(clazz, types) && !hiddenIn((ClassSymbol)clazz, types); }
/** Fully check membership: hierarchy, protection, and hiding. * Does not exclude methods not inherited due to overriding. */ public boolean isMemberOf(TypeSymbol clazz, Types types) { return owner == clazz || clazz.isSubClass(owner, types) && isInheritedIn(clazz, types) && !hiddenIn((ClassSymbol)clazz, types); }
@Override public boolean matches(ExpressionTree t, VisitorState state) { Type type = ((JCTree) t).type; // Expect a class type. if (!(type instanceof ClassType)) { return false; } // Expect one type argument, the type of the JUnit class runner to use. com.sun.tools.javac.util.List<Type> typeArgs = ((ClassType) type).getTypeArguments(); if (typeArgs.size() != 1) { return false; } Type runnerType = typeArgs.get(0); for (String testRunner : TEST_RUNNERS) { Symbol parent = state.getSymbolFromString(testRunner); if (parent == null) { continue; } if (runnerType.tsym.isSubClass(parent, state.getTypes())) { return true; } } return false; } };