Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofix orElseGet #690

Merged
merged 4 commits into from
Jul 12, 2019
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
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