aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Corso <bcorso@google.com>2024-02-12 13:05:36 -0800
committerDagger Team <dagger-dev+copybara@google.com>2024-02-12 13:11:47 -0800
commit02d62d69329af9ba71773718cd0ae8a41bac4f3e (patch)
tree452bf3c374892e9310d00417522d8f65a3a82576
parentc8722386a1fb10d9e70c6fbccba01ebdd5e56967 (diff)
downloaddagger2-02d62d69329af9ba71773718cd0ae8a41bac4f3e.tar.gz
Replace `processingEnv.requireTypeElement()` with `DaggerSuperficialValidation.requireTypeElement()`.
I found a case when using `--dagger.pluginsVisitFullBindingGraphs` where `BindingGraphFactory` is triggered from the `ModuleProcessingStep`. In this case, we can't guarantee that the monitoring module has been generated yet so we need to wrap in `DaggerSuperficialValidation.requireTypeElement` to ensure that processing will get delayed if the modules doesn't exist yet. RELNOTES=N/A PiperOrigin-RevId: 606341195
-rw-r--r--java/dagger/internal/codegen/binding/BindingGraphFactory.java4
-rw-r--r--javatests/dagger/internal/codegen/ProductionComponentProcessorTest.java45
2 files changed, 48 insertions, 1 deletions
diff --git a/java/dagger/internal/codegen/binding/BindingGraphFactory.java b/java/dagger/internal/codegen/binding/BindingGraphFactory.java
index 7dcabe4bb..503435901 100644
--- a/java/dagger/internal/codegen/binding/BindingGraphFactory.java
+++ b/java/dagger/internal/codegen/binding/BindingGraphFactory.java
@@ -44,6 +44,7 @@ import com.google.common.collect.Multimaps;
import dagger.Reusable;
import dagger.internal.codegen.base.ClearableCache;
import dagger.internal.codegen.base.ContributionType;
+import dagger.internal.codegen.base.DaggerSuperficialValidation;
import dagger.internal.codegen.base.Keys;
import dagger.internal.codegen.base.MapType;
import dagger.internal.codegen.base.OptionalType;
@@ -261,7 +262,8 @@ public final class BindingGraphFactory implements ClearableCache {
.addAll(componentDescriptor.modules())
.add(
moduleDescriptorFactory.create(
- processingEnv.requireTypeElement(
+ DaggerSuperficialValidation.requireTypeElement(
+ processingEnv,
generatedMonitoringModuleName(componentDescriptor.typeElement()))))
.add(
moduleDescriptorFactory.create(
diff --git a/javatests/dagger/internal/codegen/ProductionComponentProcessorTest.java b/javatests/dagger/internal/codegen/ProductionComponentProcessorTest.java
index b9758c121..39e63c99e 100644
--- a/javatests/dagger/internal/codegen/ProductionComponentProcessorTest.java
+++ b/javatests/dagger/internal/codegen/ProductionComponentProcessorTest.java
@@ -202,6 +202,51 @@ public class ProductionComponentProcessorTest {
}
@Test
+ public void dependsOnProductionSubcomponentWithPluginsVisitFullBindingGraphs() throws Exception {
+ Source myComponent =
+ CompilerTests.javaSource(
+ "test.MyComponent",
+ "package test;",
+ "",
+ "import dagger.Component;",
+ "",
+ "@Component(modules = MyModule.class)",
+ "interface MyComponent {}");
+ Source myModule =
+ CompilerTests.javaSource(
+ "test.MyModule",
+ "package test;",
+ "",
+ "import dagger.Component;",
+ "import dagger.Module;",
+ "",
+ "@Module(subcomponents = MyProductionSubcomponent.class)",
+ "interface MyModule {}");
+ Source myProductionSubcomponent =
+ CompilerTests.javaSource(
+ "test.MyProductionSubcomponent",
+ "package test;",
+ "",
+ "import dagger.producers.ProductionSubcomponent;",
+ "",
+ "@ProductionSubcomponent",
+ "interface MyProductionSubcomponent {",
+ " @ProductionSubcomponent.Builder",
+ " interface Builder {",
+ " MyProductionSubcomponent build();",
+ " }",
+ "}");
+
+ CompilerTests.daggerCompiler(myComponent, myModule, myProductionSubcomponent)
+ .withProcessingOptions(
+ ImmutableMap.<String, String>builder()
+ .putAll(compilerMode.processorOptions())
+ .put("dagger.pluginsVisitFullBindingGraphs", "ENABLED")
+ .buildOrThrow())
+ .compile(subject -> subject.hasErrorCount(0));
+ }
+
+ @Test
public void simpleComponent() throws Exception {
Source component =
CompilerTests.javaSource(