Skip to content

Commit d48a7a6

Browse files
committed
Issue #55: updated computeColumnPosition
1 parent 6b118b8 commit d48a7a6

File tree

7 files changed

+53
-5
lines changed

7 files changed

+53
-5
lines changed

src/main/java/org/checkstyle/autofix/recipe/UpperEll.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ private int computeLinePosition(J tree, J targetElement, Cursor cursor) {
166166
}
167167

168168
private int computeColumnPosition(J tree, J targetElement, Cursor cursor) {
169-
return computePosition(tree, targetElement, cursor, this::calculateColumnOffset);
169+
return computePosition(tree, targetElement, cursor, out -> {
170+
int column = calculateColumnOffset(out);
171+
if (((J.Literal) targetElement).getValueSource().matches("^[+-].*")) {
172+
column++;
173+
}
174+
return column;
175+
});
170176
}
171177

172178
private int calculateColumnOffset(String out) {

src/test/java/org/checkstyle/autofix/recipe/UpperEllTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,9 @@ void complexLongLiterals() throws IOException, CheckstyleException {
5454
void stringAndCommentTest() throws IOException, CheckstyleException {
5555
testRecipe("upperell", "StringAndComments");
5656
}
57+
58+
@Test
59+
void symbolicLiteralTest() throws IOException, CheckstyleException {
60+
testRecipe("upperell", "SymbolicLiterals");
61+
}
5762
}

src/test/resources/org/checkstyle/autofix/recipe/upperell/complexlongliterals/InputComplexLongLiterals.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ public class InputComplexLongLiterals {
55
private long multipleUnderscores = 1_234_567_890l;
66

77
private long maxLong = 9223372036854775807l;
8-
private long minLong = -9223372036854775808l; //false negative
8+
private long minLong = -9223372036854775808l;
99

1010
private Long nullLong = null;
1111
private Long simpleLong = 1234l;
12-
private Long negativeLong = -5678l; //false negative
12+
private Long negativeLong = -5678l;
1313
private Long underscoreLong = 1_000_000l;
1414
Long maxLongObject = 9223372036854775807l; //suppressed violation
1515
Long minLongObject = -9223372036854775808l; //suppressed violation

src/test/resources/org/checkstyle/autofix/recipe/upperell/complexlongliterals/OutputComplexLongLiterals.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ public class OutputComplexLongLiterals {
55
private long multipleUnderscores = 1_234_567_890L;
66

77
private long maxLong = 9223372036854775807L;
8-
private long minLong = -9223372036854775808l; //false negative
8+
private long minLong = -9223372036854775808L;
99

1010
private Long nullLong = null;
1111
private Long simpleLong = 1234L;
12-
private Long negativeLong = -5678l; //false negative
12+
private Long negativeLong = -5678L;
1313
private Long underscoreLong = 1_000_000L;
1414
Long maxLongObject = 9223372036854775807l; //suppressed violation
1515
Long minLongObject = -9223372036854775808l; //suppressed violation

src/test/resources/org/checkstyle/autofix/recipe/upperell/report.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,23 @@
107107
message="Use uppercase 'L' for long literals."
108108
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
109109
</file>
110+
111+
<file name="org/checkstyle/autofix/recipe/upperell/symbolicliterals/InputSymbolicLiterals.java">
112+
<error line="4" column="29" severity="error"
113+
message="Use uppercase 'L' for long literals."
114+
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
115+
<error line="5" column="34" severity="error"
116+
message="Use uppercase 'L' for long literals."
117+
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
118+
<error line="6" column="15" severity="error"
119+
message="Use uppercase 'L' for long literals."
120+
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
121+
<error line="7" column="16" severity="error"
122+
message="Use uppercase 'L' for long literals."
123+
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
124+
<error line="8" column="22" severity="error"
125+
message="Use uppercase 'L' for long literals."
126+
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
127+
</file>
128+
110129
</checkstyle>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.checkstyle.autofix.recipe.upperell.symbolicliterals;
2+
3+
public class InputSymbolicLiterals {
4+
private long minLong = -9223372036854775808l;
5+
private Long negativeLong = -5678l;
6+
long a = -0xAl;
7+
long b = +-12l;
8+
long c = +-(-(-(-4l)));;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.checkstyle.autofix.recipe.upperell.symbolicliterals;
2+
3+
public class OutputSymbolicLiterals {
4+
private long minLong = -9223372036854775808L;
5+
private Long negativeLong = -5678L;
6+
long a = -0xAL;
7+
long b = +-12L;
8+
long c = +-(-(-(-4L)));;
9+
}

0 commit comments

Comments
 (0)