[java] Fix DontCallSuperVisitWhenUsingRuleChain issues
This commit is contained in:
11 files changed
+32
-32
No files matched your search
+1
-1
@@ -27,6 +27,6 @@ public class JUnitTestsShouldIncludeAssertRule extends AbstractJavaRulechainRule
|
||||
.none(TestFrameworksUtil::isProbableAssertCall)) {
|
||||
addViolation(data, method);
|
||||
}
|
||||
return super.visit(method, data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class UnusedFormalParameterRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTConstructorDeclaration node, Object data) {
|
||||
check(node, data);
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
-8
@@ -55,7 +55,8 @@ public class CommentDefaultAccessModifierRule extends AbstractJavaRulechainRule
|
||||
private final Set<Integer> interestingLineNumberComments = new HashSet<>();
|
||||
|
||||
public CommentDefaultAccessModifierRule() {
|
||||
super(ASTCompilationUnit.class, ASTMethodDeclaration.class, ASTAnyTypeDeclaration.class, ASTConstructorDeclaration.class, ASTFieldDeclaration.class);
|
||||
super(ASTCompilationUnit.class, ASTMethodDeclaration.class, ASTAnyTypeDeclaration.class,
|
||||
ASTConstructorDeclaration.class, ASTFieldDeclaration.class);
|
||||
definePropertyDescriptor(IGNORED_ANNOTS);
|
||||
definePropertyDescriptor(REGEX_DESCRIPTOR);
|
||||
definePropertyDescriptor(TOP_LEVEL_TYPES);
|
||||
@@ -69,7 +70,7 @@ public class CommentDefaultAccessModifierRule extends AbstractJavaRulechainRule
|
||||
interestingLineNumberComments.add(comment.getBeginLine());
|
||||
}
|
||||
}
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,7 +78,7 @@ public class CommentDefaultAccessModifierRule extends AbstractJavaRulechainRule
|
||||
if (shouldReport(decl)) {
|
||||
report((RuleContext) data, decl, "method", PrettyPrintingUtil.displaySignature(decl));
|
||||
}
|
||||
return super.visit(decl, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,7 +86,7 @@ public class CommentDefaultAccessModifierRule extends AbstractJavaRulechainRule
|
||||
if (shouldReport(decl)) {
|
||||
report((RuleContext) data, decl, "field", decl.getVarIds().firstOrThrow().getName());
|
||||
}
|
||||
return super.visit(decl, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,7 +94,7 @@ public class CommentDefaultAccessModifierRule extends AbstractJavaRulechainRule
|
||||
if (!decl.isNested() && shouldReportTypeDeclaration(decl)) { // check for top-level annotation declarations
|
||||
report((RuleContext) data, decl, "top-level annotation", decl.getSimpleName());
|
||||
}
|
||||
return super.visit(decl, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,7 +102,7 @@ public class CommentDefaultAccessModifierRule extends AbstractJavaRulechainRule
|
||||
if (!decl.isNested() && shouldReportTypeDeclaration(decl)) { // check for top-level enums
|
||||
report((RuleContext) data, decl, "top-level enum", decl.getSimpleName());
|
||||
}
|
||||
return super.visit(decl, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,7 +112,7 @@ public class CommentDefaultAccessModifierRule extends AbstractJavaRulechainRule
|
||||
} else if (!decl.isNested() && shouldReportTypeDeclaration(decl)) { // and for top-level ones
|
||||
report((RuleContext) data, decl, "top-level class", decl.getSimpleName());
|
||||
}
|
||||
return super.visit(decl, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,7 +120,7 @@ public class CommentDefaultAccessModifierRule extends AbstractJavaRulechainRule
|
||||
if (shouldReport(decl)) {
|
||||
report((RuleContext) data, decl, "constructor", PrettyPrintingUtil.displaySignature(decl));
|
||||
}
|
||||
return super.visit(decl, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
private void report(RuleContext data, AccessNode decl, String kind, String description) {
|
||||
|
||||
+4
-3
@@ -52,7 +52,8 @@ import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
*/
|
||||
public class ConfusingTernaryRule extends AbstractJavaRulechainRule {
|
||||
|
||||
private static final PropertyDescriptor<Boolean> IGNORE_ELSE_IF = booleanProperty("ignoreElseIf").desc("Ignore conditions with an else-if case").defaultValue(false).build();
|
||||
private static final PropertyDescriptor<Boolean> IGNORE_ELSE_IF = booleanProperty("ignoreElseIf")
|
||||
.desc("Ignore conditions with an else-if case").defaultValue(false).build();
|
||||
|
||||
public ConfusingTernaryRule() {
|
||||
super(ASTIfStatement.class, ASTConditionalExpression.class);
|
||||
@@ -70,7 +71,7 @@ public class ConfusingTernaryRule extends AbstractJavaRulechainRule {
|
||||
addViolation(data, node);
|
||||
}
|
||||
}
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,7 +80,7 @@ public class ConfusingTernaryRule extends AbstractJavaRulechainRule {
|
||||
if (isMatch(node.getCondition())) {
|
||||
addViolation(data, node);
|
||||
}
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
// recursive!
|
||||
|
||||
+1
-2
@@ -96,8 +96,7 @@ public class IdenticalCatchBranchesRule extends AbstractJavaRulechainRule {
|
||||
}
|
||||
}
|
||||
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+2
-2
@@ -41,7 +41,7 @@ public class MethodNamingConventionsRule extends AbstractNamingConventionRule<AS
|
||||
public Object visit(ASTMethodDeclaration node, Object data) {
|
||||
|
||||
if (node.isOverridden()) {
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
if (node.hasModifiers(JModifier.NATIVE)) {
|
||||
@@ -58,7 +58,7 @@ public class MethodNamingConventionsRule extends AbstractNamingConventionRule<AS
|
||||
checkMatches(node, instanceRegex, data);
|
||||
}
|
||||
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -99,13 +99,13 @@ public class CyclomaticComplexityRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public final Object visit(ASTMethodDeclaration node, Object data) {
|
||||
visitMethodLike(node, data);
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object visit(ASTConstructorDeclaration node, Object data) {
|
||||
visitMethodLike(node, data);
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
private void visitMethodLike(ASTMethodOrConstructorDeclaration node, Object data) {
|
||||
|
||||
@@ -50,15 +50,13 @@ public class GodClassRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
||||
if (!MetricsUtil.supportsAll(node, WEIGHED_METHOD_COUNT, TIGHT_CLASS_COHESION, ACCESS_TO_FOREIGN_DATA)) {
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
int wmc = MetricsUtil.computeMetric(WEIGHED_METHOD_COUNT, node);
|
||||
double tcc = MetricsUtil.computeMetric(TIGHT_CLASS_COHESION, node);
|
||||
int atfd = MetricsUtil.computeMetric(ACCESS_TO_FOREIGN_DATA, node);
|
||||
|
||||
super.visit(node, data);
|
||||
|
||||
if (wmc >= WMC_VERY_HIGH && atfd > FEW_ATFD_THRESHOLD && tcc < TCC_THRESHOLD) {
|
||||
|
||||
addViolation(data, node, new Object[] {wmc,
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public class UselessOverridingMethodRule extends AbstractJavaRulechainRule {
|
||||
ASTStatement statement = ASTList.singleOrNull(node.getBody());
|
||||
// Only process functions with one statement
|
||||
if (statement == null) {
|
||||
return super.visit(node, data);
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((statement instanceof ASTExpressionStatement || statement instanceof ASTReturnStatement)
|
||||
|
||||
+8
-7
@@ -21,6 +21,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTEnumDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.AccessNode.Visibility;
|
||||
import net.sourceforge.pmd.lang.java.ast.JavaNode;
|
||||
import net.sourceforge.pmd.lang.java.ast.JavadocCommentOwner;
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
|
||||
@@ -145,14 +146,14 @@ public class CommentRequiredRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTClassOrInterfaceDeclaration decl, Object data) {
|
||||
checkCommentMeetsRequirement(data, decl, CLASS_CMT_REQUIREMENT_DESCRIPTOR);
|
||||
return super.visit(decl, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object visit(ASTConstructorDeclaration decl, Object data) {
|
||||
checkMethodOrConstructorComment(decl, data);
|
||||
return super.visit(decl, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -165,14 +166,14 @@ public class CommentRequiredRule extends AbstractJavaRulechainRule {
|
||||
} else {
|
||||
checkMethodOrConstructorComment(decl, data);
|
||||
}
|
||||
return super.visit(decl, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
private void checkMethodOrConstructorComment(ASTMethodOrConstructorDeclaration decl, Object data) {
|
||||
if (decl.isPublic()) {
|
||||
if (decl.getVisibility() == Visibility.V_PUBLIC) {
|
||||
checkCommentMeetsRequirement(data, decl, PUB_METHOD_CMT_REQUIREMENT_DESCRIPTOR);
|
||||
} else if (decl.isProtected()) {
|
||||
} else if (decl.getVisibility() == Visibility.V_PROTECTED) {
|
||||
checkCommentMeetsRequirement(data, decl, PROT_METHOD_CMT_REQUIREMENT_DESCRIPTOR);
|
||||
}
|
||||
}
|
||||
@@ -188,14 +189,14 @@ public class CommentRequiredRule extends AbstractJavaRulechainRule {
|
||||
checkCommentMeetsRequirement(data, decl, FIELD_CMT_REQUIREMENT_DESCRIPTOR);
|
||||
}
|
||||
|
||||
return super.visit(decl, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object visit(ASTEnumDeclaration decl, Object data) {
|
||||
checkCommentMeetsRequirement(data, decl, ENUM_CMT_REQUIREMENT_DESCRIPTOR);
|
||||
return super.visit(decl, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
private boolean allCommentsAreIgnored() {
|
||||
|
||||
+2
-2
@@ -85,7 +85,7 @@ public class DoubleCheckedLockingRule extends AbstractJavaRule {
|
||||
// if the return variable is local and only written with the volatile
|
||||
// field, then it's ok, too
|
||||
if (isLocalOnlyStoredWithVolatileField(node, returnVariable)) {
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
List<ASTIfStatement> isl = node.findDescendantsOfType(ASTIfStatement.class);
|
||||
@@ -107,7 +107,7 @@ public class DoubleCheckedLockingRule extends AbstractJavaRule {
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
private boolean isLocalOnlyStoredWithVolatileField(ASTMethodDeclaration method, JVariableSymbol local) {
|
||||
|
||||
Reference in new issue
Block a user