Fix violations of UnnecessaryVarargsArrayCreation

This commit is contained in:
Clément Fournier
2024-04-21 13:31:27 +02:00
parent 34e0b217a2
commit 75e284075b
14 changed files with 34 additions and 42 deletions

View File

@ -75,7 +75,7 @@ public class CognitiveComplexityRule extends AbstractApexRule {
String.valueOf(classLevelThreshold),
};
asCtx(data).addViolation(node, messageParams);
asCtx(data).addViolation(node, (Object[]) messageParams);
}
}
return data;

View File

@ -78,7 +78,7 @@ public class CyclomaticComplexityRule extends AbstractApexRule {
" total",
classWmc + " (highest " + classHighest + ")", };
asCtx(data).addViolation(node, messageParams);
asCtx(data).addViolation(node, (Object[]) messageParams);
}
}
return data;

View File

@ -76,7 +76,7 @@ public class AccessorMethodGenerationRule extends AbstractJavaRulechainRule {
JavaNode node = sym.tryGetNode();
assert node != null : "Node should be in the same compilation unit";
if (reportedNodes.add(node)) {
ruleContext.addViolation(node, new String[] {stripPackageName(refExpr.getEnclosingType().getSymbol())});
ruleContext.addViolation(node, stripPackageName(refExpr.getEnclosingType().getSymbol()));
}
}
}

View File

@ -91,7 +91,7 @@ public class IdenticalCatchBranchesRule extends AbstractJavaRulechainRule {
// By convention, lower catch blocks are collapsed into the highest one
// The first node of the equivalence class is thus the block that should be transformed
for (int i = 1; i < identicalStmts.size(); i++) {
asCtx(data).addViolation(identicalStmts.get(i), new String[]{identicalBranchName, });
asCtx(data).addViolation(identicalStmts.get(i), identicalBranchName);
}
}
}

View File

@ -220,7 +220,7 @@ public class UnnecessaryImportRule extends AbstractJavaRule {
}
private void reportWithMessage(ASTImportDeclaration node, Object data, String message) {
asCtx(data).addViolationWithMessage(node, message, new String[] { PrettyPrintingUtil.prettyImport(node) });
asCtx(data).addViolationWithMessage(node, message, PrettyPrintingUtil.prettyImport(node));
}
@Override

View File

@ -54,12 +54,10 @@ public class UnnecessaryModifierRule extends AbstractJavaRulechainRule {
if (unnecessaryModifiers.isEmpty()) {
return;
}
asCtx(data).addViolation(node, new String[]{
formatUnnecessaryModifiers(unnecessaryModifiers),
PrettyPrintingUtil.getPrintableNodeKind(node),
PrettyPrintingUtil.getNodeName(node),
explanation.isEmpty() ? "" : ": " + explanation,
});
asCtx(data).addViolation(node, formatUnnecessaryModifiers(unnecessaryModifiers),
PrettyPrintingUtil.getPrintableNodeKind(node),
PrettyPrintingUtil.getNodeName(node),
explanation.isEmpty() ? "" : ": " + explanation);
}

View File

@ -85,7 +85,7 @@ public class UseDiamondOperatorRule extends AbstractJavaRulechainRule {
JavaNode reportNode = targs == null ? newTypeNode : targs;
String message = targs == null ? RAW_TYPE_MESSAGE : REPLACE_TYPE_ARGS_MESSAGE;
String replaceWith = produceSuggestedExprImage(ctorCall);
asCtx(data).addViolationWithMessage(reportNode, message, new String[] { replaceWith });
asCtx(data).addViolationWithMessage(reportNode, message, replaceWith);
}
return null;
}

View File

@ -56,10 +56,10 @@ public class CognitiveComplexityRule extends AbstractJavaRulechainRule {
int cognitive = MetricsUtil.computeMetric(COGNITIVE_COMPLEXITY, node);
final int reportLevel = getReportLevel();
if (cognitive >= reportLevel) {
asCtx(data).addViolation(node, new String[] { node instanceof ASTMethodDeclaration ? "method" : "constructor",
PrettyPrintingUtil.displaySignature(node),
String.valueOf(cognitive),
String.valueOf(reportLevel) });
asCtx(data).addViolation(node, node instanceof ASTMethodDeclaration ? "method" : "constructor",
PrettyPrintingUtil.displaySignature(node),
String.valueOf(cognitive),
String.valueOf(reportLevel));
}
return data;

View File

@ -89,7 +89,7 @@ public class CyclomaticComplexityRule extends AbstractJavaRulechainRule {
" total",
classWmc + " (highest " + classHighest + ")", };
asCtx(data).addViolation(node, messageParams);
asCtx(data).addViolation(node, (Object[]) messageParams);
}
}
return data;
@ -120,11 +120,7 @@ public class CyclomaticComplexityRule extends AbstractJavaRulechainRule {
String kindname = node instanceof ASTConstructorDeclaration ? "constructor" : "method";
asCtx(data).addViolation(node, new String[] {kindname,
opname,
"",
"" + cyclo, });
asCtx(data).addViolation(node, kindname, opname, "", "" + cyclo);
}
}
}

View File

