Skip to content

Commit f0b6d55

Browse files
committed
Migrate some rules to precise issue location
1 parent ca05e5a commit f0b6d55

97 files changed

Lines changed: 198 additions & 164 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

java-checks/src/main/java/org/sonar/java/checks/AssertionsCompletenessCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void visitMethodInvocation(MethodInvocationTree mit) {
113113

114114
private boolean incompleteAssertion(MethodInvocationTree mit) {
115115
if (((FEST_LIKE_ASSERT_THAT.anyMatch(mit) && (mit.arguments().size() == 1)) || MOCKITO_VERIFY.matches(mit)) && !Boolean.TRUE.equals(chainedToAnyMethodButFestExclusions)) {
116-
context.addIssue(mit, this, "Complete the assertion.");
116+
context.reportIssue(this, mit.methodSelect(), "Complete the assertion.");
117117
return true;
118118
}
119119
return false;

java-checks/src/main/java/org/sonar/java/checks/BadAbstractClassName_S00118_Check.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.sonar.plugins.java.api.JavaFileScannerContext;
3030
import org.sonar.plugins.java.api.tree.BaseTreeVisitor;
3131
import org.sonar.plugins.java.api.tree.ClassTree;
32+
import org.sonar.plugins.java.api.tree.IdentifierTree;
3233
import org.sonar.plugins.java.api.tree.Modifier;
3334
import org.sonar.plugins.java.api.tree.Tree;
3435
import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
@@ -67,14 +68,15 @@ public void scanFile(JavaFileScannerContext context) {
6768

6869
@Override
6970
public void visitClass(ClassTree tree) {
70-
if (tree.is(Tree.Kind.CLASS) && tree.simpleName() != null) {
71-
if (pattern.matcher(tree.simpleName().name()).matches()) {
71+
IdentifierTree simpleName = tree.simpleName();
72+
if (tree.is(Tree.Kind.CLASS) && simpleName != null) {
73+
if (pattern.matcher(simpleName.name()).matches()) {
7274
if (!isAbstract(tree)) {
73-
context.addIssue(tree, this, "Make this class abstract or rename it, since it matches the regular expression '" + format + "'.");
75+
context.reportIssue(this, simpleName, "Make this class abstract or rename it, since it matches the regular expression '" + format + "'.");
7476
}
7577
} else {
7678
if (isAbstract(tree)) {
77-
context.addIssue(tree, this, "Rename this abstract class name to match the regular expression '" + format + "'.");
79+
context.reportIssue(this, simpleName, "Rename this abstract class name to match the regular expression '" + format + "'.");
7880
}
7981
}
8082
}

java-checks/src/main/java/org/sonar/java/checks/BadClassName_S00101_Check.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void scanFile(JavaFileScannerContext context) {
6868
@Override
6969
public void visitClass(ClassTree tree) {
7070
if (tree.is(Tree.Kind.CLASS) && tree.simpleName() != null && !pattern.matcher(tree.simpleName().name()).matches()) {
71-
context.addIssue(tree, this, "Rename this class name to match the regular expression '" + format + "'.");
71+
context.reportIssue(this, tree.simpleName(), "Rename this class name to match the regular expression '" + format + "'.");
7272
}
7373

7474
super.visitClass(tree);

java-checks/src/main/java/org/sonar/java/checks/BadConstantName_S00115_Check.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static boolean isConstantType(Type symbolType) {
9494

9595
private void checkName(VariableTree variableTree) {
9696
if (!SerializableContract.SERIAL_VERSION_UID_FIELD.equals(variableTree.simpleName().name()) && !pattern.matcher(variableTree.simpleName().name()).matches()) {
97-
addIssue(variableTree, "Rename this constant name to match the regular expression '" + format + "'.");
97+
reportIssue(variableTree.simpleName(), "Rename this constant name to match the regular expression '" + format + "'.");
9898
}
9999
}
100100

java-checks/src/main/java/org/sonar/java/checks/BadInterfaceName_S00114_Check.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void scanFile(JavaFileScannerContext context) {
6868
@Override
6969
public void visitClass(ClassTree tree) {
7070
if (tree.is(Tree.Kind.INTERFACE) && !pattern.matcher(tree.simpleName().name()).matches()) {
71-
context.addIssue(tree, this, "Rename this interface name to match the regular expression '" + format + "'.");
71+
context.reportIssue(this, tree.simpleName(), "Rename this interface name to match the regular expression '" + format + "'.");
7272
}
7373

7474
super.visitClass(tree);

java-checks/src/main/java/org/sonar/java/checks/BadLocalVariableName_S00117_Check.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void visitForEachStatement(ForEachStatement tree) {
9393
@Override
9494
public void visitVariable(VariableTree tree) {
9595
if (!pattern.matcher(tree.simpleName().name()).matches()) {
96-
context.addIssue(tree, this, "Rename this local variable name to match the regular expression '" + format + "'.");
96+
context.reportIssue(this, tree.simpleName(), "Rename this local variable name to match the regular expression '" + format + "'.");
9797
}
9898
super.visitVariable(tree);
9999
}

java-checks/src/main/java/org/sonar/java/checks/BadMethodName_S00100_Check.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void scanFile(JavaFileScannerContext context) {
7575
public void visitNode(Tree tree) {
7676
MethodTree methodTree = (MethodTree) tree;
7777
if (isNotOverriden(methodTree) && !pattern.matcher(methodTree.simpleName().name()).matches()) {
78-
addIssue(tree, "Rename this method name to match the regular expression '" + format + "'.");
78+
reportIssue(methodTree.simpleName(), "Rename this method name to match the regular expression '" + format + "'.");
7979
}
8080
}
8181

java-checks/src/main/java/org/sonar/java/checks/BadPackageName_S00120_Check.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void visitCompilationUnit(CompilationUnitTree tree) {
7070
if (tree.packageDeclaration() != null) {
7171
String name = PackageUtils.packageName(tree.packageDeclaration(), ".");
7272
if (!pattern.matcher(name).matches()) {
73-
context.addIssue(tree, this, "Rename this package name to match the regular expression '" + format + "'.");
73+
context.reportIssue(this, tree.packageDeclaration().packageName(), "Rename this package name to match the regular expression '" + format + "'.");
7474
}
7575
}
7676
}

java-checks/src/main/java/org/sonar/java/checks/BadTypeParameterName_S00119_Check.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.sonar.check.RuleProperty;
2727
import org.sonar.java.tag.Tag;
2828
import org.sonar.plugins.java.api.JavaFileScannerContext;
29+
import org.sonar.plugins.java.api.tree.IdentifierTree;
2930
import org.sonar.plugins.java.api.tree.Tree;
3031
import org.sonar.plugins.java.api.tree.Tree.Kind;
3132
import org.sonar.plugins.java.api.tree.TypeParameterTree;
@@ -68,9 +69,9 @@ public void scanFile(JavaFileScannerContext context) {
6869

6970
@Override
7071
public void visitNode(Tree tree) {
71-
String name = ((TypeParameterTree) tree).identifier().name();
72-
if (!pattern.matcher(name).matches()) {
73-
addIssue(tree, "Rename this generic name to match the regular expression '" + format + "'.");
72+
IdentifierTree identifier = ((TypeParameterTree) tree).identifier();
73+
if (!pattern.matcher(identifier.name()).matches()) {
74+
reportIssue(identifier, "Rename this generic name to match the regular expression '" + format + "'.");
7475
}
7576
}
7677
}

java-checks/src/main/java/org/sonar/java/checks/BooleanLiteralCheck.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@ public List<Kind> nodesToVisit() {
5252

5353
@Override
5454
public void visitNode(Tree tree) {
55-
String literal;
55+
LiteralTree literal;
5656
if(tree.is(Kind.LOGICAL_COMPLEMENT)) {
5757
literal = getBooleanLiteral(((UnaryExpressionTree)tree).expression());
5858
} else {
5959
literal = getBooleanLiteralOperands((BinaryExpressionTree)tree);
6060
}
6161
if(literal != null) {
62-
addIssue(tree, "Remove the literal \"" + literal + "\" boolean value.");
62+
reportIssue(literal, "Remove the literal \"" + literal.value() + "\" boolean value.");
6363
}
6464
}
6565

66-
private static String getBooleanLiteral(Tree tree) {
67-
String result = null;
66+
private static LiteralTree getBooleanLiteral(Tree tree) {
67+
LiteralTree result = null;
6868
if (tree.is(Kind.BOOLEAN_LITERAL)) {
69-
result = ((LiteralTree) tree).value();
69+
result = (LiteralTree) tree;
7070
}
7171
return result;
7272
}
7373

74-
private static String getBooleanLiteralOperands(BinaryExpressionTree tree) {
75-
String result = getBooleanLiteral(tree.leftOperand());
74+
private static LiteralTree getBooleanLiteralOperands(BinaryExpressionTree tree) {
75+
LiteralTree result = getBooleanLiteral(tree.leftOperand());
7676
if (result == null) {
7777
result = getBooleanLiteral(tree.rightOperand());
7878
}

0 commit comments

Comments
 (0)