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

replaceIncludingComments: skip synthetic variable declarations in records. #4764

Merged
merged 1 commit into from
Jan 13, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static com.google.errorprone.util.ASTHelpers.getStartPosition;
import static com.google.errorprone.util.ASTHelpers.getSymbol;
import static com.google.errorprone.util.ASTHelpers.hasImplicitType;
import static com.google.errorprone.util.ASTHelpers.isRecord;
import static com.sun.source.tree.Tree.Kind.ASSIGNMENT;
import static com.sun.source.tree.Tree.Kind.CONDITIONAL_EXPRESSION;
import static com.sun.source.tree.Tree.Kind.NEW_ARRAY;
Expand Down Expand Up @@ -1641,7 +1642,11 @@ public static SuggestedFix replaceIncludingComments(
ClassTree classTree = (ClassTree) parent;
int startTokenization;
for (Tree member : classTree.getMembers()) {
if (member instanceof MethodTree && ASTHelpers.isGeneratedConstructor((MethodTree) member)) {
if (member instanceof MethodTree methodTree
&& ASTHelpers.isGeneratedConstructor(methodTree)) {
continue;
}
if (member instanceof VariableTree && isRecord(getSymbol(member))) {
continue;
}
if (member.equals(tree)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,6 @@ public long getId() {
}
}
""")
// TODO(kak): we shouldn't delete the closing parenthesis and open curly bracket!
.addOutputLines(
"Client.java",
"""
Expand All @@ -1015,8 +1014,7 @@ public long getId() {
import com.google.errorprone.annotations.InlineMe;

public final class Client {
public record SomeRecord(long id
}
public record SomeRecord(long id) {}
}
""")
.doTest(TestMode.TEXT_MATCH);
Expand Down
Loading