-
Notifications
You must be signed in to change notification settings - Fork 357
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
Don't issue warnings on dead code #6246
Conversation
((ExceptionBlock) cur) | ||
.getExceptionalSuccessors() | ||
.forEach( | ||
(key, value) -> { | ||
if (!shouldIgnoreException.apply(key)) { | ||
for (Block b : value) { | ||
if (visited.add(b)) { | ||
worklist.add(b); | ||
} | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
List<Node> result = new ArrayList<>(); | ||
for (Block b : getAllBlocks(shouldIgnoreException)) { | ||
result.addAll(b.getNodes()); | ||
} | ||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be done with flatMap
if you want to make it a one-liner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any of those, or the current code, is fine with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This should fix the errors in #6221.