|
17 | 17 |
|
18 | 18 | import lombok.EqualsAndHashCode; |
19 | 19 | import lombok.Value; |
20 | | -import org.jspecify.annotations.NonNull; |
21 | 20 | import org.jspecify.annotations.Nullable; |
22 | 21 | import org.openrewrite.*; |
| 22 | +import org.openrewrite.internal.ToBeRemoved; |
23 | 23 | import org.openrewrite.java.JavaIsoVisitor; |
24 | | -import org.openrewrite.java.TypeNameMatcher; |
25 | 24 | import org.openrewrite.java.JavaVisitor; |
26 | 25 | import org.openrewrite.java.TypeMatcher; |
| 26 | +import org.openrewrite.java.TypeNameMatcher; |
27 | 27 | import org.openrewrite.java.table.TypeUses; |
28 | 28 | import org.openrewrite.java.tree.*; |
29 | 29 | import org.openrewrite.marker.SearchResult; |
@@ -145,19 +145,35 @@ private static boolean typeMatches(boolean checkAssignability, TypeNameMatcher m |
145 | 145 | return false; |
146 | 146 | } |
147 | 147 | if (checkAssignability) { |
148 | | - return test.isAssignableFrom(matcher); |
| 148 | + return isAssignableFrom(matcher, test); |
149 | 149 | } else { |
150 | 150 | return matcher.matches(test.getFullyQualifiedName()); |
151 | 151 | } |
152 | 152 | } |
153 | 153 |
|
| 154 | + @ToBeRemoved(after = "2025-10-15") |
| 155 | + private static boolean isAssignableFrom(TypeNameMatcher matcher, JavaType.FullyQualified test) { |
| 156 | + if (matcher.matches(test.getFullyQualifiedName())) { |
| 157 | + return true; |
| 158 | + } |
| 159 | + if (test.getSupertype() != null && isAssignableFrom(matcher, test.getSupertype())) { |
| 160 | + return true; |
| 161 | + } |
| 162 | + for (JavaType.FullyQualified anInterface : test.getInterfaces()) { |
| 163 | + if (isAssignableFrom(matcher, anInterface)) { |
| 164 | + return true; |
| 165 | + } |
| 166 | + } |
| 167 | + return false; |
| 168 | + } |
| 169 | + |
154 | 170 | @Value |
155 | 171 | @EqualsAndHashCode(callSuper = false) |
156 | 172 | private static class ReferenceVisitor extends TreeVisitor<Tree, ExecutionContext> { |
157 | 173 | Set<Tree> matches; |
158 | 174 |
|
159 | 175 | @Override |
160 | | - public Tree postVisit(@NonNull Tree tree, ExecutionContext ctx) { |
| 176 | + public Tree postVisit(Tree tree, ExecutionContext ctx) { |
161 | 177 | return matches.contains(tree) ? SearchResult.found(tree) : tree; |
162 | 178 | } |
163 | 179 | } |
|
0 commit comments