Skip to content

Commit 6788e93

Browse files
committed
SONARJAVA-1285 Drop multiple issues per line support
1 parent 74db83b commit 6788e93

10 files changed

Lines changed: 16 additions & 38 deletions

File tree

java-checks-testkit/src/main/java/org/sonar/java/checks/verifier/JavaCheckVerifier.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,8 @@ private void collectExpectedIssues(String comment, int line) {
181181
final int endIndex = cleanedComment.indexOf(' ');
182182
if (endIndex == -1) {
183183
lineAdjustment = Integer.parseInt(cleanedComment.substring(2));
184-
cleanedComment = "";
185184
} else {
186185
lineAdjustment = Integer.parseInt(cleanedComment.substring(2, endIndex));
187-
cleanedComment = cleanedComment.substring(endIndex + 1).trim();
188186
}
189187
if (firstChar == '+') {
190188
expectedLine += lineAdjustment;
@@ -194,11 +192,7 @@ private void collectExpectedIssues(String comment, int line) {
194192
throw Fail.fail("Use only '@+N' or '@-N' to shifts messages.");
195193
}
196194
}
197-
cleanedComment = StringUtils.trim(cleanedComment);
198-
int times = StringUtils.isEmpty(cleanedComment) ? 1 : Integer.parseInt(cleanedComment);
199-
for (int i = 0; i < times; i++) {
200-
expected.put(expectedLine, expectedMessage);
201-
}
195+
expected.put(expectedLine, expectedMessage);
202196
}
203197
}
204198

java-checks-testkit/src/test/files/JavaCheckVerifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ void foo() { // test method
66
// Noncompliant@+1 {{message2}}
77
int j;
88
int k;
9-
// Noncompliant@-1 2 {{message3}}
10-
int l; // Noncompliant 2 {{message4}}
9+
// Noncompliant@-1 {{message3}}
10+
int l; // Noncompliant {{message4}}
1111
int m; // Noncompliant
1212
}
1313
}

java-checks-testkit/src/test/java/org/sonar/java/checks/verifier/JavaCheckVerifierTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ private FakeVisitor withDefaultIssues() {
183183
.withIssue(3, "message1")
184184
.withIssue(7, "message2")
185185
.withIssue(8, "message3")
186-
.withIssue(8, "message3")
187-
.withIssue(10, "message4")
188186
.withIssue(10, "message4")
189187
.withIssue(11, "no message");
190188
}

java-checks/src/test/files/JavaCheckVerifier.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

java-checks/src/test/files/checks/NullPointerCheck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ public void testDoWhileLoop(boolean condition) {
275275

276276
public void testForLoop() {
277277
Object object = null;
278-
for(; object.hashCode() != 0; object.hashCode()) { // Noncompliant 2 {{NullPointerException might be thrown as 'object' is nullable here}}
278+
for(; object.hashCode() != 0; // Noncompliant {{NullPointerException might be thrown as 'object' is nullable here}}
279+
object.hashCode()) { // Noncompliant {{NullPointerException might be thrown as 'object' is nullable here}}
279280
object.hashCode(); // False negative
280281
object = null;
281282
}

java-checks/src/test/files/checks/PrintfCheck.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ void foo(){
4242
String.format("%08d%n", 1);
4343
GregorianCalendar gc;
4444
String.format("Duke's Birthday year is %tH", gc);
45-
String.format("Duke's Birthday year is %t", loc); // Noncompliant 2
45+
// Noncompliant@+1
46+
String.format("Duke's Birthday year is %t", loc); // Noncompliant
4647

4748
pr.format("string without arguments"); // Noncompliant {{String contains no format specifiers.}}
4849
pr.format(loc, "string without arguments"); // Noncompliant {{String contains no format specifiers.}}
@@ -74,4 +75,4 @@ void foo(){
7475
String.format("%0$s", "tmp"); // Noncompliant {{Arguments are numbered starting from 1.}}
7576

7677
}
77-
}
78+
}

java-checks/src/test/files/checks/SelectorMethodArgumentCheck.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public void attempt(String name, int size, boolean isNice) { // Compliant
3434
}
3535

3636
abstract class B {
37-
public int foo(int a, boolean b, boolean c) { // Noncompliant 2
37+
// Noncompliant@+1
38+
public int foo(int a, boolean b, boolean c) { // Noncompliant
3839
if (b) {
3940
} else {
4041
}
@@ -76,4 +77,4 @@ private int hal(int a, boolean b) { // Compliant - rule only check for public me
7677
public int lap(int a, boolean b) { // Compliant
7778
return b && false ? a+1 : a-1;
7879
}
79-
}
80+
}

java-checks/src/test/files/checks/UndocumentedApi.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ class FooPackage { // Compliant - non public
157157
/** Documented.
158158
*/
159159
public class Foo { // Compliant
160+
// Noncompliant@+3
160161
/** foo.
161162
*/
162-
public int foo(int a, int b, int c) { // Noncompliant 2
163+
public int foo(int a, int b, int c) { // Noncompliant
163164
return 0;
164165
}
165166

@@ -291,4 +292,4 @@ public int compare(String o1, String o2) {
291292
}
292293
};
293294
}
294-
}
295+
}

java-checks/src/test/files/checks/UselessParenthesesCheck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ void foo() {
2222
tab[(1+2)]; // Noncompliant
2323
tab[(1+2)/2];
2424
A a = new A((1/3)); // Noncompliant
25-
return (((x & 0x0000FFFF)) | y); // Noncompliant 2
25+
return (( // Noncompliant
26+
(x & 0x0000FFFF)) | y); // Noncompliant
2627
getContentSpec(((int[])contentSpec.value)[0], contentSpec);
2728

2829
this.a = b; // Compliant

java-checks/src/test/java/org/sonar/java/checks/PrintfCheckTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@
1919
*/
2020
package org.sonar.java.checks;
2121

22-
import org.junit.Rule;
2322
import org.junit.Test;
2423
import org.sonar.java.checks.verifier.JavaCheckVerifier;
25-
import org.sonar.squidbridge.checks.CheckMessagesVerifierRule;
2624

2725
public class PrintfCheckTest {
2826

29-
@Rule
30-
public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
31-
3227
@Test
3328
public void detected() {
3429
JavaCheckVerifier.verify("src/test/files/checks/PrintfCheck.java", new PrintfCheck());
35-
;
3630
}
3731
}

0 commit comments

Comments
 (0)