@Override public boolean equals(Object other) { if (!(other instanceof VarSymbol)) { return false; } VarSymbol that = (VarSymbol) other; if (!that.getSimpleName().contentEquals(ENCLOSING_INSTANCE_NAME)) { return false; } return owner.equals(that.owner); } }
@Override boolean classIsAppropriate(ClassSymbol classSymbol) { return classSymbol.getQualifiedName().contentEquals(className); }
@Override boolean classIsAppropriate(ClassSymbol classSymbol) { return classSymbol.getQualifiedName().contentEquals(className); }
private Symbol getLexicallyEnclosing(ClassSymbol symbol, String name) { Symbol current = symbol.owner; while (true) { if (current == null || current.getSimpleName().contentEquals(name)) { return current; } if (current != current.owner && current.owner instanceof Symbol.ClassSymbol) { current = current.owner; } else { return null; } } }
@Override boolean classIsAppropriate(ClassSymbol classSymbol) { return classSymbol.getQualifiedName().contentEquals(className); }
/** * Returns the value of the annotation element-value pair with the given name if it is not * explicitly set. */ public static Optional<Attribute> getValue(Attribute.Compound attribute, String name) { return attribute.getElementValues().entrySet().stream() .filter(e -> e.getKey().getSimpleName().contentEquals(name)) .map(Map.Entry::getValue) .findFirst(); }
private boolean isSystemExit(ExpressionTree expression) { if (!(expression instanceof MethodInvocationTree)) { return false; } MethodSymbol sym = getSymbol((MethodInvocationTree) expression); if (sym == null) { return false; } return sym.owner.getQualifiedName().contentEquals("java.lang.System") && sym.getSimpleName().contentEquals("exit"); }
@Override protected Optional<MatchState> matchResult( ExpressionTree item, MatchState method, VisitorState state) { if (!method.sym().getSimpleName().contentEquals(name)) { return Optional.absent(); } return Optional.of(method); } }
private static String getDoNotCallValue(Symbol symbol) { for (Attribute.Compound a : symbol.getRawAttributes()) { if (!a.type.tsym.getQualifiedName().contentEquals(DO_NOT_CALL)) { continue; } return MoreAnnotations.getValue(a, "value") .flatMap(MoreAnnotations::asStringValue) .orElse(""); } throw new IllegalStateException(); } }
/** * Returns true if the given type parameter's declaration is annotated with {@link * #typeParameterAnnotation} indicated it will only ever be instantiated with thread-safe types. */ public boolean hasThreadSafeTypeParameterAnnotation(TypeVariableSymbol symbol) { return typeParameterAnnotation != null && symbol.getAnnotationMirrors().stream() .anyMatch(t -> t.type.tsym.flatName().contentEquals(typeParameterAnnotation.getName())); }
@Override boolean fieldSymbolIsAppropriate(Symbol symbol) { return !symbol.isStatic() && symbol.getSimpleName().contentEquals(fieldName); } };
private static boolean matchesClass(ExpressionTree tree) { Symbol symbol = getSymbol(tree); if (!(symbol instanceof VarSymbol)) { return false; } VarSymbol varSymbol = (VarSymbol) symbol; return varSymbol.getSimpleName().contentEquals("class"); }
@Override boolean fieldSymbolIsAppropriate(Symbol symbol) { return symbol.isStatic() && symbol.getSimpleName().contentEquals(fieldName); } };
@Override protected Optional<MatchState> matchResult( ExpressionTree item, MatchState method, VisitorState state) { // TODO(cushon): build a way to match signatures (including varargs ones!) that doesn't // rely on MethodSymbol#toString(). boolean matches = method.sym().getSimpleName().contentEquals(methodName) || method.sym().toString().equals(methodName); return matches ? Optional.of(method) : Optional.<MatchState>absent(); } }
private static void pprintSelect(Select exp, StringBuilder sb) { sb.append(String.format("(%s ", exp.kind())); pprint(exp.base(), sb); if (exp.sym().name.contentEquals(ENCLOSING_INSTANCE_NAME)) { sb.append(String.format(" %s%s)", ENCLOSING_INSTANCE_NAME, exp.sym().owner)); } else { sb.append(String.format(" %s)", exp.sym())); } } }
@Override public boolean matches(MethodTree methodTree, VisitorState state) { return ASTHelpers.getSymbol(methodTree) .getEnclosingElement() .getQualifiedName() .contentEquals(className) && methodTree.getName().contentEquals(methodName); } };
/** Returns true if the given symbol has static modifier and is all upper case. */ private static boolean isUpperCaseAndStatic(Symbol symbol) { return symbol.isStatic() && symbol.name.contentEquals(Ascii.toUpperCase(symbol.name.toString())); }
private Description.Builder describeClass( Tree tree, ClassSymbol sym, AnnotationInfo annotation, Violation info) { String message; if (sym.getQualifiedName().contentEquals(annotation.typeName())) { message = "type annotated with @Immutable could not be proven immutable: " + info.message(); } else { message = String.format( "Class extends @Immutable type %s, but is not immutable: %s", annotation.typeName(), info.message()); } return buildDescription(tree).setMessage(message); }
boolean shouldUseGuava(VisitorState state) { for (ImportTree importTree : state.getPath().getCompilationUnit().getImports()) { Symbol sym = ASTHelpers.getSymbol(importTree.getQualifiedIdentifier()); if (sym == null) { continue; } if (sym.getQualifiedName().contentEquals("com.google.common.io.Files")) { return true; } } return false; }
private boolean overrides(MethodSymbol sym, MethodSymbol other) { return !sym.isStatic() && !other.isStatic() && (((sym.flags() | other.flags()) & Flags.SYNTHETIC) == 0) && sym.name.contentEquals(other.name) && sym.overrides( other, sym.owner.enclClass(), state.getTypes(), /* checkResult= */ false); } }.scan(method.getBody(), null),