Skip to content

Commit 7410102

Browse files
committed
SONARJAVA-1390 Enable precise issue location on S109
1 parent 5f1f5db commit 7410102

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void visitLiteral(LiteralTree tree) {
9595
// noop case not encountered
9696
}
9797
if (checked != null && !isExcluded(checked)) {
98-
context.addIssue(tree, this, "Assign this magic number " + tree.value() + " to a well-named constant, and use the constant instead.");
98+
context.reportIssue(this, tree, "Assign this magic number " + tree.value() + " to a well-named constant, and use the constant instead.");
9999
}
100100
}
101101
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ final class A {
1212
int b = 1;
1313
int c = -1;
1414

15-
int d = 2; // Noncompliant {{Assign this magic number 2 to a well-named constant, and use the constant instead.}}
16-
int e = 42; // Noncompliant {{Assign this magic number 42 to a well-named constant, and use the constant instead.}}
15+
int d = 2; // Noncompliant [[sc=11;ec=12]] {{Assign this magic number 2 to a well-named constant, and use the constant instead.}}
16+
int e = 42; // Noncompliant [[sc=11;ec=13]] {{Assign this magic number 42 to a well-named constant, and use the constant instead.}}
1717

18-
long aLong = 12L; // Noncompliant {{Assign this magic number 12L to a well-named constant, and use the constant instead.}}
19-
double aDouble = 12.3d; // Noncompliant {{Assign this magic number 12.3d to a well-named constant, and use the constant instead.}}
20-
float aFloat = 12.3F; // Noncompliant {{Assign this magic number 12.3F to a well-named constant, and use the constant instead.}}
18+
long aLong = 12L; // Noncompliant [[sc=16;ec=19]] {{Assign this magic number 12L to a well-named constant, and use the constant instead.}}
19+
double aDouble = 12.3d; // Noncompliant [[sc=20;ec=25]] {{Assign this magic number 12.3d to a well-named constant, and use the constant instead.}}
20+
float aFloat = 12.3F; // Noncompliant [[sc=18;ec=23]] {{Assign this magic number 12.3F to a well-named constant, and use the constant instead.}}
2121
String string = "string";
2222
String strDouble = "123.3d";
2323
boolean bool = true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class A {
1313
int c = -1;
1414

1515
int d = 2;
16-
int e = 42; // Noncompliant {{Assign this magic number 42 to a well-named constant, and use the constant instead.}}
16+
int e = 42; // Noncompliant [[sc=11;ec=13]] {{Assign this magic number 42 to a well-named constant, and use the constant instead.}}
1717

1818
long aLong = 12L; // Noncompliant {{Assign this magic number 12L to a well-named constant, and use the constant instead.}}
1919
double aDouble = 12.3d; // Noncompliant {{Assign this magic number 12.3d to a well-named constant, and use the constant instead.}}

0 commit comments

Comments
 (0)