Skip to content

Commit

Permalink
Support parentheses in binary for InstanceOfPatternMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Jul 15, 2024
1 parent ab9825a commit b1b7116
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<J.InstanceOf> originalRight = (J.Parentheses<J.InstanceOf>) original.getRight();
newRight = originalRight.withTree(replacements.processInstanceOf(originalRight.getTree(), widenedCursor));
} else {
newRight = (Expression) super.visitNonNull(original.getRight(), integer, widenedCursor);
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ void test(Object o) {
}
}
}
"""
"""
)
);
}
Expand All @@ -405,7 +405,7 @@ void test(Object o) {
}
}
}
"""
"""
)
);
}
Expand All @@ -423,7 +423,7 @@ void test(Object o) {
}
}
}
"""
"""
)
);
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -799,7 +798,7 @@ boolean test(Object o) {
}
}

@SuppressWarnings({"rawtypes", "unchecked"})
@SuppressWarnings("unchecked")
@Nested
class Generics {
@Test
Expand Down

0 comments on commit b1b7116

Please sign in to comment.