Skip to content

Commit

Permalink
Replace javac implementation of XProcessingEnv#isAssignable() with XP…
Browse files Browse the repository at this point in the history
…rocessing implementation.

RELNOTES=N/A
PiperOrigin-RevId: 446229240
  • Loading branch information
bcorso authored and Dagger Team committed May 3, 2022
1 parent dfab36d commit b0aa9f1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
5 changes: 2 additions & 3 deletions java/dagger/internal/codegen/binding/BindsTypeChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
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;
import androidx.room.compiler.processing.XTypeElement;
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;

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
7 changes: 0 additions & 7 deletions java/dagger/internal/codegen/xprocessing/XProcessingEnvs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions java/dagger/internal/codegen/xprocessing/XTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down

0 comments on commit b0aa9f1

Please sign in to comment.