Skip to content

Commit 02d62d6

Browse files
bcorsoDagger Team
authored and
Dagger Team
committed
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
1 parent c872238 commit 02d62d6

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

java/dagger/internal/codegen/binding/BindingGraphFactory.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import dagger.Reusable;
4545
import dagger.internal.codegen.base.ClearableCache;
4646
import dagger.internal.codegen.base.ContributionType;
47+
import dagger.internal.codegen.base.DaggerSuperficialValidation;
4748
import dagger.internal.codegen.base.Keys;
4849
import dagger.internal.codegen.base.MapType;
4950
import dagger.internal.codegen.base.OptionalType;
@@ -261,7 +262,8 @@ private ImmutableSet<ModuleDescriptor> modules(
261262
.addAll(componentDescriptor.modules())
262263
.add(
263264
moduleDescriptorFactory.create(
264-
processingEnv.requireTypeElement(
265+
DaggerSuperficialValidation.requireTypeElement(
266+
processingEnv,
265267
generatedMonitoringModuleName(componentDescriptor.typeElement()))))
266268
.add(
267269
moduleDescriptorFactory.create(

javatests/dagger/internal/codegen/ProductionComponentProcessorTest.java

+45
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,51 @@ public void dependsOnProductionExecutor() throws Exception {
201201
// TODO(dpb): Report at the binding if enclosed in the module.
202202
}
203203

204+
@Test
205+
public void dependsOnProductionSubcomponentWithPluginsVisitFullBindingGraphs() throws Exception {
206+
Source myComponent =
207+
CompilerTests.javaSource(
208+
"test.MyComponent",
209+
"package test;",
210+
"",
211+
"import dagger.Component;",
212+
"",
213+
"@Component(modules = MyModule.class)",
214+
"interface MyComponent {}");
215+
Source myModule =
216+
CompilerTests.javaSource(
217+
"test.MyModule",
218+
"package test;",
219+
"",
220+
"import dagger.Component;",
221+
"import dagger.Module;",
222+
"",
223+
"@Module(subcomponents = MyProductionSubcomponent.class)",
224+
"interface MyModule {}");
225+
Source myProductionSubcomponent =
226+
CompilerTests.javaSource(
227+
"test.MyProductionSubcomponent",
228+
"package test;",
229+
"",
230+
"import dagger.producers.ProductionSubcomponent;",
231+
"",
232+
"@ProductionSubcomponent",
233+
"interface MyProductionSubcomponent {",
234+
" @ProductionSubcomponent.Builder",
235+
" interface Builder {",
236+
" MyProductionSubcomponent build();",
237+
" }",
238+
"}");
239+
240+
CompilerTests.daggerCompiler(myComponent, myModule, myProductionSubcomponent)
241+
.withProcessingOptions(
242+
ImmutableMap.<String, String>builder()
243+
.putAll(compilerMode.processorOptions())
244+
.put("dagger.pluginsVisitFullBindingGraphs", "ENABLED")
245+
.buildOrThrow())
246+
.compile(subject -> subject.hasErrorCount(0));
247+
}
248+
204249
@Test
205250
public void simpleComponent() throws Exception {
206251
Source component =

0 commit comments

Comments
 (0)