-
Notifications
You must be signed in to change notification settings - Fork 39
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
Prefer Mono#fromSupplier
over Mono#fromCallable
where possible
#232
Conversation
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 significantly improves our setup, very cool!
Also nice Refaster template 🚀.
Have some questions and considerations :).
import com.sun.source.util.TreeScanner; | ||
import javax.annotation.Nullable; | ||
|
||
abstract class AbstractTestChecker extends BugChecker implements CompilationUnitTreeMatcher { |
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.
To make clear the checker is solely focused on matching ExpressionTree
s, should we either (1) change the name or (2) add some Javadoc explaining this?
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.
Hmm, maybe AbstractMatcherTestChecker
. Will add some documentation.
public Void visitImport(ImportTree node, @Nullable Void unused) { | ||
/* | ||
* We're not interested in matching import statements. While components of these | ||
* can be `ExpressionTree`s. |
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.
Should we do this to be consistent with the method below?
* can be `ExpressionTree`s. | |
* can be `ExpressionTree`s, they will never be matched by Refaster. |
new TreeScanner<Void, Void>() { | ||
@Nullable | ||
@Override | ||
public Void scan(Tree tree, @Nullable Void p) { |
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.
public Void scan(Tree tree, @Nullable Void p) { | |
public Void scan(Tree tree, @Nullable Void unused) { |
The name p
was most likely choosen over unused
on purpose, but still wanted to ask, technically it's "unused" because p
is Void
... Does it make sense to let it be consistent with the visitImport
one and also call it unused
?
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.
Ah, it's named p
after the method in the TreeScanner
superclass. First it had another name, but then IDEA complained. But I see that IDEA handles unused
specially, which makes sense. No strong opinion either way, so will change.
import com.sun.source.util.TreeScanner; | ||
import javax.annotation.Nullable; | ||
|
||
abstract class AbstractTestChecker extends BugChecker implements CompilationUnitTreeMatcher { |
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.
Is there anything against moving this to refaster-test-support
?
People might want to use this AbstractTestChecker
for their own Matcher
s as well.
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.
I'd defer such a move for two reasons:
- This class isn't truly Refaster- specific.
- As-is the class isn't part of the public API, thus allowing us to change it more freely in the future.
@Override | ||
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { | ||
return new IsArray().matches(tree, state) ? describeMatch(tree) : Description.NO_MATCH; | ||
// XXX: This is false positive reported by CheckStyle. See |
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.
// XXX: This is false positive reported by CheckStyle. See | |
// XXX: This is a false positive reported by Checkstyle. See |
Right?
It's funny, you usually write Github
instead of GitHub
and for Checkstyle it's the other way around 😉.
} | ||
} | ||
|
||
private static boolean containsCheckedException(Collection<Type> types, VisitorState state) { |
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.
Should this method be above the other one because it comes before getThrownTypes
? "Call-down" 😄 ?
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.
In either case we would call down, but getThrownTypes
is invoked before containsCheckedException
, so I'd say the current order is "correct".
This rule is implemented using a Refaster template, relying on the new `ThrowsCheckedException` matcher. While there, introduce `AbstractTestChecker` to simplify the test setup for Refaster `Matcher`s. This base class flags all `ExpressionTree`s matched by the `Matcher` under test.
0cd0e3a
to
6f199a3
Compare
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.
Rebased and added a commit. Tnx for the review!
} | ||
} | ||
|
||
private static boolean containsCheckedException(Collection<Type> types, VisitorState state) { |
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.
In either case we would call down, but getThrownTypes
is invoked before containsCheckedException
, so I'd say the current order is "correct".
import com.sun.source.util.TreeScanner; | ||
import javax.annotation.Nullable; | ||
|
||
abstract class AbstractTestChecker extends BugChecker implements CompilationUnitTreeMatcher { |
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.
I'd defer such a move for two reasons:
- This class isn't truly Refaster- specific.
- As-is the class isn't part of the public API, thus allowing us to change it more freely in the future.
import com.sun.source.util.TreeScanner; | ||
import javax.annotation.Nullable; | ||
|
||
abstract class AbstractTestChecker extends BugChecker implements CompilationUnitTreeMatcher { |
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.
Hmm, maybe AbstractMatcherTestChecker
. Will add some documentation.
new TreeScanner<Void, Void>() { | ||
@Nullable | ||
@Override | ||
public Void scan(Tree tree, @Nullable Void p) { |
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.
Ah, it's named p
after the method in the TreeScanner
superclass. First it had another name, but then IDEA complained. But I see that IDEA handles unused
specially, which makes sense. No strong opinion either way, so will change.
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.
Changes LGTM!
Suggested commit message is 👍🏻.
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.
Nice! From now on will be able to stop checking all Mono.fromCallable(...
for checked exceptions 😄
Didn't review the ThrowsCheckedException
matcher because it escapes my knowledge and I have no time to learn it right now, but looks cool :)
Thanks for the review @EnricSala 😄. |
Suggested commit message: