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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,23 @@ protected String getPackageLocation() {
}

protected void verify(String testCaseName) throws Exception {
verify(getCheckConfigurations(getInputFilePath(testCaseName)), testCaseName);

final String inputPath = getInputFilePath(testCaseName);
final String outputPath = getOutputFilePath(testCaseName);
final Configuration config = getCheckConfigurations(inputPath);
verifyOutputFile(outputPath, config);

final List<CheckstyleViolation> violations = runCheckstyle(inputPath, config);

verifyWithInlineConfigParser(getPath(inputPath), convertToExpectedMessages(violations));

final String beforeCode = readFile(getPath(inputPath));
final String expectedAfterCode = readFile(getPath(outputPath));
final CheckConfiguration checkConfig = ConfigurationLoader.mapConfiguration(config);
final Recipe mainRecipe = createRecipe(violations, checkConfig);
testRecipe(beforeCode, expectedAfterCode,
getPath(inputPath), new InputClassRenamer(),
mainRecipe, new RemoveViolationComments());
}

protected void verify(Configuration config, String testCaseName) throws Exception {
Expand All @@ -74,8 +90,7 @@ protected void verify(Configuration config, String testCaseName) throws Exceptio
final CheckConfiguration checkConfig = ConfigurationLoader.mapConfiguration(config);
final Recipe mainRecipe = createRecipe(violations, checkConfig);
testRecipe(beforeCode, expectedAfterCode,
getPath(inputPath), new InputClassRenamer(),
new RemoveViolationComments(), mainRecipe);
getPath(inputPath), new InputClassRenamer(), mainRecipe);
}

private List<CheckstyleViolation> runCheckstyle(String inputPath,
Expand Down Expand Up @@ -120,6 +135,17 @@ private void verifyOutputFile(String outputPath, Configuration config) throws Ex
}
}

private String[] convertToExpectedMessages(List<CheckstyleViolation> violations) {
return violations.stream()
.map(violation -> {
final String message;
message = violation.getLine() + ":"
+ violation.getColumn() + ": " + violation.getMessage();
return message;
})
.toArray(String[]::new);
}

