Skip to content

Commit 2454088

Browse files
authored
SONARJAVA-6028 fix FP for rule S1120 raising on compact source files (#5433)
1 parent 30221df commit 2454088

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1-
// SONARJAVA-6028: FPs ahead. Only the line with "Too much." should be noncompliant.
2-
3-
void main() { // Noncompliant
4-
System.out.println("Just right."); // Noncompliant
1+
void main() {
2+
System.out.println("Just right.");
53
if (true) {
64
System.out.println("Too much."); // Noncompliant
75
}
86
}
97

10-
class MyClass { // Noncompliant
8+
class MyClass {
9+
void myMethod() {
10+
System.err.println("Error message");
11+
}
12+
13+
static private class MyNestedClass {
14+
private final static int VALUE = 42;
15+
public float pi = 3.14f;
16+
public String badlyIndentedField = "Oops"; // Noncompliant
17+
public String secondBadlyIndentedField = "Oops x 2"; // Compliant, raised on previous line
18+
19+
20+
void anotherMethod() {
21+
System.out.println("Nested class output");
22+
}
23+
}
1124
}
25+
26+
int i = 0;
27+
public String badlyIndentedField = "Oops"; // Noncompliant
28+
public String secondBadlyIndentedField = "Oops x 2"; // Compliant, raised on previous line
29+
int j = 0;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public void visitClass(ClassTree tree) {
8282
excludeIssueAtLine = LineUtils.startLine(tree.openBraceToken());
8383
expectedLevel = Position.startOf(tree.closeBraceToken()).columnOffset();
8484
}
85-
newBlock();
85+
if (!tree.is(Kind.IMPLICIT_CLASS)) {
86+
newBlock();
87+
}
8688
checkIndentation(tree.members());
8789
super.visitClass(tree);
8890
leaveNode(tree);

0 commit comments

Comments
 (0)