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

ImmutableMemberCollection: support field-level @SuppressWarnings #2301

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public Description matchClass(ClassTree classTree, VisitorState state) {
classTree.getMembers().stream()
.filter(member -> PRIVATE_FINAL_VAR_MATCHER.matches(member, state))
.filter(member -> !EXCLUSIONS.matches(member, state))
.filter(member -> !isSuppressed(member))
.map(VariableTree.class::cast)
.flatMap(varTree -> stream(isReplaceable(varTree, state)))
.collect(toImmutableMap(ReplaceableVar::symbol, var -> var));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ public void listInitInline_notMutated_replacesTypeWithImmutableList() {
.doTest();
}

@Test
public void setInitConstructor_notMutatedButSuppressed_doesNothing() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Tried to follow the test naming convention of other tests in this class.)

refactoringHelper
.addInputLines(
"Test.java",
"import java.util.List;",
"class Test {",
" @SuppressWarnings(\"ImmutableMemberCollection\")",
" private final List<String> myList;",
" Test(List<String> myList) {",
" this.myList = myList;",
" }",
"}")
.expectUnchanged()
.doTest();
}

@Test
public void listInitConstructor_notMutated_replacesTypeWithImmutableList() {
refactoringHelper
Expand Down