From e9e27c311069ab0394c0bbb448d54bc5df441ce0 Mon Sep 17 00:00:00 2001 From: ghm Date: Thu, 26 Mar 2020 11:02:39 -0700 Subject: [PATCH] Simplify SuggestedFix creation using the static factories. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=303150947 --- .../com/google/errorprone/fixes/SuggestedFixes.java | 2 +- .../bugpatterns/ProtoFieldNullComparison.java | 12 +++++------- .../refaster/DescriptionBasedDiffTest.java | 10 ++++------ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java b/check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java index a4774199df7..331a2ed7733 100644 --- a/check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java +++ b/check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java @@ -630,7 +630,7 @@ public static SuggestedFix renameMethod( List methodTokens = state.getOffsetTokens(basePos, endPos); for (ErrorProneToken token : methodTokens) { if (token.kind() == TokenKind.IDENTIFIER && token.name().equals(tree.getName())) { - return SuggestedFix.builder().replace(token.pos(), token.endPos(), replacement).build(); + return SuggestedFix.replace(token.pos(), token.endPos(), replacement); } } // Method name not found. diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ProtoFieldNullComparison.java b/core/src/main/java/com/google/errorprone/bugpatterns/ProtoFieldNullComparison.java index db6f8a24861..3dfc7fb4965 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/ProtoFieldNullComparison.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/ProtoFieldNullComparison.java @@ -501,13 +501,11 @@ SuggestedFix fix(Fixer fixer, ExpressionTree tree, VisitorState state) { .map( r -> { MethodInvocationTree receiver = (MethodInvocationTree) getReceiver(tree); - return SuggestedFix.builder() - .replace( - tree, - String.format( - "%s(%s).isTrue()", - state.getSourceForNode(receiver.getMethodSelect()), r)) - .build(); + return SuggestedFix.replace( + tree, + String.format( + "%s(%s).isTrue()", + state.getSourceForNode(receiver.getMethodSelect()), r)); }) .orElse(SuggestedFix.builder().build()); } diff --git a/core/src/test/java/com/google/errorprone/refaster/DescriptionBasedDiffTest.java b/core/src/test/java/com/google/errorprone/refaster/DescriptionBasedDiffTest.java index f386f792fa9..a22c2f3c0d0 100644 --- a/core/src/test/java/com/google/errorprone/refaster/DescriptionBasedDiffTest.java +++ b/core/src/test/java/com/google/errorprone/refaster/DescriptionBasedDiffTest.java @@ -145,20 +145,18 @@ public void overlappingDiffs_throws() { .build()))); DescriptionBasedDiff diff2 = createDescriptionBasedDiff(); - diff2.onDescribed(dummyDescription(SuggestedFix.builder().replace(137, 140, "baz").build())); + diff2.onDescribed(dummyDescription(SuggestedFix.replace(137, 140, "baz"))); assertThrows( IllegalArgumentException.class, - () -> - diff2.onDescribed( - dummyDescription(SuggestedFix.builder().replace(137, 140, "bar").build()))); + () -> diff2.onDescribed(dummyDescription(SuggestedFix.replace(137, 140, "bar")))); DescriptionBasedDiff diff3 = DescriptionBasedDiff.createIgnoringOverlaps( compilationUnit, ImportOrganizer.STATIC_FIRST_ORGANIZER); - diff3.onDescribed(dummyDescription(SuggestedFix.builder().replace(137, 140, "baz").build())); + diff3.onDescribed(dummyDescription(SuggestedFix.replace(137, 140, "baz"))); // No throw, since it's lenient. Refactors to the first "baz" replacement and ignores this. - diff3.onDescribed(dummyDescription(SuggestedFix.builder().replace(137, 140, "bar").build())); + diff3.onDescribed(dummyDescription(SuggestedFix.replace(137, 140, "bar"))); diff3.applyDifferences(sourceFile); assertThat(sourceFile.getLines())