Skip to content

Commit 8c8c450

Browse files
refactor: Adopt J.Literal.isLiteralValue(expression, null) (#751)
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.java.recipes.IsLiteralNullRecipe?organizationId=ODQ2MGExMTUtNDg0My00N2EwLTgzMGMtNGE1NGExMTBmZDkw Co-authored-by: Moderne <team@moderne.io>
1 parent bcefa4e commit 8c8c450

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseNullToAssertNotNull.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ private boolean isEqualBinaryWithNull(J.MethodInvocation method) {
113113
if (binary.getOperator() != J.Binary.Type.Equal) {
114114
return false;
115115
}
116-
return binary.getLeft() instanceof J.Literal && ((J.Literal) binary.getLeft()).getValue() == null ||
117-
binary.getRight() instanceof J.Literal && ((J.Literal) binary.getRight()).getValue() == null;
116+
return J.Literal.isLiteralValue(binary.getLeft(), null) ||
117+
J.Literal.isLiteralValue(binary.getRight(), null);
118118
}
119119
});
120120
}

src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueNullToAssertNull.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ private boolean isEqualBinaryWithNull(J.MethodInvocation method) {
113113
if (binary.getOperator() != J.Binary.Type.Equal) {
114114
return false;
115115
}
116-
return binary.getLeft() instanceof J.Literal && ((J.Literal) binary.getLeft()).getValue() == null ||
117-
binary.getRight() instanceof J.Literal && ((J.Literal) binary.getRight()).getValue() == null;
116+
return J.Literal.isLiteralValue(binary.getLeft(), null) ||
117+
J.Literal.isLiteralValue(binary.getRight(), null);
118118
}
119119
});
120120
}

0 commit comments

Comments
 (0)