Skip to content

Commit

Permalink
Simplify SuggestedFix creation using the static factories.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=303150947
  • Loading branch information
graememorgan authored and nick-someone committed Mar 30, 2020
1 parent 9ba1ce0 commit e9e27c3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ public static SuggestedFix renameMethod(
List<ErrorProneToken> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit e9e27c3

Please sign in to comment.