Skip to content

Commit 6240501

Browse files
bcorsoDagger Team
authored andcommitted
Internal changes.
RELNOTES=N/A PiperOrigin-RevId: 765386692
1 parent fca4e7e commit 6240501

280 files changed

Lines changed: 22528 additions & 75 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dagger-compiler/main/java/dagger/internal/codegen/DelegateComponentProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ final class DelegateComponentProcessor {
7979
@Inject ValidationBindingGraphPlugins validationBindingGraphPlugins;
8080
@Inject ExternalBindingGraphPlugins externalBindingGraphPlugins;
8181
@Inject Set<ClearableCache> clearableCaches;
82+
@Inject CompilerOptions compilerOptions;
8283

8384
public void initialize(
8485
XProcessingEnv env,

java/dagger/testing/compile/CompilerTests.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,12 @@ public DaggerCompiler withAdditionalClasspath(ImmutableList<File> libs) {
283283
}
284284

285285
public void compile(Consumer<CompilationResultSubject> onCompilationResult) {
286-
compileInternal(onCompilationResult, DEFAULT_KOTLINC_OPTIONS);
287-
}
288-
289-
private void compileInternal(
290-
Consumer<CompilationResultSubject> onCompilationResult,
291-
ImmutableList<String> kotlincArguments) {
292286
ProcessorTestExtKt.runProcessorTest(
293287
sources().asList(),
294288
additionalClasspath(),
295289
processorOptions(),
296290
/* javacArguments= */ DEFAULT_JAVAC_OPTIONS,
297-
/* kotlincArguments= */ kotlincArguments,
291+
/* kotlincArguments= */ DEFAULT_KOTLINC_OPTIONS,
298292
/* config= */ PROCESSING_ENV_CONFIG,
299293
/* javacProcessors= */ mergeProcessors(
300294
ImmutableList.of(

javatests/dagger/internal/codegen/AssistedFactoryErrorsTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -894,17 +894,15 @@ public void testInaccessibleFoo() {
894894
CompilerTests.daggerCompiler(foo, fooFactory, component)
895895
.withProcessingOptions(compilerMode.processorOptions());
896896

897-
if (compilerMode == CompilerMode.FAST_INIT_MODE) {
898-
// TODO(bcorso): Remove once we fix inaccessible assisted factory imlementation for fastInit.
897+
if (compilerMode == CompilerMode.FAST_INIT_MODE) {
898+
// TODO(bcorso): Remove once we fix inaccessible assisted factory implementation for fastInit.
899899
daggerCompiler.compile(
900-
subject -> {
901-
// TODO(bcorso): We don't report the error count here because javac reports
902-
// the error once, whereas ksp reports the error twice.
903-
subject
904-
.hasErrorContaining(
905-
"test.subpackage.InaccessibleFoo is not public in test.subpackage; cannot be "
906-
+ "accessed from outside package");
907-
});
900+
subject ->
901+
// TODO(bcorso): We don't report the error count here because javac reports
902+
// the error once, whereas ksp reports the error twice.
903+
subject.hasErrorContaining(
904+
"test.subpackage.InaccessibleFoo is not public in test.subpackage; cannot be "
905+
+ "accessed from outside package"));
908906
} else {
909907
daggerCompiler.compile(subject -> subject.hasErrorCount(0));
910908
}

javatests/dagger/internal/codegen/CompilerMode.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@
2828
// TODO(bcorso): Consider moving the java version into its own separate enum.
2929
public enum CompilerMode {
3030
DEFAULT_MODE,
31-
FAST_INIT_MODE("-Adagger.fastInit=enabled");
31+
FAST_INIT_MODE("-Adagger.fastInit=enabled"),
32+
;
3233

3334
/** Returns the compiler modes as a list of parameters for parameterized tests */
3435
public static final ImmutableList<Object[]> TEST_PARAMETERS =
3536
ImmutableList.copyOf(
36-
new Object[][] {{CompilerMode.DEFAULT_MODE}, {CompilerMode.FAST_INIT_MODE}});
37+
new Object[][] {
38+
{CompilerMode.DEFAULT_MODE},
39+
{CompilerMode.FAST_INIT_MODE},
40+
});
3741

3842
private final ImmutableList<String> javacopts;
3943

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package test;
2+
3+
import dagger.internal.DaggerGenerated;
4+
import dagger.internal.Provider;
5+
import javax.annotation.processing.Generated;
6+
7+
@DaggerGenerated
8+
@Generated(
9+
value = "dagger.internal.codegen.ComponentProcessor",
10+
comments = "https://dagger.dev"
11+
)
12+
@SuppressWarnings({
13+
"unchecked",
14+
"rawtypes",
15+
"KotlinInternal",
16+
"KotlinInternalInJava",
17+
"cast",
18+
"deprecation",
19+
"nullness:initialization.field.uninitialized"
20+
})
21+
final class DaggerTestComponent {
22+
private DaggerTestComponent() {
23+
}
24+
25+
public static Builder builder() {
26+
return new Builder();
27+
}
28+
29+
public static TestComponent create() {
30+
return new Builder().build();
31+
}
32+
33+
static final class Builder {
34+
private Builder() {
35+
}
36+
37+
public TestComponent build() {
38+
return new TestComponentImpl();
39+
}
40+
}
41+
42+
private static final class TestComponentImpl implements TestComponent {
43+
private final TestComponentImpl testComponentImpl = this;
44+
45+
Foo_Factory fooProvider;
46+
47+
Provider<FooFactory> fooFactoryProvider;
48+
49+
TestComponentImpl() {
50+
51+
initialize();
52+
53+
}
54+
55+
@SuppressWarnings("unchecked")
56+
private void initialize() {
57+
this.fooProvider = Foo_Factory.create(Bar_Factory.create());
58+
this.fooFactoryProvider = FooFactory_Impl.createFactoryProvider(fooProvider);
59+
}
60+
61+
@Override
62+
public FooFactory fooFactory() {
63+
return fooFactoryProvider.get();
64+
}
65+
}
66+
}
67+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package test;
2+
3+
import dagger.internal.DaggerGenerated;
4+
import dagger.internal.Provider;
5+
import dagger.internal.SingleCheck;
6+
import javax.annotation.processing.Generated;
7+
8+
@DaggerGenerated
9+
@Generated(
10+
value = "dagger.internal.codegen.ComponentProcessor",
11+
comments = "https://dagger.dev"
12+
)
13+
@SuppressWarnings({
14+
"unchecked",
15+
"rawtypes",
16+
"KotlinInternal",
17+
"KotlinInternalInJava",
18+
"cast",
19+
"deprecation",
20+
"nullness:initialization.field.uninitialized"
21+
})
22+
final class DaggerTestComponent {
23+
private DaggerTestComponent() {
24+
}
25+
26+
public static Builder builder() {
27+
return new Builder();
28+
}
29+
30+
public static TestComponent create() {
31+
return new Builder().build();
32+
}
33+
34+
static final class Builder {
35+
private Builder() {
36+
}
37+
38+
public TestComponent build() {
39+
return new TestComponentImpl();
40+
}
41+
}
42+
43+
private static final class TestComponentImpl implements TestComponent {
44+
private final TestComponentImpl testComponentImpl = this;
45+
46+
Provider<Bar> barProvider;
47+
48+
Provider<FooFactory> fooFactoryProvider;
49+
50+
TestComponentImpl() {
51+
52+
initialize();
53+
54+
}
55+
56+
@SuppressWarnings("unchecked")
57+
private void initialize() {
58+
this.barProvider = new SwitchingProvider<>(testComponentImpl, 1);
59+
this.fooFactoryProvider = SingleCheck.provider(new SwitchingProvider<FooFactory>(testComponentImpl, 0));
60+
}
61+
62+
@Override
63+
public FooFactory fooFactory() {
64+
return fooFactoryProvider.get();
65+
}
66+
67+
private static final class SwitchingProvider<T> implements Provider<T> {
68+
private final TestComponentImpl testComponentImpl;
69+
70+
private final int id;
71+
72+
SwitchingProvider(TestComponentImpl testComponentImpl, int id) {
73+
this.testComponentImpl = testComponentImpl;
74+
this.id = id;
75+
}
76+
77+
@Override
78+
@SuppressWarnings("unchecked")
79+
public T get() {
80+
switch (id) {
81+
case 0: // test.FooFactory
82+
return (T) new FooFactory() {
83+
@Override
84+
public Foo create(String testComponentImpl2) {
85+
return new Foo(testComponentImpl2, testComponentImpl.barProvider);
86+
}
87+
};
88+
89+
case 1: // test.Bar
90+
return (T) new Bar();
91+
92+
default: throw new AssertionError(id);
93+
}
94+
}
95+
}
96+
}
97+
}
98+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package test;
2+
3+
import dagger.internal.DaggerGenerated;
4+
import dagger.internal.DelegateFactory;
5+
import dagger.internal.Provider;
6+
import javax.annotation.processing.Generated;
7+
8+
@DaggerGenerated
9+
@Generated(
10+
value = "dagger.internal.codegen.ComponentProcessor",
11+
comments = "https://dagger.dev"
12+
)
13+
@SuppressWarnings({
14+
"unchecked",
15+
"rawtypes",
16+
"KotlinInternal",
17+
"KotlinInternalInJava",
18+
"cast",
19+
"deprecation",
20+
"nullness:initialization.field.uninitialized"
21+
})
22+
final class DaggerTestComponent {
23+
private DaggerTestComponent() {
24+
}
25+
26+
public static Builder builder() {
27+
return new Builder();
28+
}
29+
30+
public static TestComponent create() {
31+
return new Builder().build();
32+
}
33+
34+
static final class Builder {
35+
private Builder() {
36+
}
37+
38+
public TestComponent build() {
39+
return new TestComponentImpl();
40+
}
41+
}
42+
43+
private static final class TestComponentImpl implements TestComponent {
44+
private final TestComponentImpl testComponentImpl = this;
45+
46+
Provider<FooFactory> fooFactoryProvider;
47+
48+
Provider<Bar> barProvider;
49+
50+
Foo_Factory fooProvider;
51+
52+
TestComponentImpl() {
53+
54+
initialize();
55+
56+
}
57+
58+
@SuppressWarnings("unchecked")
59+
private void initialize() {
60+
this.fooFactoryProvider = new DelegateFactory<>();
61+
this.barProvider = Bar_Factory.create(fooFactoryProvider);
62+
this.fooProvider = Foo_Factory.create(barProvider);
63+
DelegateFactory.setDelegate(fooFactoryProvider, FooFactory_Impl.createFactoryProvider(fooProvider));
64+
}
65+
66+
@Override
67+
public FooFactory fooFactory() {
68+
return fooFactoryProvider.get();
69+
}
70+
}
71+
}
72+

0 commit comments

Comments
 (0)