Skip to content

Commit

Permalink
Autofix orElseGet (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn authored and bulldozer-bot[bot] committed Jul 12, 2019
1 parent 617b857 commit 90c5974
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-690.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Auto-fix OptionalOrElseMethodInvocation using `-PerrorProneApply`.
links:
- https://github.com/palantir/gradle-baseline/pull/690
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class BaselineErrorProneExtension {
"PreferListsPartition",
"PreferSafeLoggableExceptions",
"PreferSafeLoggingPreconditions",
"OptionalOrElseMethodInvocation",

// Built-in checks
"ArrayEquals",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public void apply(Project project) {
"-XepPatchChecks:refaster:" + refasterRulesFile.get().getAbsolutePath(),
"-XepPatchLocation:IN_PLACE"));
} else if (project.hasProperty(PROP_ERROR_PRONE_APPLY)) {
javaCompile.getOptions().setWarnings(false);
// TODO(gatesn): Is there a way to discover error-prone checks?
// Maybe service-load from a ClassLoader configured with annotation processor path?
// https://github.com/google/error-prone/pull/947
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ class BaselineErrorProneIntegrationTest extends AbstractPluginTest {

def invalidJavaFile = '''
package test;
import java.util.Optional;
public class Test {
void test() {
int[] a = {1, 2, 3};
int[] b = {1, 2, 3};
if (a.equals(b)) {
System.out.println("arrays are equal!");
Optional.of("hello").orElse(System.getProperty("world"));
}
}
}
Expand Down Expand Up @@ -112,14 +114,15 @@ class BaselineErrorProneIntegrationTest extends AbstractPluginTest {
result.task(":compileJava").outcome == TaskOutcome.SUCCESS
file('src/main/java/test/Test.java').text == '''
package test;
import java.util.Arrays;
import java.util.Optional;
public class Test {
void test() {
int[] a = {1, 2, 3};
int[] b = {1, 2, 3};
if (Arrays.equals(a, b)) {
System.out.println("arrays are equal!");
Optional.of("hello").orElseGet(() -> System.getProperty("world"));
}
}
}
Expand Down

0 comments on commit 90c5974

Please sign in to comment.