@ -51,10 +51,10 @@ public class NPathComplexityRule extends AbstractJavaRulechainRule {
BigInteger npath = MetricsUtil.computeMetric(JavaMetrics.NPATH, node);
if (npath.compareTo(BigInteger.valueOf(reportLevel)) >= 0) {
asCtx(data).addViolation(node, new String[] {node instanceof ASTMethodDeclaration ? "method" : "constructor",
PrettyPrintingUtil.displaySignature(node),
String.valueOf(npath),
String.valueOf(reportLevel)});
asCtx(data).addViolation(node, node instanceof ASTMethodDeclaration ? "method" : "constructor",
PrettyPrintingUtil.displaySignature(node),
String.valueOf(npath),
String.valueOf(reportLevel));
}
return data;

View File

@ -115,9 +115,8 @@ public final class NcssCountRule extends AbstractJavaRulechainRule {
if (JavaMetrics.NCSS.supports(node)) {
int methodSize = MetricsUtil.computeMetric(JavaMetrics.NCSS, node, ncssOptions);
if (methodSize >= level) {
asCtx(data).addViolation(node, new String[] {
node instanceof ASTMethodDeclaration ? "method" : "constructor",
PrettyPrintingUtil.displaySignature(node), "" + methodSize, });
asCtx(data).addViolation(node, node instanceof ASTMethodDeclaration ? "method" : "constructor",
PrettyPrintingUtil.displaySignature(node), "" + methodSize);
}
}
}

View File

@ -258,8 +258,7 @@ public class ConsecutiveLiteralAppendsRule extends AbstractJavaRulechainRule {
private void checkForViolation(Object data) {
if (counter.isViolation()) {
assert counter.getReportNode() != null;
String[] param = { String.valueOf(counter.getCounter()) };
asCtx(data).addViolation(counter.getReportNode(), param);
asCtx(data).addViolation(counter.getReportNode(), String.valueOf(counter.getCounter()));
}
}

View File

@ -72,7 +72,7 @@ public class InsufficientStringBufferDeclarationRule extends AbstractJavaRulecha
}
public String[] getParamsForViolation() {
public Object[] getParamsForViolation() {
return new String[] { getTypeName(variable), String.valueOf(capacity), String.valueOf(anticipatedLength) };
}

View File

@ -210,8 +210,8 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
classEntry.getComplexityAverage(), classEntry.highestDecisionPoints);
if (showClassesComplexity) {
if (classEntry.getComplexityAverage() >= reportLevel || classEntry.highestDecisionPoints >= reportLevel) {
asCtx(data).addViolation(node, new String[] { "class", node.getImage(),
classEntry.getComplexityAverage() + " (Highest = " + classEntry.highestDecisionPoints + ')', });
asCtx(data).addViolation(node, "class", node.getImage(),
classEntry.getComplexityAverage() + " (Highest = " + classEntry.highestDecisionPoints + ')');
}
}
return data;
@ -227,8 +227,8 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
classEntry.highestDecisionPoints);
if (showClassesComplexity) {
if (classEntry.getComplexityAverage() >= reportLevel || classEntry.highestDecisionPoints >= reportLevel) {
asCtx(data).addViolation(node, new String[] { "class", node.getImage(),
classEntry.getComplexityAverage() + " (Highest = " + classEntry.highestDecisionPoints + ')', });
asCtx(data).addViolation(node, "class", node.getImage(),
classEntry.getComplexityAverage() + " (Highest = " + classEntry.highestDecisionPoints + ')');
}
}
return data;
@ -276,8 +276,8 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
ASTMethodDeclarator methodDeclarator = node.firstChild(ASTMethodDeclarator.class);
if (methodEntry.decisionPoints >= reportLevel) {
asCtx(data).addViolation(node,
new String[] { "method", methodDeclarator == null ? "" : methodDeclarator.getImage(),
String.valueOf(methodEntry.decisionPoints), });
"method", methodDeclarator == null ? "" : methodDeclarator.getImage(),
String.valueOf(methodEntry.decisionPoints));
}
}
return data;
@ -306,8 +306,8 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
ASTMethodDeclarator methodDeclarator = node.firstChild(ASTMethodDeclarator.class);
if (methodEntry.decisionPoints >= reportLevel) {
asCtx(data).addViolation(node,
new String[] { "method", methodDeclarator == null ? "" : methodDeclarator.getImage(),
String.valueOf(methodEntry.decisionPoints), });
"method", methodDeclarator == null ? "" : methodDeclarator.getImage(),
String.valueOf(methodEntry.decisionPoints));
}
}
return data;
@ -334,8 +334,8 @@ public class CyclomaticComplexityRule extends AbstractPLSQLRule {
ASTMethodDeclarator methodDeclarator = node.firstChild(ASTMethodDeclarator.class);
if (methodEntry.decisionPoints >= reportLevel) {
asCtx(data).addViolation(node,
new String[] { "method", methodDeclarator == null ? "" : methodDeclarator.getImage(),
String.valueOf(methodEntry.decisionPoints), });
"method", methodDeclarator == null ? "" : methodDeclarator.getImage(),
String.valueOf(methodEntry.decisionPoints));
}
}
return data;