private boolean isAbstract(ClassTree tree) { for (Modifier modifier : tree.modifiers().modifiers()) { if (modifier == Modifier.ABSTRACT) { return true; } } return false; }
private static boolean classHasNoAutoValueOrImmutableAnnotation(ClassTree tree) { return tree.modifiers().annotations().stream() .map(AnnotationTree::annotationType) .map(TypeTree::symbolType) .noneMatch(type -> type.is("com.google.auto.value.AutoValue") || type.is("org.immutables.value.Value$Immutable")); } }
private static boolean classHasNoAutoValueOrImmutableAnnotation(ClassTree tree) { return tree.modifiers().annotations().stream() .map(AnnotationTree::annotationType) .map(TypeTree::symbolType) .noneMatch(type -> type.is("com.google.auto.value.AutoValue") || type.is("org.immutables.value.Value$Immutable")); } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } ((ClassTree) tree).modifiers().annotations().stream() .filter(SpringAutoConfigurationCheck::isAutoConfiguration) .filter(annotation -> !hasExclude(annotation.arguments())) .forEach(annotation -> reportIssue(annotation, "Exclude from the auto-configuration mechanism the beans you don't need.")); }
private void checkScopeAnnotation(ClassTree tree) { tree.modifiers().annotations().stream() .filter(a -> a.annotationType().symbolType().fullyQualifiedName().equals(SCOPE_ANNOTATION_FQN)) .forEach(a -> reportIssue(a, "Remove this \"@Scope\" annotation.")); }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } ClassTree classTree = (ClassTree) tree; if (ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.FINAL)) { classTree.members().forEach(this::checkMember); } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } ClassTree classTree = (ClassTree) tree; if (ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.FINAL)) { classTree.members().forEach(this::checkMember); } }
@Override public void visitNode(Tree tree) { ClassTree classTree = (ClassTree) tree; findRequestMappingAnnotation(classTree.modifiers()) .flatMap(SpringRequestMappingMethodCheck::findRequestMethod) .filter(SpringRequestMappingMethodCheck::hasMoreThanOneValue) .ifPresent(assignment -> reportIssue(assignment.expression(), "Consider narrowing this list of methods to one.")); classTree.members().stream() .filter(member -> member.is(Tree.Kind.METHOD)) .forEach(member -> checkMethod((MethodTree) member, classTree.symbol())); }
@Override public void visitClass(ClassTree tree) { handleSuppressWarning(tree.modifiers().annotations(), tree); super.visitClass(tree); }
@Override public void visitNode(Tree tree) { ClassTree classTree = (ClassTree) tree; ModifierKeywordTree staticKeyword = ModifiersUtils.getModifier(classTree.modifiers(), Modifier.STATIC); if (staticKeyword != null) { List<JavaFileScannerContext.Location> secondary = Collections.singletonList(new JavaFileScannerContext.Location("", classTree.declarationKeyword())); reportIssue(staticKeyword, "Remove this redundant \"static\" qualifier.", secondary, null); } } }
private void handleClassTree(ClassTree tree) { tree.superInterfaces().stream() .filter(superInterface -> INTERFACES.stream().anyMatch(superInterface.symbolType()::is)) .forEach(this::reportIssue); TypeTree superClass = tree.superClass(); if (superClass != null && superClass.symbolType().is(GLOBAL_METHOD_SECURITY_CONFIGURATION)) { reportIssue(superClass); } checkAnnotations(tree.modifiers(), JSR_250_ANNOTATIONS); }
private int computeClassFlags(ClassTree tree) { int flags = computeFlags(tree.modifiers(), tree); if (tree.is(Tree.Kind.INTERFACE)) { flags |= Flags.INTERFACE; }else if (tree.is(Tree.Kind.ENUM)) { flags |= Flags.ENUM; }else if (tree.is(Tree.Kind.ANNOTATION_TYPE)) { flags |= Flags.INTERFACE | Flags.ANNOTATION; } return flags; }
@Override public void visitNode(Tree tree) { ClassTree classTree = (ClassTree) tree; if (!ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.ABSTRACT)) { List<Tree> members = classTree.members(); checkMethods(members); checkSingleNoArgPublicConstructor(members); } }
@Override public void visitNode(Tree tree) { ClassTree classTree = (ClassTree) tree; if (!ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.ABSTRACT)) { List<Tree> members = classTree.members(); checkMethods(members); checkSingleNoArgPublicConstructor(members); } }
private static ModifiersTree getModifierTrees(Tree tree) { ModifiersTree modifiersTree = null; if (tree.is(CLASS_KINDS)) { modifiersTree = ((ClassTree) tree).modifiers(); } else if (tree.is(METHOD_KINDS)) { modifiersTree = ((MethodTree) tree).modifiers(); } else if (tree.is(Kind.VARIABLE)) { modifiersTree = ((VariableTree) tree).modifiers(); } return modifiersTree; }
private static ModifiersTree getModifierTrees(Tree tree) { ModifiersTree modifiersTree = null; if (tree.is(CLASS_KINDS)) { modifiersTree = ((ClassTree) tree).modifiers(); } else if (tree.is(METHOD_KINDS)) { modifiersTree = ((MethodTree) tree).modifiers(); } else if (tree.is(Kind.VARIABLE)) { modifiersTree = ((VariableTree) tree).modifiers(); } return modifiersTree; }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } ClassTree classTree = (ClassTree) tree; if (hasOnlyPrivateConstructors(classTree) && !isExtended(classTree) && !ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.FINAL)) { reportIssue(classTree.simpleName(), "Make this class \"final\" or add a public constructor."); } }
@Override public void visitClass(ClassTree tree) { scan(tree.modifiers()); scan(tree.typeParameters()); scan(tree.superClass()); scan(tree.superInterfaces()); scan(tree.members()); }
@Override public void visitClass(ClassTree tree) { scan(tree.modifiers()); scan(tree.simpleName()); scan(tree.typeParameters()); scan(tree.superClass()); scan(tree.superInterfaces()); scan(tree.members()); }