diff --git a/rewrite-java/src/main/java/org/openrewrite/java/TypeMatcher.java b/rewrite-java/src/main/java/org/openrewrite/java/TypeMatcher.java index 7d60668563d..da7ffd20dbd 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/TypeMatcher.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/TypeMatcher.java @@ -98,7 +98,7 @@ public boolean matches(@Nullable JavaType type) { private boolean matchesTargetTypeName(String fullyQualifiedTypeName) { return this.targetType != null && fullyQualifiedNamesAreEqual(this.targetType, fullyQualifiedTypeName) || - this.targetTypePattern != null && this.targetTypePattern.matcher(fullyQualifiedTypeName).matches(); + this.targetTypePattern.matcher(fullyQualifiedTypeName).matches(); } private static boolean isPlainIdentifier(MethodSignatureParser.TargetTypePatternContext context) { diff --git a/rewrite-java/src/main/java/org/openrewrite/java/search/UsesField.java b/rewrite-java/src/main/java/org/openrewrite/java/search/UsesField.java index 6b1ce3c08d4..cec0bd139f9 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/search/UsesField.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/search/UsesField.java @@ -38,7 +38,10 @@ public J visit(@Nullable Tree tree, P p) { boolean isGlob = field.contains("*") || field.contains("?"); TypeMatcher typeMatcher = null; for (JavaType.Variable variable : cu.getTypesInUse().getVariables()) { - if ((variable.getName().equals(field) || isGlob && StringUtils.matchesGlob(variable.getName(), field)) && + if (isGlob && (typeMatcher = typeMatcher == null ? new TypeMatcher(owner, true) : typeMatcher).matches(variable.getOwner()) && + StringUtils.matchesGlob(variable.getName(), field)) { + return SearchResult.found(cu); + } else if (!isGlob && variable.getName().equals(field) && (typeMatcher = typeMatcher == null ? new TypeMatcher(owner, true) : typeMatcher).matches(variable.getOwner())) { return SearchResult.found(cu); }