diff --git a/src/main/java/org/openrewrite/analysis/BasicJavaTypeMethodMatcher.java b/src/main/java/org/openrewrite/analysis/BasicJavaTypeMethodMatcher.java index d805974f5..3c5aa84bf 100644 --- a/src/main/java/org/openrewrite/analysis/BasicJavaTypeMethodMatcher.java +++ b/src/main/java/org/openrewrite/analysis/BasicJavaTypeMethodMatcher.java @@ -18,6 +18,7 @@ import io.micrometer.core.lang.Nullable; import lombok.NoArgsConstructor; import org.openrewrite.java.tree.JavaType; +import org.openrewrite.java.tree.TypeUtils; import java.util.List; @@ -46,31 +47,11 @@ default boolean matches(@Nullable JavaType.Method type) { * @implNote {@link #isMatchOverrides()} will be used to determine if parent types should also be checked */ default boolean matchesTargetType(@Nullable JavaType.FullyQualified type) { - if (type == null || type instanceof JavaType.Unknown) { - return false; - } - - if (matchesTargetTypeName(type.getFullyQualifiedName())) { - return true; - } - - if (isMatchOverrides()) { - if (!"java.lang.Object".equals(type.getFullyQualifiedName()) && - matchesTargetType(SimpleMethodMatcherHolder.OBJECT_CLASS)) { - return true; - } - - if (matchesTargetType(type.getSupertype())) { - return true; - } - - for (JavaType.FullyQualified anInterface : type.getInterfaces()) { - if (matchesTargetType(anInterface)) { - return true; - } - } - } - return false; + return TypeUtils.isOfTypeWithName( + type, + isMatchOverrides(), + this::matchesTargetTypeName + ); } /** diff --git a/src/main/java/org/openrewrite/analysis/trait/expr/BinaryExpr.java b/src/main/java/org/openrewrite/analysis/trait/expr/BinaryExpr.java index 4df59c700..f266b4a98 100644 --- a/src/main/java/org/openrewrite/analysis/trait/expr/BinaryExpr.java +++ b/src/main/java/org/openrewrite/analysis/trait/expr/BinaryExpr.java @@ -26,6 +26,9 @@ import java.util.UUID; +/** + * A common super-class to represent binary operator expressions. + */ public interface BinaryExpr extends Expr { J.Binary.Type getOperator(); diff --git a/src/main/java/org/openrewrite/analysis/trait/expr/ClassInstanceExpr.java b/src/main/java/org/openrewrite/analysis/trait/expr/ClassInstanceExpr.java index 93e548929..cb19183e6 100644 --- a/src/main/java/org/openrewrite/analysis/trait/expr/ClassInstanceExpr.java +++ b/src/main/java/org/openrewrite/analysis/trait/expr/ClassInstanceExpr.java @@ -26,6 +26,9 @@ import java.util.UUID; +/** + * A class instance creation expression. + */ public interface ClassInstanceExpr extends ConstructorCall, Expr { enum Factory implements TraitFactory { F; diff --git a/src/main/java/org/openrewrite/analysis/trait/expr/ConstructorCall.java b/src/main/java/org/openrewrite/analysis/trait/expr/ConstructorCall.java index 8685d849e..c8a113005 100644 --- a/src/main/java/org/openrewrite/analysis/trait/expr/ConstructorCall.java +++ b/src/main/java/org/openrewrite/analysis/trait/expr/ConstructorCall.java @@ -20,6 +20,10 @@ import org.openrewrite.analysis.trait.TraitFactory; import org.openrewrite.analysis.trait.util.TraitErrors; +/** + * A constructor call, which occurs either as a constructor invocation + * inside a constructor, or as part of a class instance expression. + */ public interface ConstructorCall extends Call { enum Factory implements TraitFactory { F; diff --git a/src/main/java/org/openrewrite/analysis/trait/expr/ExprParent.java b/src/main/java/org/openrewrite/analysis/trait/expr/ExprParent.java index 59cb4b1ff..f8a989ebf 100644 --- a/src/main/java/org/openrewrite/analysis/trait/expr/ExprParent.java +++ b/src/main/java/org/openrewrite/analysis/trait/expr/ExprParent.java @@ -21,6 +21,9 @@ import org.openrewrite.analysis.trait.TraitFactory; import org.openrewrite.analysis.trait.util.TraitErrors; +/** + * An expression parent is an element that may have an expression as its child. + */ public interface ExprParent extends Top { enum Factory implements TraitFactory { F; diff --git a/src/main/java/org/openrewrite/analysis/trait/expr/Literal.java b/src/main/java/org/openrewrite/analysis/trait/expr/Literal.java index 2fb55abf7..c6da022e9 100644 --- a/src/main/java/org/openrewrite/analysis/trait/expr/Literal.java +++ b/src/main/java/org/openrewrite/analysis/trait/expr/Literal.java @@ -26,6 +26,9 @@ import java.util.Optional; import java.util.UUID; +/** + * A common super-class to represent constant literals. + */ public interface Literal extends Expr { Optional getValue(); diff --git a/src/main/java/org/openrewrite/analysis/trait/expr/MethodAccess.java b/src/main/java/org/openrewrite/analysis/trait/expr/MethodAccess.java index 6d101e2ef..9cfa8521f 100644 --- a/src/main/java/org/openrewrite/analysis/trait/expr/MethodAccess.java +++ b/src/main/java/org/openrewrite/analysis/trait/expr/MethodAccess.java @@ -29,6 +29,9 @@ import java.util.Objects; import java.util.UUID; +/** + * A method access is an invocation of a method with a list of arguments. + */ public interface MethodAccess extends Expr, Call { String getSimpleName(); diff --git a/src/main/java/org/openrewrite/analysis/trait/expr/VarAccess.java b/src/main/java/org/openrewrite/analysis/trait/expr/VarAccess.java index 519926842..356b16478 100644 --- a/src/main/java/org/openrewrite/analysis/trait/expr/VarAccess.java +++ b/src/main/java/org/openrewrite/analysis/trait/expr/VarAccess.java @@ -36,6 +36,10 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; +/** + * A variable access is a (possibly qualified) reference to a field, + * parameter or local variable. + */ public interface VarAccess extends Expr { String getName();