Don't issue warnings on dead code#6246
Merged
mernst merged 16 commits intotypetools:masterfrom Oct 23, 2023
Merged
Conversation
mernst
requested changes
Oct 21, 2023
Comment on lines
+304
to
+315
| ((ExceptionBlock) cur) | ||
| .getExceptionalSuccessors() | ||
| .forEach( | ||
| (key, value) -> { | ||
| if (!shouldIgnoreException.apply(key)) { | ||
| for (Block b : value) { | ||
| if (visited.add(b)) { | ||
| worklist.add(b); | ||
| } | ||
| } | ||
| } | ||
| }); |
Member
There was a problem hiding this comment.
Writing this as
for (Map.Entry<TypeMirror, Set<Block>> entry :
((ExceptionBlock) cur).getExceptionalSuccessors().entrySet()) {
if (!shouldIgnoreException.apply(entry.getKey())) {
for (Block b : entry.getValue()) {
if (visited.add(b)) {
worklist.add(b);
}
}
}
}is two lines shorter and I find it easier to read (for example, types are given and there are no lambdas).
I do wish there were a way to bind variables to the parts of the Entry, right in the for statement header.
Comment on lines
+346
to
+350
| List<Node> result = new ArrayList<>(); | ||
| for (Block b : getAllBlocks(shouldIgnoreException)) { | ||
| result.addAll(b.getNodes()); | ||
| } | ||
| return result; |
Member
There was a problem hiding this comment.
This could be done with flatMap if you want to make it a one-liner.
Member
Author
There was a problem hiding this comment.
flatMap would create a new stream for each block:
getAllBlocks(shouldIgnoreException).stream().flatMap(b -> b.getNodes().stream()).collect(Collectors.toList());
collect would be better:
getAllBlocks(shouldIgnoreException).stream().collect(ArrayList::new, (list, b) -> list.addAll(b.getNodes()), ArrayList::addAll);
But still it creates a Stream object. I think forEach makes the most sense:
getAllBlocks(shouldIgnoreException).forEach(b -> result.addAll(b.getNodes()));
Member
There was a problem hiding this comment.
Any of those, or the current code, is fine with me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This should fix the errors in #6221.