@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); } } }
@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); } } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } ClassTree classTree = (ClassTree) tree; List<Tree> methods = classTree.members().stream() .filter(member -> member.is(Tree.Kind.METHOD, Tree.Kind.CONSTRUCTOR) && (countNonPublic || ((MethodTree) member).symbol().isPublic())) .collect(Collectors.toList()); if(shouldNotReportIssue(classTree, methods)) { return; } List<JavaFileScannerContext.Location> secondary = methods.stream() .map(element -> new JavaFileScannerContext.Location("Method + 1", element)) .collect(Collectors.toList()); String classDescription; if (classTree.simpleName() == null) { classDescription = "Anonymous class \"" + ((NewClassTree) classTree.parent()).identifier().symbolType().name() + "\""; } else { classDescription = classTree.declarationKeyword().text() + " \"" + classTree.simpleName() + "\""; } reportIssue( ExpressionsHelper.reportOnClassTree(classTree), String.format("%s has %d%s methods, which is greater than the %d authorized. Split it into smaller classes.", classDescription, methods.size(), countNonPublic ? "" : " public", maximumMethodThreshold), secondary, null); }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } ClassTree classTree = (ClassTree) tree; List<Tree> methods = classTree.members().stream() .filter(member -> member.is(Tree.Kind.METHOD, Tree.Kind.CONSTRUCTOR) && (countNonPublic || ((MethodTree) member).symbol().isPublic())) .collect(Collectors.toList()); if(shouldNotReportIssue(classTree, methods)) { return; } List<JavaFileScannerContext.Location> secondary = methods.stream() .map(element -> new JavaFileScannerContext.Location("Method + 1", element)) .collect(Collectors.toList()); String classDescription; if (classTree.simpleName() == null) { classDescription = "Anonymous class \"" + ((NewClassTree) classTree.parent()).identifier().symbolType().name() + "\""; } else { classDescription = classTree.declarationKeyword().text() + " \"" + classTree.simpleName() + "\""; } reportIssue( ExpressionsHelper.reportOnClassTree(classTree), String.format("%s has %d%s methods, which is greater than the %d authorized. Split it into smaller classes.", classDescription, methods.size(), countNonPublic ? "" : " public", maximumMethodThreshold), secondary, null); }
private void checkClassTree(ClassTree tree) { IdentifierTree simpleName = tree.simpleName(); if (simpleName != null && !ModifiersUtils.hasModifier(tree.modifiers(), Modifier.ABSTRACT) && isNotEJBAnnotated(tree.symbol())) { List<JavaFileScannerContext.Location> uninitializedVariables = new ArrayList<>(); for (Tree member : tree.members()) { if (member.is(Kind.CONSTRUCTOR)) { // there is a constructor, no need to check further return; } else if (member.is(Kind.VARIABLE) && requiresInitialization((VariableTree) member)) { uninitializedVariables.add(new JavaFileScannerContext.Location("Uninitialized field", member)); } } if (!uninitializedVariables.isEmpty()) { reportIssue(simpleName, "Add a constructor to the " + tree.declarationKeyword().text() + ", or provide default values.", uninitializedVariables, null); } } }
private void checkClassTree(ClassTree tree) { IdentifierTree simpleName = tree.simpleName(); if (simpleName != null && !ModifiersUtils.hasModifier(tree.modifiers(), Modifier.ABSTRACT) && isNotEJBAnnotated(tree.symbol())) { List<JavaFileScannerContext.Location> uninitializedVariables = new ArrayList<>(); for (Tree member : tree.members()) { if (member.is(Kind.CONSTRUCTOR)) { // there is a constructor, no need to check further return; } else if (member.is(Kind.VARIABLE) && requiresInitialization((VariableTree) member)) { uninitializedVariables.add(new JavaFileScannerContext.Location("Uninitialized field", member)); } } if (!uninitializedVariables.isEmpty()) { reportIssue(simpleName, "Add a constructor to the " + tree.declarationKeyword().text() + ", or provide default values.", uninitializedVariables, null); } } }