From b0aa9f15f6b4f8d5f8872f751e65a0f275746c2d Mon Sep 17 00:00:00 2001 From: Brad Corso Date: Tue, 3 May 2022 10:32:37 -0700 Subject: [PATCH] Replace javac implementation of XProcessingEnv#isAssignable() with XProcessing implementation. RELNOTES=N/A PiperOrigin-RevId: 446229240 --- java/dagger/internal/codegen/binding/BindsTypeChecker.java | 5 ++--- .../codegen/writing/ComponentRequestRepresentations.java | 4 ++-- .../codegen/writing/DelegateRequestRepresentation.java | 4 ++-- .../internal/codegen/xprocessing/XProcessingEnvs.java | 7 ------- java/dagger/internal/codegen/xprocessing/XTypes.java | 5 +++++ 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/java/dagger/internal/codegen/binding/BindsTypeChecker.java b/java/dagger/internal/codegen/binding/BindsTypeChecker.java index 9071fda2fb0..1b4aa347264 100644 --- a/java/dagger/internal/codegen/binding/BindsTypeChecker.java +++ b/java/dagger/internal/codegen/binding/BindsTypeChecker.java @@ -20,6 +20,7 @@ import static dagger.internal.codegen.extension.DaggerCollectors.onlyElement; import static dagger.internal.codegen.xprocessing.XElements.getSimpleName; import static dagger.internal.codegen.xprocessing.XProcessingEnvs.getUnboundedWildcardType; +import static dagger.internal.codegen.xprocessing.XTypes.isAssignableTo; import androidx.room.compiler.processing.XProcessingEnv; import androidx.room.compiler.processing.XType; @@ -27,7 +28,6 @@ import com.google.common.collect.ImmutableList; import dagger.internal.codegen.base.ContributionType; import dagger.internal.codegen.javapoet.TypeNames; -import dagger.internal.codegen.xprocessing.XProcessingEnvs; import dagger.internal.codegen.xprocessing.XTypeElements; import javax.inject.Inject; @@ -52,8 +52,7 @@ public final class BindsTypeChecker { */ public boolean isAssignable( XType rightHandSide, XType leftHandSide, ContributionType contributionType) { - return XProcessingEnvs.isAssignable( - rightHandSide, desiredAssignableType(leftHandSide, contributionType), processingEnv); + return isAssignableTo(rightHandSide, desiredAssignableType(leftHandSide, contributionType)); } private XType desiredAssignableType(XType leftHandSide, ContributionType contributionType) { diff --git a/java/dagger/internal/codegen/writing/ComponentRequestRepresentations.java b/java/dagger/internal/codegen/writing/ComponentRequestRepresentations.java index 395d42eab15..eb43504a8c2 100644 --- a/java/dagger/internal/codegen/writing/ComponentRequestRepresentations.java +++ b/java/dagger/internal/codegen/writing/ComponentRequestRepresentations.java @@ -28,7 +28,7 @@ import static dagger.internal.codegen.langmodel.Accessibility.isTypeAccessibleFrom; import static dagger.internal.codegen.xprocessing.XElements.getSimpleName; import static dagger.internal.codegen.xprocessing.XProcessingEnvs.erasure; -import static dagger.internal.codegen.xprocessing.XProcessingEnvs.isAssignable; +import static dagger.internal.codegen.xprocessing.XTypes.isAssignableTo; import androidx.room.compiler.processing.XMethodElement; import androidx.room.compiler.processing.XProcessingEnv; @@ -245,7 +245,7 @@ private Expression getComponentMethodExpression( // for types that have protected accessibility to the component but are not accessible to other // classes, e.g. shards, that may need to handle the implementation of the binding. XType returnType = componentMethod.methodElement().getReturnType(); - return !isVoid(returnType) && !isAssignable(expression.type(), returnType, processingEnv) + return !isVoid(returnType) && !isAssignableTo(expression.type(), returnType) ? expression.castTo(returnType) : expression; } diff --git a/java/dagger/internal/codegen/writing/DelegateRequestRepresentation.java b/java/dagger/internal/codegen/writing/DelegateRequestRepresentation.java index d2bb162fc22..f79d3ea322f 100644 --- a/java/dagger/internal/codegen/writing/DelegateRequestRepresentation.java +++ b/java/dagger/internal/codegen/writing/DelegateRequestRepresentation.java @@ -23,7 +23,7 @@ import static dagger.internal.codegen.binding.BindingRequest.bindingRequest; import static dagger.internal.codegen.langmodel.Accessibility.isTypeAccessibleFrom; import static dagger.internal.codegen.xprocessing.XProcessingEnvs.erasure; -import static dagger.internal.codegen.xprocessing.XProcessingEnvs.isAssignable; +import static dagger.internal.codegen.xprocessing.XTypes.isAssignableTo; import static dagger.spi.model.BindingKind.DELEGATE; import androidx.room.compiler.processing.XProcessingEnv; @@ -117,7 +117,7 @@ static boolean instanceRequiresCast( */ // TODO(ronshapiro): this probably can be generalized for usage in InjectionMethods private Expression castToRawTypeIfNecessary(Expression delegateExpression, XType desiredType) { - if (isAssignable(delegateExpression.type(), desiredType, processingEnv)) { + if (isAssignableTo(delegateExpression.type(), desiredType)) { return delegateExpression; } Expression castedExpression = delegateExpression.castTo(erasure(desiredType, processingEnv)); diff --git a/java/dagger/internal/codegen/xprocessing/XProcessingEnvs.java b/java/dagger/internal/codegen/xprocessing/XProcessingEnvs.java index ae2db779948..98afda5bd8c 100644 --- a/java/dagger/internal/codegen/xprocessing/XProcessingEnvs.java +++ b/java/dagger/internal/codegen/xprocessing/XProcessingEnvs.java @@ -136,13 +136,6 @@ public static XType rewrapType( } } - /** Returns {@code true} if and only if the {@code type1} is assignable to {@code type2}. */ - public static boolean isAssignable(XType type1, XType type2, XProcessingEnv processingEnv) { - return toJavac(processingEnv) - .getTypeUtils() // ALLOW_TYPES_ELEMENTS - .isAssignable(toJavac(type1), toJavac(type2)); - } - /** Returns the erasure of the given type. */ public static XType erasure(XType type, XProcessingEnv processingEnv) { return toXProcessing( diff --git a/java/dagger/internal/codegen/xprocessing/XTypes.java b/java/dagger/internal/codegen/xprocessing/XTypes.java index 617aeb164c3..4e8b2f863d8 100644 --- a/java/dagger/internal/codegen/xprocessing/XTypes.java +++ b/java/dagger/internal/codegen/xprocessing/XTypes.java @@ -36,6 +36,11 @@ /** A utility class for {@link XType} helper methods. */ public final class XTypes { + /** Returns {@code true} if and only if the {@code type1} is assignable to {@code type2}. */ + public static boolean isAssignableTo(XType type1, XType type2) { + return type2.isAssignableFrom(type1); + } + /** * Throws {@link TypeNotPresentException} if {@code type} is an {@link * javax.lang.model.type.ErrorType}.