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

Various fixes for generating @SuppressWarnings #271

Merged
merged 4 commits into from Dec 13, 2018
Merged

Conversation

msridhar
Copy link
Collaborator

@msridhar msridhar commented Dec 12, 2018

Fixes #266

Fixes some issues with generating suppressions for method reference and lambda issues (see new tests).

Also refactors the code a bit to be more consistent in using the TreePath to find the right place to suppress

Copy link
Collaborator

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

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

Cool!

@msridhar msridhar changed the title Suppress properly for issue on RHS of field initializer Various fixes for generating @SuppressWarnings Dec 12, 2018
@msridhar
Copy link
Collaborator Author

@lazaroclapp want to take another look? I made some further fixes

Copy link
Collaborator

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

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

Looks good, but see the few questions/nits added.

&& ((ClassTree) tree).getSimpleName().length() != 0)
|| tree instanceof VariableTree)
.findFirst()
.orElse(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this iterate over the full path even if the suppressible node is close? Or is it a lazy iterator / generator?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think so. From what I can see it bottoms out in an iterator and goes one by one checking the predicate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry by "I think so" I meant that I think it's lazy

" @SuppressWarnings(\"NullAway\")",
" int x = foo + 1;",
" };",
"}");
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you assign a lambda within a method, where does this put the suppression? And, does that suppression work?

e.g.

public void foo() {
  this.f = () -> { ... };
  Object o = () -> { ... };
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a test case. For the this.f assignment the suppression goes on the method, whereas for the Object o case it goes on the assignment itself (you can suppress on variable declarations).

" }",
" void m2() {",
" @SuppressWarnings(\"NullAway\")",
" java.util.function.Function<Object,Integer> g = (x) -> { return foo + 1; };",
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@msridhar msridhar merged commit 46073af into master Dec 13, 2018
@msridhar msridhar deleted the ms/suppress-fix branch December 13, 2018 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants