Skip to content

Commit

Permalink
Replace processingEnv.requireTypeElement() with `DaggerSuperficialV…
Browse files Browse the repository at this point in the history
…alidation.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
  • Loading branch information
bcorso authored and Dagger Team committed Feb 12, 2024
1 parent c872238 commit 02d62d6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
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;
Expand Down Expand Up @@ -261,7 +262,8 @@ private ImmutableSet<ModuleDescriptor> modules(
.addAll(componentDescriptor.modules())
.add(
moduleDescriptorFactory.create(
processingEnv.requireTypeElement(
DaggerSuperficialValidation.requireTypeElement(
processingEnv,
generatedMonitoringModuleName(componentDescriptor.typeElement()))))
.add(
moduleDescriptorFactory.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,51 @@ public void dependsOnProductionExecutor() throws Exception {
// TODO(dpb): Report at the binding if enclosed in the module.
}

@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 =
Expand Down

0 comments on commit 02d62d6

Please sign in to comment.