Skip to content

Commit

Permalink
Merge pull request #12 from aaronist/update_matches_target_type
Browse files Browse the repository at this point in the history
  • Loading branch information
JLLeitschuh authored Jun 30, 2023
2 parents bb2c588 + 99dd12b commit d101f60
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

import java.util.UUID;

/**
* A class instance creation expression.
*/
public interface ClassInstanceExpr extends ConstructorCall, Expr {
enum Factory implements TraitFactory<ClassInstanceExpr> {
F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConstructorCall> {
F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExprParent> {
F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d101f60

Please sign in to comment.