diff --git a/src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java b/src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java index ce994926a..3a4e53fc8 100644 --- a/src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java +++ b/src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java @@ -318,6 +318,11 @@ public J visitBinary(J.Binary original, Integer integer) { Expression newRight; if (original.getRight() instanceof J.InstanceOf) { newRight = replacements.processInstanceOf((J.InstanceOf) original.getRight(), widenedCursor); + } else if (original.getRight() instanceof J.Parentheses && + ((J.Parentheses) original.getRight()).getTree() instanceof J.InstanceOf) { + @SuppressWarnings("unchecked") + J.Parentheses originalRight = (J.Parentheses) original.getRight(); + newRight = originalRight.withTree(replacements.processInstanceOf(originalRight.getTree(), widenedCursor)); } else { newRight = (Expression) super.visitNonNull(original.getRight(), integer, widenedCursor); } @@ -443,7 +448,7 @@ public String variableName(@Nullable JavaType type) { OUTER: while (true) { for (Cursor scope : contextScopes) { - String newCandidate = VariableNameUtils.generateVariableName(candidate, scope, VariableNameUtils.GenerationStrategy.INCREMENT_NUMBER); + String newCandidate = VariableNameUtils.generateVariableName(candidate, scope, INCREMENT_NUMBER); if (!newCandidate.equals(candidate)) { candidate = newCandidate; continue OUTER; diff --git a/src/test/java/org/openrewrite/staticanalysis/InstanceOfPatternMatchTest.java b/src/test/java/org/openrewrite/staticanalysis/InstanceOfPatternMatchTest.java index bcc35611b..b7343ff1a 100644 --- a/src/test/java/org/openrewrite/staticanalysis/InstanceOfPatternMatchTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/InstanceOfPatternMatchTest.java @@ -385,7 +385,7 @@ void test(Object o) { } } } - """ + """ ) ); } @@ -405,7 +405,7 @@ void test(Object o) { } } } - """ + """ ) ); } @@ -423,7 +423,7 @@ void test(Object o) { } } } - """ + """ ) ); } @@ -500,7 +500,6 @@ int combinedLength(Object o, Object o2) { ); } - @Disabled("Not handled correctly yet") @Test @Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/174") void ifTwoDifferentInstanceOfWithParentheses() { @@ -799,7 +798,7 @@ boolean test(Object o) { } } - @SuppressWarnings({"rawtypes", "unchecked"}) + @SuppressWarnings("unchecked") @Nested class Generics { @Test