Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
oxkitsune committed Aug 9, 2023
1 parent f85916e commit cbfbc54
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -745,17 +745,14 @@ public Void visitMemberSelect(MemberSelectTree tree, Void unused) {

/** Be warned, only changes method name at the declaration. */
public static SuggestedFix renameMethod(MethodTree tree, String replacement, VisitorState state) {
// Search tokens from beginning of method tree to beginning of method body.
int basePos = getStartPosition(tree);
// Search tokens from end of return type tree to beginning of method body.
int basePos = state.getEndPosition(tree.getReturnType());
int endPos =
tree.getBody() != null ? getStartPosition(tree.getBody()) : state.getEndPosition(tree);
List<ErrorProneToken> methodTokens = state.getOffsetTokens(basePos, endPos);

int returnTypeEndPos = state.getEndPosition(tree.getReturnType());
for (ErrorProneToken token : methodTokens) {
if (token.kind() == TokenKind.IDENTIFIER
&& token.pos() > returnTypeEndPos
&& token.name().equals(tree.getName())) {
if (token.kind() == TokenKind.IDENTIFIER && token.name().equals(tree.getName())) {
return SuggestedFix.replace(token.pos(), token.endPos(), replacement);
}
}
Expand Down

0 comments on commit cbfbc54

Please sign in to comment.