-
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
Introduce IdentityConversionCheck
#27
Changes from 1 commit
b592066
57180ca
07ebfd3
e060553
8bf0f8f
9c9825e
bd40a22
6886c85
47205e6
943eebc
d9bc85a
1f0ccf9
0506118
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package tech.picnic.errorprone.bugpatterns; | ||
|
||
import static com.google.common.base.Preconditions.checkState; | ||
import static com.google.errorprone.matchers.Matchers.anyOf; | ||
import static com.google.errorprone.matchers.Matchers.staticMethod; | ||
import static com.google.errorprone.suppliers.Suppliers.typeFromString; | ||
|
@@ -79,11 +78,9 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState | |
ExpressionTree sourceTree = arguments.get(0); | ||
Type sourceType = ASTHelpers.getType(sourceTree); | ||
TargetType targetType = ASTHelpers.targetType(state); | ||
checkState( | ||
sourceType != null && targetType != null, | ||
"sourceType `%s` or targetType `%s` is null.", | ||
sourceType, | ||
targetType); | ||
if (sourceType == null || targetType == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the |
||
return Description.NO_MATCH; | ||
} | ||
|
||
if (state.getTypes().isSameType(sourceType, ASTHelpers.getType(tree)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that in practice |
||
|| isSubtypeWithDefinedEquality(sourceType, targetType.type(), 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.
Genuine question: What's the target type here exactly? Why not
ASTHelpers.getType(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.
Javadoc
getType
:Javadoc
getTargetType
:Nice question; the type would only give us information about the current expression itself (state), while we want to know what the "expected" type of the current expression is (i.o.w. what the parent expects/wants to receive) and thus what the target type is of this expression.
So in the
Flux#flatMap
case, let's say we matched aRxJava2Adapter.fluxToFlowable(flux)
and we ask for the target type, we know that we want to havePublisher
in the end. AFlux
is already satiesfies that, so we can remove the conversion.