@Override public Void visitWildcardType(Type.WildcardType type, Void unused) { if (type.getSuperBound() != null) { type.getSuperBound().accept(this, null); } if (type.getExtendsBound() != null) { type.getExtendsBound().accept(this, null); } return null; }
public void visitIntersectionClassType(Type.IntersectionClassType type) { for (Type component : type.getComponents()) { component.accept(this, null); } }
@Override public Void visitClassType(Type.ClassType t, Void aVoid) { for (Type a : t.getTypeArguments()) { a.accept(this, null); } if (t.getEnclosingType() != null) { t.getEnclosingType().accept(this, null); } return null; }
@Override public void visitSelect(JCTree.JCFieldAccess jcFieldAccess) { Symbol symbol = jcFieldAccess.sym; if (symbol.getEnclosingElement() != null && symbol.getEnclosingElement().getEnclosingElement() != null && symbol.getEnclosingElement().getEnclosingElement().enclClass() != null) { try { int value = (Integer) requireNonNull(((Symbol.VarSymbol) symbol).getConstantValue()); resourceIds.put(value, new Id(value, symbol)); } catch (Exception ignored) { } } }
private boolean isIgnoredReturnType(JCMethodDecl method, VisitorState state) { Type returnType = method.sym.getReturnType(); // Methods returning a primitive cannot return null. Also ignore Void-returning methods as // the only valid Void value is null, so it's implied. // TODO(kmb): Technically we should assume NULL when we see a call to a method that returns Void return returnType.isPrimitiveOrVoid() || state.getTypes().isSameType(returnType, state.getTypeFromString("java.lang.Void")); }
private Symbol getSuperType(Symbol symbol, String name) { for (Type t : types.closure(symbol.type)) { if (t.asElement().getSimpleName().contentEquals(name)) { return t.asElement(); } } return null; }
private static String getClassName(ClassSymbol s) { if (s.isAnonymous()) { return s.getSuperclass().tsym.getSimpleName().toString(); } else { return s.getSimpleName().toString(); } }
@Override public String visitType(Type t, Void unused) { return t.toString(); } },
private GuardedBySymbolResolver( ClassSymbol enclosingClass, CompilationUnitTree compilationUnit, Context context, Tree leaf) { this.compilationUnit = (JCCompilationUnit) compilationUnit; this.enclosingClass = enclosingClass; this.context = context; this.types = Types.instance(context); this.decl = leaf; }
/** * Returns {@code true} for {@link MethodSymbol}s whose result type is a generic type variable. */ private static boolean hasGenericResult(MethodSymbol methodSymbol) { return methodSymbol.getReturnType().tsym instanceof TypeVariableSymbol; }
private ClassAndField(VarSymbol symbol) { this.symbol = symbol; this.clazz = symbol.owner.getQualifiedName().toString(); this.field = symbol.getSimpleName().toString(); }
@Override public Void visitClassType(Type.ClassType type, Void unused) { if (type instanceof Type.IntersectionClassType) { // TypeVisitor doesn't support intersection types natively visitIntersectionClassType((Type.IntersectionClassType) type); } else { for (Type t : type.getTypeArguments()) { t.accept(this, null); } } return null; }
@Override public Void visitArrayType(Type.ArrayType type, Void unused) { type.elemtype.accept(this, null); return null; }
/** Returns true if the given method symbol has a {@code @Test(expected=...)} annotation. */ private static boolean isExpectedExceptionTest(MethodSymbol sym, VisitorState state) { Compound attribute = sym.attribute(state.getSymbolFromString(JUnitMatchers.JUNIT4_TEST_ANNOTATION)); if (attribute == null) { return false; } return attribute.member(state.getName("expected")) != null; }
@Override public int hashCode() { int h = 1; h *= 1000003; h ^= (type == null) ? 0 : this.type.hashCode(); return h; }
private boolean isOwnedBy(Symbol sym, Symbol owner, Types types) { if (sym.owner == owner) { return true; } if (owner instanceof TypeSymbol) { return sym.isMemberOf((TypeSymbol) owner, types); } return false; }
private static Symbol createSymbol(Symbol oldSymbol, Name newName, Type newType) { Symbol newSymbol = oldSymbol.clone(oldSymbol.owner); newSymbol.name = newName; newSymbol.type = newType; return newSymbol; }
@Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.typeTag.hashCode(); return h; }