private Configuration getCheckConfigurations(String inputPath) throws Exception {
final String configFilePath = getPath(inputPath);
final TestInputConfiguration testInputConfiguration =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,49 @@
package org.checkstyle.autofix.recipe.upperell.complexlongliterals;

public class InputComplexLongLiterals {
private long withUnderscores = 1_000_000l;
private long multipleUnderscores = 1_234_567_890l;
private long withUnderscores = 1_000_000l; // violation 'Should use uppercase 'L'.'
private long multipleUnderscores = 1_234_567_890l; // violation 'Should use uppercase 'L'.'

private long maxLong = 9223372036854775807l; //suppressed violation
private long minLong = -9223372036854775808l; //suppressed violation
private long maxLong = 9223372036854775807l; // suppressed violation
private long minLong = -9223372036854775808l; // suppressed violation

private Long nullLong = null;
private Long simpleLong = 1234l;
private Long negativeLong = -5678l;
private Long underscoreLong = 1_000_000l;
Long maxLongObject = 9223372036854775807l; //suppressed violation
Long minLongObject = -9223372036854775808l; //suppressed violation
private Long simpleLong = 1234l; // violation 'Should use uppercase 'L'.'
private Long negativeLong = -5678l; // violation 'Should use uppercase 'L'.'
private Long underscoreLong = 1_000_000l; // violation 'Should use uppercase 'L'.'
Long maxLongObject = 9223372036854775807l; // suppressed violation
Long minLongObject = -9223372036854775808l; // suppressed violation

public long calculate(long input1, long input2) {
return input1 + input2 + 1000l;
return input1 + input2 + 1000l; // violation 'Should use uppercase 'L'.'
}

public void lambdaUsage() {
// violation below, 'Should use uppercase 'L'.'
java.util.function.LongSupplier supplier = () -> 42l;
// 3 violations below
java.util.Arrays.asList(1l, 2l, 3l).forEach(System.out::println);
}

public java.util.List<Long> getNumbers() {
return java.util.Arrays.asList(100l, 200l, 300l);
return java.util.Arrays.asList(100l, 200l, 300l); // 3 violations
}

public void longObjectOperations() {
Long a = null;
Long b = 1234l;
Long c = Long.valueOf(5678l);
Long d = new Long(9999l);
Long b = 1234l; // violation 'Should use uppercase 'L'.'
Long c = Long.valueOf(5678l); // violation 'Should use uppercase 'L'.'
Long d = new Long(9999l); // violation 'Should use uppercase 'L'.'

Long conditional = (a != null) ? a : 0l;
long primitive = b != null ? b : 0l;
Long boxed = primitive + 1000l;
Long conditional = (a != null) ? a : 0l; // violation 'Should use uppercase 'L'.'
long primitive = b != null ? b : 0l; // violation 'Should use uppercase 'L'.'
Long boxed = primitive + 1000l; // violation 'Should use uppercase 'L'.'
}

public Long methodReturningLong(Long param) {
if (param == null) {
return 12345l;
return 12345l; // violation 'Should use uppercase 'L'.'
}
return param + 6789l;
return param + 6789l; // violation 'Should use uppercase 'L'.'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class OutputComplexLongLiterals {
private long withUnderscores = 1_000_000L;
private long multipleUnderscores = 1_234_567_890L;

private long maxLong = 9223372036854775807l; //suppressed violation
private long minLong = -9223372036854775808l; //suppressed violation
private long maxLong = 9223372036854775807l; // suppressed violation
private long minLong = -9223372036854775808l; // suppressed violation

private Long nullLong = null;
private Long simpleLong = 1234L;
private Long negativeLong = -5678L;
private Long underscoreLong = 1_000_000L;
Long maxLongObject = 9223372036854775807l; //suppressed violation
Long minLongObject = -9223372036854775808l; //suppressed violation
Long maxLongObject = 9223372036854775807l; // suppressed violation
Long minLongObject = -9223372036854775808l; // suppressed violation

public long calculate(long input1, long input2) {
return input1 + input2 + 1000L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
package org.checkstyle.autofix.recipe.upperell.hexoctalliteral;

public class InputHexOctalLiteral {
private long hexLower = 0x1ABCl;
private long hexUpper = 0X2DEFl;
private long octal = 0777l;
private long binary = 0b1010l;
private long decimal = 12345l;
private long hexLower = 0x1ABCl; // violation 'Should use uppercase 'L'.'
private long hexUpper = 0X2DEFl; // violation 'Should use uppercase 'L'.'
private long octal = 0777l; // violation 'Should use uppercase 'L'.'
private long binary = 0b1010l; // violation 'Should use uppercase 'L'.'
private long decimal = 12345l; // violation 'Should use uppercase 'L'.'

public void calculateValues() {
// violation below, 'Should use uppercase 'L'.'
long hexResult = 0xDEADBEEFl + 0xDEADBEFl; //suppressed violation for 0xDEADBEFl
// violation below, 'Should use uppercase 'L'.'
long octalResult = 01234l + 0xDEADBEEFl; //suppressed violation for 01234l
long binaryResult = 0b11110000l;
long binaryResult = 0b11110000l; // violation 'Should use uppercase 'L'.'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ public class InputStringAndComments {
private String message = "The value 456l should not change in strings";
private String code = "long value = 789l;"; // This 789l in string should not change

// Only this actual long literal should change
private long actualLong = 999l;
private long actualLong = 999l; // violation 'Should use uppercase 'L'.'

/*
* Multi-line comment with 111l should not change
*/
public void method() {
// Single line comment with 222l should not change
long value = 333l; // This should change
long value = 333l; // violation 'Should use uppercase 'L'.'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ public class OutputStringAndComments {
private String message = "The value 456l should not change in strings";
private String code = "long value = 789l;"; // This 789l in string should not change

// Only this actual long literal should change
private long actualLong = 999L;

/*
* Multi-line comment with 111l should not change
*/
public void method() {
// Single line comment with 222l should not change
long value = 333L; // This should change
long value = 333L;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,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)));;
private long minLong = -9223372036854775808l; // violation 'Should use uppercase 'L'.'
private Long negativeLong = -5678l; // violation 'Should use uppercase 'L'.'
long a = -0xAl; // violation 'Should use uppercase 'L'.'
long b = +-12l; // violation 'Should use uppercase 'L'.'
long c = +-(-(-(-4l)));; // violation 'Should use uppercase 'L'.'
}
Loading