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
Refactor simple onOverrideMayBeNullExpr
handlers
#747
Conversation
execution of the touched handler methods is inconsequential when parameter exprMayBeNull is already true
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.
a similar refactoring is possible for LibraryModelsHandler
but i wanted to "test out the water" first 😅
&& exprSymbol instanceof Symbol.MethodSymbol) { | ||
return exprMayBeNull || isReturnAnnotatedNullable((Symbol.MethodSymbol) exprSymbol); | ||
if (exprMayBeNull) { | ||
return true; |
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.
like a preamble: "this handler only supports false -> true
transitions"
&& isReturnAnnotatedNullable((Symbol.MethodSymbol) exprSymbol)) { | ||
return true; | ||
} | ||
return false; |
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 is structured like:
if reason1_why_expr_may_be_null:
return true
if reason2_why_expr_may_be_null:
return true
return false
when there is only a single reason, we could of course use the condition in a single return statement if preferred?
the old style is imo more confusing (an has redundant checks):
if check1:
return exprMayBeNull || check2
return exprMayBeNull
if any of the checks have important side-effects (that i am not seeing) we should add tests that expose those imo.
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.
agreed this is an improvement here
if (exprMayBeNull) { | ||
return true; | ||
} | ||
if (expr.getKind() == Tree.Kind.METHOD_INVOCATION | ||
&& exprSymbol instanceof Symbol.MethodSymbol | ||
&& optionalIsGetCall((Symbol.MethodSymbol) exprSymbol, state.getTypes())) { | ||
return true; |
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 the old code, this line returning true (and thus the whole if condition) only matters, if we wouldnt eventually be returning true with return exprMayBeNull
anyway.
this again is assuming that the checks have no side-effects (if they do tests around it are missing)
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.
These changes LGTM. Sorry for the slow review. I will rewrite the PR title a bit and then merge
&& isReturnAnnotatedNullable((Symbol.MethodSymbol) exprSymbol)) { | ||
return true; | ||
} | ||
return false; |
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.
agreed this is an improvement here
onOverrideMayBeNullExpr
handlersonOverrideMayBeNullExpr
handlers
This reverts commit 7714c45.
This reverts commit 7714c45.
This reverts commit 7714c45.
This reverts commit 7714c45.
This reverts commit 7714c45.
execution of the affected handlers is inconsequential when parameter exprMayBeNull is already true