Skip resolving inject constructor and type annotations when looking for members injection.

This CL avoids validation so that we don't validate the constructor or type annotations when we only care about its inject members.

RELNOTES=N/A
PiperOrigin-RevId: 420381501
diff --git a/java/dagger/internal/codegen/validation/InjectBindingRegistryImpl.java b/java/dagger/internal/codegen/validation/InjectBindingRegistryImpl.java
index 0fd39bb..7091204 100644
--- a/java/dagger/internal/codegen/validation/InjectBindingRegistryImpl.java
+++ b/java/dagger/internal/codegen/validation/InjectBindingRegistryImpl.java
@@ -314,7 +314,7 @@
   private Optional<MembersInjectionBinding> tryRegisterMembersInjectedType(
       XTypeElement typeElement, Optional<XType> resolvedType, boolean warnIfNotAlreadyGenerated) {
     // Validating here shouldn't have a performance penalty because the validator caches its reports
-    ValidationReport report = injectValidator.validate(typeElement);
+    ValidationReport report = injectValidator.validateForMembersInjection(typeElement);
     report.printMessagesTo(messager);
     if (!report.isClean()) {
       return Optional.empty();
diff --git a/java/dagger/internal/codegen/validation/InjectValidator.java b/java/dagger/internal/codegen/validation/InjectValidator.java
index fef7ce5..f347ad3 100644
--- a/java/dagger/internal/codegen/validation/InjectValidator.java
+++ b/java/dagger/internal/codegen/validation/InjectValidator.java
@@ -70,7 +70,8 @@
   private final Optional<Diagnostic.Kind> privateAndStaticInjectionDiagnosticKind;
   private final InjectionAnnotations injectionAnnotations;
   private final KotlinMetadataUtil metadataUtil;
-  private final Map<XTypeElement, ValidationReport> reports = new HashMap<>();
+  private final Map<XTypeElement, ValidationReport> provisionReports = new HashMap<>();
+  private final Map<XTypeElement, ValidationReport> membersInjectionReports = new HashMap<>();
 
   @Inject
   InjectValidator(
@@ -113,7 +114,8 @@
 
   @Override
   public void clearCache() {
-    reports.clear();
+    provisionReports.clear();
+    membersInjectionReports.clear();
   }
 
   /**
@@ -136,12 +138,12 @@
   }
 
   public ValidationReport validate(XTypeElement typeElement) {
-    return reentrantComputeIfAbsent(reports, typeElement, this::validateUncached);
+    return reentrantComputeIfAbsent(provisionReports, typeElement, this::validateUncached);
   }
 
   private ValidationReport validateUncached(XTypeElement typeElement) {
     ValidationReport.Builder builder = ValidationReport.about(typeElement);
-    builder.addSubreport(validateMembersInjectionType(typeElement));
+    builder.addSubreport(validateForMembersInjection(typeElement));
 
     ImmutableSet<XConstructorElement> injectConstructors =
         ImmutableSet.<XConstructorElement>builder()
@@ -333,7 +335,14 @@
     dependencyRequestValidator.checkNotProducer(builder, parameter);
   }
 
-  private ValidationReport validateMembersInjectionType(XTypeElement typeElement) {
+  public ValidationReport validateForMembersInjection(XTypeElement typeElement) {
+    // TODO(bcorso): validate the entire type if a factory hasn't been generated yet so that we
+    // we can report any errors on the constructor etc. that may have been missed.
+    return reentrantComputeIfAbsent(
+        membersInjectionReports, typeElement, this::validateForMembersInjectionUncached);
+  }
+
+  private ValidationReport validateForMembersInjectionUncached(XTypeElement typeElement) {
     DaggerSuperficialValidation.validateTypeOf(typeElement);
     // TODO(beder): This element might not be currently compiled, so this error message could be
     // left in limbo. Find an appropriate way to display the error message in that case.
@@ -365,7 +374,7 @@
     if (typeElement.getSuperType() != null) {
       DaggerSuperficialValidation.validateSuperTypeOf(typeElement);
       ValidationReport report =
-          validateMembersInjectionType(typeElement.getSuperType().getTypeElement());
+          validateForMembersInjection(typeElement.getSuperType().getTypeElement());
       if (!report.isClean()) {
         builder.addSubreport(report);
       }
diff --git a/javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/FooBase.java b/javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/FooBase.java
index 3a50f57..5015925 100644
--- a/javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/FooBase.java
+++ b/javatests/artifacts/dagger/transitive-annotation-app/library1/src/main/java/library1/FooBase.java
@@ -22,7 +22,7 @@
 import library2.MyTransitiveAnnotation;
 
 /** A baseclass for {@link Foo}. */
-// @MyTransitiveAnnotation(VALUE): Not supported on base-types yet.
+@MyTransitiveAnnotation(VALUE)
 public class FooBase {
   @MyTransitiveAnnotation(VALUE)
   int baseNonDaggerField;
@@ -33,11 +33,9 @@
   @MyTransitiveAnnotation(VALUE)
   FooBase(@MyTransitiveAnnotation(VALUE) String str) {}
 
-  // @MyTransitiveAnnotation(VALUE): Not supported on inject-constructors yet.
+  @MyTransitiveAnnotation(VALUE)
   @Inject
-  FooBase(
-      // @MyTransitiveAnnotation(VALUE): Not supported on inject-constructor parameters yet.
-      int i) {}
+  FooBase(@MyTransitiveAnnotation(VALUE) int i) {}
 
   @MyTransitiveAnnotation(VALUE)
   void baseNonDaggerMethod(@MyTransitiveAnnotation(VALUE) int i) {}