Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/org/checkstyle/autofix/recipe/UpperEll.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ private int computeLinePosition(J tree, J targetElement, Cursor cursor) {
}

private int computeColumnPosition(J tree, J targetElement, Cursor cursor) {
return computePosition(tree, targetElement, cursor, this::calculateColumnOffset);
return computePosition(tree, targetElement, cursor, out -> {
int column = calculateColumnOffset(out);
if (((J.Literal) targetElement).getValueSource().matches("^[+-].*")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some doubts for this regex match, it doesn't feel right and we may miss other edge cases. Let's rethink this when we get another use case this logic doesn't cover

column++;
}
return column;
});
}

private int calculateColumnOffset(String out) {
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/checkstyle/autofix/recipe/UpperEllTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ void complexLongLiterals() throws IOException, CheckstyleException {
void stringAndCommentTest() throws IOException, CheckstyleException {
testRecipe("upperell", "StringAndComments");
}

@Test
void symbolicLiteralTest() throws IOException, CheckstyleException {
testRecipe("upperell", "SymbolicLiterals");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ public class InputComplexLongLiterals {
private long multipleUnderscores = 1_234_567_890l;

private long maxLong = 9223372036854775807l;
private long minLong = -9223372036854775808l; //false negative
private long minLong = -9223372036854775808l;

private Long nullLong = null;
private Long simpleLong = 1234l;
private Long negativeLong = -5678l; //false negative
private Long negativeLong = -5678l;
private Long underscoreLong = 1_000_000l;
Long maxLongObject = 9223372036854775807l; //suppressed violation
Long minLongObject = -9223372036854775808l; //suppressed violation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ public class OutputComplexLongLiterals {
private long multipleUnderscores = 1_234_567_890L;

private long maxLong = 9223372036854775807L;
private long minLong = -9223372036854775808l; //false negative
private long minLong = -9223372036854775808L;

private Long nullLong = null;
private Long simpleLong = 1234L;
private Long negativeLong = -5678l; //false negative
private Long negativeLong = -5678L;
private Long underscoreLong = 1_000_000L;
Long maxLongObject = 9223372036854775807l; //suppressed violation
Long minLongObject = -9223372036854775808l; //suppressed violation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,23 @@
message="Use uppercase 'L' for long literals."
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
</file>

<file name="org/checkstyle/autofix/recipe/upperell/symbolicliterals/InputSymbolicLiterals.java">
<error line="4" column="29" severity="error"
message="Use uppercase 'L' for long literals."
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
<error line="5" column="34" severity="error"
message="Use uppercase 'L' for long literals."
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
<error line="6" column="15" severity="error"
message="Use uppercase 'L' for long literals."
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
<error line="7" column="16" severity="error"
message="Use uppercase 'L' for long literals."
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
<error line="8" column="22" severity="error"
message="Use uppercase 'L' for long literals."
source="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
</file>

</checkstyle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.checkstyle.autofix.recipe.upperell.symbolicliterals;

public class InputSymbolicLiterals {
private long minLong = -9223372036854775808l;
private Long negativeLong = -5678l;
long a = -0xAl;
long b = +-12l;
long c = +-(-(-(-4l)));;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.checkstyle.autofix.recipe.upperell.symbolicliterals;

public class OutputSymbolicLiterals {
private long minLong = -9223372036854775808L;
private Long negativeLong = -5678L;
long a = -0xAL;
long b = +-12L;
long c = +-(-(-(-4L)));;
}
Loading