@CheckForNull private static Symbol.TypeSymbol getSuperclass(Symbol.TypeSymbol symbol) { Type superType = symbol.superClass(); if (superType != null) { return superType.symbol(); } return null; }
@CheckForNull private Symbol.TypeSymbol getSuperclass(Symbol.TypeSymbol symbol) { Type superType = symbol.superClass(); if (superType != null) { return superType.symbol(); } return null; }
private static Optional<Symbol> findIteratorMethod(Symbol parameter) { return parameter.type().symbol().lookupSymbols("iterator").stream() .filter(Symbol::isMethodSymbol) .filter(s -> ((Symbol.MethodSymbol) s).parameterTypes().isEmpty()) .findFirst(); }
private static long numberConstants(SwitchStatementTree switchStatementTree) { return switchStatementTree.expression().symbolType().symbol().memberSymbols().stream() .filter(Symbol::isVariableSymbol) .filter(Symbol::isEnum) .count(); } }
private static List<Symbol> retrieveMembers(Symbol.TypeSymbol classSymbol) { List<Symbol> results = Lists.newLinkedList(); results.addAll(extractMembers(classSymbol, false)); for (Type parentInterface : classSymbol.interfaces()) { results.addAll(extractMembers(parentInterface.symbol(), true)); } Type superClass = classSymbol.superClass(); if (superClass != null) { results.addAll(extractMembers(superClass.symbol(), true)); } return results; }
private static boolean implementsEqualsMethod(Type type) { Symbol.TypeSymbol symbol = type.symbol(); return hasEqualsMethod(symbol) || parentClassImplementsEquals(symbol); }
private void checkSuperTypeDeprecation(@Nullable TypeTree superTypeTree, boolean isInterface) { if (superTypeTree != null) { Type symbolType = superTypeTree.symbolType(); if (symbolType.isClass() && symbolType.symbol().isDeprecated()) { addIssue(superTypeTree, "\"" + symbolType.symbol().name() + "\"" + " is deprecated, " + (isInterface ? "implement" : "extend") + " the suggested replacement instead."); } } }
private static String getTypeName(ExpressionTree tree) { Type type = tree.symbolType(); String name = getTypeName(type); if (name.isEmpty()) { name = getAnonymousClassTypeName(type.symbol()); } return name; }
private static boolean requiresSuperCall(Symbol.MethodSymbol methodSymbol) { Type superType = methodSymbol.owner().type().symbol().superClass(); Collection<Symbol> symbols = Lists.newArrayList(); while (superType != null && !superType.is(JUNIT_FRAMEWORK_TEST_CASE) && symbols.isEmpty()) { symbols = superType.symbol().lookupSymbols(methodSymbol.name()); superType = superType.symbol().superClass(); } return !symbols.isEmpty() && !symbols.iterator().next().owner().type().is(JUNIT_FRAMEWORK_TEST_CASE); }
private static boolean requiresSuperCall(Symbol.MethodSymbol methodSymbol) { Type superType = methodSymbol.owner().type().symbol().superClass(); Collection<Symbol> symbols = Lists.newArrayList(); while (superType != null && !superType.is(JUNIT_FRAMEWORK_TEST_CASE) && symbols.isEmpty()) { symbols = superType.symbol().lookupSymbols(methodSymbol.name()); superType = superType.symbol().superClass(); } return !symbols.isEmpty() && !symbols.iterator().next().owner().type().is(JUNIT_FRAMEWORK_TEST_CASE); }
private Symbol.TypeSymbol wrapperClassSymbol(NewClassTree newClassTree) { Symbol.TypeSymbol classSymbol = newClassTree.symbolType().symbol(); if (PRIMITIVE_TYPES_BY_WRAPPER.containsKey(newClassTree.symbolType().fullyQualifiedName())) { return classSymbol; } return null; }
private static boolean parentClassImplementsEquals(Symbol.TypeSymbol symbol) { Type superClass = symbol.superClass(); while (superClass != null && superClass.symbol().isTypeSymbol()) { Symbol.TypeSymbol superClassSymbol = superClass.symbol(); if (!superClass.is(JAVA_LANG_OBJECT) && hasEqualsMethod(superClassSymbol)) { return true; } superClass = superClassSymbol.superClass(); } return false; }
@Override public void visitNewClass(NewClassTree tree) { super.visitNewClass(tree); checkSymbol(tree.symbolType().symbol()); }
private void checkSuperType(ClassTree tree, @Nullable Type superType) { if (superType != null && superType.symbol().name().equals(tree.symbol().name())) { String classOrInterface = tree.is(Tree.Kind.CLASS) ? "class" : "interface"; reportIssue(tree.simpleName(), "Rename this " + classOrInterface + "."); } }
private static Symbol.TypeSymbol wrapperClassSymbol(NewClassTree newClassTree) { Symbol.TypeSymbol classSymbol = newClassTree.symbolType().symbol(); if (PRIMITIVE_TYPES_BY_WRAPPER.containsKey(newClassTree.symbolType().fullyQualifiedName()) && !newClassTree.arguments().isEmpty()) { return classSymbol; } return null; }
private static boolean isSpringWebHandler(AnnotationTree annotationTree) { Type annotationType = annotationTree.annotationType().symbolType(); return annotationType.is(REQUEST_MAPPING_ANNOTATION) || annotationType.symbol().metadata().isAnnotatedWith(REQUEST_MAPPING_ANNOTATION); } }
@Override public void visitIdentifier(IdentifierTree tree) { Type type = tree.symbolType(); if (type instanceof MethodJavaType) { type = ((MethodJavaType) type).resultType(); } if (!sameErasure(type) && type.isSubtypeOf(classType.erasure())) { reportIssue(tree, String.format("Remove this reference to \"%s\".", type.symbol().name())); } }
private boolean checkStaticMethod(Tree reportTree, Symbol.MethodSymbol methodSymbol, Type superClass) { for (Symbol methodWithSameName : superClass.symbol().lookupSymbols(methodSymbol.name())) { if (methodWithSameName.isMethodSymbol() && hideStaticMethod(methodSymbol, superClass, methodWithSameName)) { reportIssue(reportTree, "Rename this method or make it \"static\"."); return true; } } return false; }
private static void addConstantValue(AnnotationTree tree, AnnotationInstanceResolve annotationInstance) { Collection<Symbol> scopeSymbols = tree.annotationType().symbolType().symbol().memberSymbols(); for (ExpressionTree expressionTree : tree.arguments()) { String name = ""; for (Symbol scopeSymbol : scopeSymbols) { if(scopeSymbol.isMethodSymbol()) { name = scopeSymbol.name(); break; } } annotationInstance.addValue(new AnnotationValueResolve(name, expressionTree)); } }
private static boolean isEnclosingClassFinal(ExpressionTree expressionTree) { if (expressionTree.is(IDENTIFIER)) { Tree parent = expressionTree.parent(); while (!parent.is(METHOD, CONSTRUCTOR)) { parent = parent.parent(); } return ((MethodTree) parent).symbol().owner().isFinal(); } return ((MemberSelectExpressionTree) expressionTree).expression().symbolType().symbol().isFinal(); } }