Skip to content

Commit

Permalink
refactor simple onOverrideMayBeNullExpr handlers (#747)
Browse files Browse the repository at this point in the history
When `exprMayBeNull` is true, return immediately, to make clear that these handlers only support `false -> true` transitions

Co-authored-by: Manu Sridharan <msridhar@gmail.com>
  • Loading branch information
XN137 and msridhar committed Mar 30, 2023
1 parent a1d1eed commit 7714c45
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
Expand Up @@ -196,11 +196,15 @@ public boolean onOverrideMayBeNullExpr(
@Nullable Symbol exprSymbol,
VisitorState state,
boolean exprMayBeNull) {
if (expr.getKind().equals(Tree.Kind.METHOD_INVOCATION)
&& exprSymbol instanceof Symbol.MethodSymbol) {
return exprMayBeNull || isReturnAnnotatedNullable((Symbol.MethodSymbol) exprSymbol);
if (exprMayBeNull) {
return true;
}
return exprMayBeNull;
if (expr.getKind() == Tree.Kind.METHOD_INVOCATION
&& exprSymbol instanceof Symbol.MethodSymbol
&& isReturnAnnotatedNullable((Symbol.MethodSymbol) exprSymbol)) {
return true;
}
return false;
}

private boolean isReturnAnnotatedNullable(Symbol.MethodSymbol methodSymbol) {
Expand Down
Expand Up @@ -87,12 +87,15 @@ public boolean onOverrideMayBeNullExpr(
@Nullable Symbol exprSymbol,
VisitorState state,
boolean exprMayBeNull) {
if (expr.getKind().equals(Tree.Kind.METHOD_INVOCATION)
if (exprMayBeNull) {
return true;
}
if (expr.getKind() == Tree.Kind.METHOD_INVOCATION
&& exprSymbol instanceof Symbol.MethodSymbol
&& optionalIsGetCall((Symbol.MethodSymbol) exprSymbol, state.getTypes())) {
return true;
}
return exprMayBeNull;
return false;
}

@Override
Expand Down
Expand Up @@ -76,13 +76,16 @@ public boolean onOverrideMayBeNullExpr(
@Nullable Symbol exprSymbol,
VisitorState state,
boolean exprMayBeNull) {
if (exprMayBeNull) {
return true;
}
Tree.Kind exprKind = expr.getKind();
if (exprSymbol != null
&& (exprKind.equals(Tree.Kind.METHOD_INVOCATION)
|| exprKind.equals(Tree.Kind.IDENTIFIER))) {
return exprMayBeNull || isSymbolRestrictivelyNullable(exprSymbol, state.context);
&& (exprKind == Tree.Kind.METHOD_INVOCATION || exprKind == Tree.Kind.IDENTIFIER)
&& isSymbolRestrictivelyNullable(exprSymbol, state.context)) {
return true;
}
return exprMayBeNull;
return false;
}

@Nullable private CodeAnnotationInfo codeAnnotationInfo;
Expand Down

0 comments on commit 7714c45

Please sign in to comment.