diff --git a/java/dagger/internal/codegen/writing/ComponentImplementation.java b/java/dagger/internal/codegen/writing/ComponentImplementation.java index 4ecf1367c54..e4028dd99c6 100644 --- a/java/dagger/internal/codegen/writing/ComponentImplementation.java +++ b/java/dagger/internal/codegen/writing/ComponentImplementation.java @@ -480,7 +480,7 @@ public final class ShardImplementation implements GeneratedImplementation { private ShardImplementation(ClassName name) { this.name = name; - this.switchingProviders = new SwitchingProviders(this); + this.switchingProviders = new SwitchingProviders(this, processingEnv); this.experimentalSwitchingProviders = new ExperimentalSwitchingProviders(this, componentRequestRepresentationsProvider); diff --git a/java/dagger/internal/codegen/writing/FrameworkFieldInitializer.java b/java/dagger/internal/codegen/writing/FrameworkFieldInitializer.java index 6791463ca19..c1ae77c4ecf 100644 --- a/java/dagger/internal/codegen/writing/FrameworkFieldInitializer.java +++ b/java/dagger/internal/codegen/writing/FrameworkFieldInitializer.java @@ -34,7 +34,6 @@ import dagger.internal.codegen.binding.FrameworkField; import dagger.internal.codegen.javapoet.AnnotationSpecs; import dagger.internal.codegen.javapoet.TypeNames; -import dagger.internal.codegen.writing.ComponentImplementation.CompilerMode; import dagger.internal.codegen.writing.ComponentImplementation.ShardImplementation; import dagger.spi.model.BindingKind; import java.util.Optional; @@ -65,7 +64,6 @@ default Optional alternativeFrameworkClass() { private final ShardImplementation shardImplementation; private final ContributionBinding binding; private final FrameworkInstanceCreationExpression frameworkInstanceCreationExpression; - private final CompilerMode compilerMode; private FieldSpec fieldSpec; private InitializationState fieldInitializationState = InitializationState.UNINITIALIZED; @@ -75,7 +73,6 @@ default Optional alternativeFrameworkClass() { FrameworkInstanceCreationExpression frameworkInstanceCreationExpression) { this.binding = checkNotNull(binding); this.shardImplementation = checkNotNull(componentImplementation).shardImplementation(binding); - this.compilerMode = componentImplementation.compilerMode(); this.frameworkInstanceCreationExpression = checkNotNull(frameworkInstanceCreationExpression); } @@ -113,12 +110,13 @@ private void initializeField() { case INITIALIZING: fieldSpec = getOrCreateField(); // We were recursively invoked, so create a delegate factory instead to break the loop. - // However, because SwitchingProvider takes no dependencies, even if they are recursively - // invoked, we don't need to delegate it since there is no dependency cycle. - if (FrameworkInstanceKind.from(binding, compilerMode) - .equals(FrameworkInstanceKind.SWITCHING_PROVIDER)) { - break; - } + + // TODO(erichang): For the most part SwitchingProvider takes no dependencies so even if they + // are recursively invoked, we don't need to delegate it since there is no dependency cycle. + // However, there is a case with a scoped @Binds where we reference the impl binding when + // passing it into DoubleCheck. For this case, we do need to delegate it. There might be + // a way to only do delegates in this situation, but we'd need to keep track of what other + // bindings use this. fieldInitializationState = InitializationState.DELEGATED; shardImplementation.addInitialization( diff --git a/java/dagger/internal/codegen/writing/SwitchingProviders.java b/java/dagger/internal/codegen/writing/SwitchingProviders.java index 9df292fe93e..dc6ec942469 100644 --- a/java/dagger/internal/codegen/writing/SwitchingProviders.java +++ b/java/dagger/internal/codegen/writing/SwitchingProviders.java @@ -30,6 +30,7 @@ import static javax.lang.model.element.Modifier.PUBLIC; import static javax.lang.model.element.Modifier.STATIC; +import androidx.room.compiler.processing.XProcessingEnv; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.squareup.javapoet.ClassName; @@ -42,6 +43,7 @@ import dagger.internal.codegen.javapoet.CodeBlocks; import dagger.internal.codegen.writing.ComponentImplementation.ShardImplementation; import dagger.internal.codegen.writing.FrameworkFieldInitializer.FrameworkInstanceCreationExpression; +import dagger.internal.codegen.xprocessing.XProcessingEnvs; import dagger.spi.model.BindingKind; import dagger.spi.model.Key; import java.util.HashMap; @@ -77,9 +79,11 @@ final class SwitchingProviders { new LinkedHashMap<>(); private final ShardImplementation shardImplementation; + private final XProcessingEnv processingEnv; - SwitchingProviders(ShardImplementation shardImplementation) { + SwitchingProviders(ShardImplementation shardImplementation, XProcessingEnv processingEnv) { this.shardImplementation = checkNotNull(shardImplementation); + this.processingEnv = checkNotNull(processingEnv); } /** Returns the framework instance creation expression for an inner switching provider class. */ @@ -133,7 +137,9 @@ private CodeBlock getNewInstanceCodeBlock( // Add the type parameter explicitly when the binding is scoped because Java can't resolve // the type when wrapped. For example, the following will error: // fooProvider = DoubleCheck.provider(new SwitchingProvider<>(1)); - (binding.scope().isPresent() || binding.kind().equals(BindingKind.ASSISTED_FACTORY)) + (binding.scope().isPresent() + || binding.kind().equals(BindingKind.ASSISTED_FACTORY) + || XProcessingEnvs.isPreJava8SourceVersion(processingEnv)) ? CodeBlock.of( "$T", shardImplementation.accessibleTypeName(binding.contributedType())) : "", diff --git a/javatests/dagger/functional/binds/BUILD b/javatests/dagger/functional/binds/BUILD index 580cdaa5dc7..6282f4cc30d 100644 --- a/javatests/dagger/functional/binds/BUILD +++ b/javatests/dagger/functional/binds/BUILD @@ -25,8 +25,19 @@ load("//:test_defs.bzl", "GenJavaTests") package(default_visibility = ["//:src"]) GenJavaTests( - name = "binds", - srcs = glob(["*.java"]), + name = "BindsTest", + srcs = [ + "AccessesExposedComponent.java", + "BindsTest.java", + "Foo.java", + "FooOfObjects.java", + "FooOfStrings.java", + "InterfaceModule.java", + "NeedsFactory.java", + "SimpleBindingModule.java", + "SomeQualifier.java", + "TestComponent.java", + ], gen_library_deps = [ "//javatests/dagger/functional/binds/subpackage", ], @@ -34,11 +45,39 @@ GenJavaTests( deps = [ "//:dagger_with_compiler", "//third_party/java/auto:factory", - "//third_party/java/guava/base", - "//third_party/java/guava/collect", - "//third_party/java/guava/util/concurrent", - "//third_party/java/jsr305_annotations", - "//third_party/java/jsr330_inject", + "//third_party/java/junit", + "//third_party/java/truth", + ], +) + +GenJavaTests( + name = "BindsCollectionsWithoutMultibindingsTest", + srcs = ["BindsCollectionsWithoutMultibindingsTest.java"], + javacopts = DOCLINT_HTML_AND_SYNTAX + DOCLINT_REFERENCES, + deps = [ + "//:dagger_with_compiler", + "//third_party/java/junit", + "//third_party/java/truth", + ], +) + +GenJavaTests( + name = "ScopedBindsTest", + srcs = ["ScopedBindsTest.java"], + javacopts = DOCLINT_HTML_AND_SYNTAX + DOCLINT_REFERENCES, + deps = [ + "//:dagger_with_compiler", + "//third_party/java/junit", + "//third_party/java/truth", + ], +) + +GenJavaTests( + name = "RecursiveBindsTest", + srcs = ["RecursiveBindsTest.java"], + javacopts = DOCLINT_HTML_AND_SYNTAX + DOCLINT_REFERENCES, + deps = [ + "//:dagger_with_compiler", "//third_party/java/junit", "//third_party/java/truth", ], diff --git a/javatests/dagger/functional/binds/RecursiveBindsTest.java b/javatests/dagger/functional/binds/RecursiveBindsTest.java new file mode 100644 index 00000000000..8b482040464 --- /dev/null +++ b/javatests/dagger/functional/binds/RecursiveBindsTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2023 The Dagger Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dagger.functional.binds; + +import static com.google.common.truth.Truth.assertThat; + +import dagger.Binds; +import dagger.Component; +import dagger.Module; +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +// This is a regression test for b/267223822 where a scoped @Binds used in a cycle caused problems +// in fastInit mode. +@RunWith(JUnit4.class) +public class RecursiveBindsTest { + + public interface Foo {} + + public static final class FooImpl implements Foo { + @Inject FooImpl(@SuppressWarnings("unused") Provider provider) {} + } + + @Module + public interface FooModule { + // This binding must be scoped to create the cycle. Otherwise without a scope, the generated + // code just doesn't have a field for this @Binds because we can directly use FooImpl's + // provider as they are equivalent. + @Binds + @Singleton + Foo bindFoo(FooImpl impl); + } + + @Component(modules = FooModule.class) + @Singleton + public interface TestSingletonComponent { + // We get the impl here to create a cycle where the impl factory needs to be delegated. + // That way the scoped binds (which does something like DoubleCheck.provider(implFactory)) is + // the one that would fail if it wasn't delegated properly. + Provider getFooImplProvider(); + } + + @Test + public void test() { + // Technically the NPE would happen when just initializing the component. + assertThat(DaggerRecursiveBindsTest_TestSingletonComponent.create().getFooImplProvider().get()) + .isNotNull(); + } +} diff --git a/javatests/dagger/functional/kotlinsrc/binds/BUILD b/javatests/dagger/functional/kotlinsrc/binds/BUILD index b6353241d7b..fa51d30453e 100644 --- a/javatests/dagger/functional/kotlinsrc/binds/BUILD +++ b/javatests/dagger/functional/kotlinsrc/binds/BUILD @@ -25,8 +25,19 @@ load("//:test_defs.bzl", "GenKtTests") package(default_visibility = ["//:src"]) GenKtTests( - name = "binds", - srcs = glob(["*.kt"]), + name = "BindsTest", + srcs = [ + "AccessesExposedComponent.kt", + "BindsTest.kt", + "Foo.kt", + "FooOfObjects.kt", + "FooOfStrings.kt", + "InterfaceModule.kt", + "NeedsFactory.kt", + "SimpleBindingModule.kt", + "SomeQualifier.kt", + "TestComponent.kt", + ], gen_library_deps = [ "//javatests/dagger/functional/kotlinsrc/binds/subpackage", ], @@ -34,11 +45,28 @@ GenKtTests( deps = [ "//:dagger_with_compiler", "//third_party/java/auto:factory", - "//third_party/java/guava/base", - "//third_party/java/guava/collect", - "//third_party/java/guava/util/concurrent", - "//third_party/java/jsr305_annotations", - "//third_party/java/jsr330_inject", + "//third_party/java/junit", + "//third_party/java/truth", + ], +) + +GenKtTests( + name = "BindsCollectionsWithoutMultibindingsTest", + srcs = ["BindsCollectionsWithoutMultibindingsTest.kt"], + javacopts = DOCLINT_HTML_AND_SYNTAX + DOCLINT_REFERENCES, + deps = [ + "//:dagger_with_compiler", + "//third_party/java/junit", + "//third_party/java/truth", + ], +) + +GenKtTests( + name = "ScopedBindsTest", + srcs = ["ScopedBindsTest.kt"], + javacopts = DOCLINT_HTML_AND_SYNTAX + DOCLINT_REFERENCES, + deps = [ + "//:dagger_with_compiler", "//third_party/java/junit", "//third_party/java/truth", ], diff --git a/javatests/dagger/functional/kotlinsrc/binds/RecursiveBindsTest.kt b/javatests/dagger/functional/kotlinsrc/binds/RecursiveBindsTest.kt new file mode 100644 index 00000000000..1654be2c8ae --- /dev/null +++ b/javatests/dagger/functional/kotlinsrc/binds/RecursiveBindsTest.kt @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023 The Dagger Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dagger.functional.kotlinsrc.binds + +import com.google.common.truth.Truth.assertThat +import dagger.Binds +import dagger.Component +import dagger.Module +import javax.inject.Inject +import javax.inject.Provider +import javax.inject.Singleton +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +// This is a regression test for b/267223822 where a scoped @Binds used in a cycle caused problems +// in fastInit mode. +@RunWith(JUnit4::class) +class RecursiveBindsTest { + + interface Foo {} + + class FooImpl internal @Inject constructor(@SuppressWarnings("unused") provider: Provider) : + Foo {} + + @Module + interface FooModule { + // This binding must be scoped to create the cycle. Otherwise without a scope, the generated + // code just doesn't have a field for this @Binds because we can directly use FooImpl's + // provider as they are equivalent. + @Binds @Singleton fun bindFoo(impl: FooImpl): Foo + } + + @Component(modules = FooModule::class) + @Singleton + interface TestSingletonComponent { + // We get the impl here to create a cycle where the impl factory needs to be delegated. + // That way the scoped binds (which does something like DoubleCheck.provider(implFactory)) is + // the one that would fail if it wasn't delegated properly. + fun getFooImplProvider(): Provider + } + + @Test + fun test() { + // Technically the NPE would happen when just initializing the component. + assertThat(DaggerRecursiveBindsTest_TestSingletonComponent.create().getFooImplProvider().get()) + .isNotNull() + } +} diff --git a/javatests/dagger/internal/codegen/InaccessibleTypeBindsTest.java b/javatests/dagger/internal/codegen/InaccessibleTypeBindsTest.java new file mode 100644 index 00000000000..f4eda9c4ad1 --- /dev/null +++ b/javatests/dagger/internal/codegen/InaccessibleTypeBindsTest.java @@ -0,0 +1,267 @@ +/* + * Copyright (C) 2023 The Dagger Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dagger.internal.codegen; + +import static com.google.testing.compile.CompilationSubject.assertThat; +import static dagger.internal.codegen.Compilers.compilerWithOptions; + +import com.google.common.collect.ImmutableList; +import com.google.testing.compile.Compilation; +import com.google.testing.compile.JavaFileObjects; +import dagger.testing.golden.GoldenFileRule; +import java.util.Collection; +import javax.tools.JavaFileObject; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class InaccessibleTypeBindsTest { + @Parameters(name = "{0}") + public static Collection parameters() { + return ImmutableList.copyOf( + new Object[][] { + {CompilerMode.DEFAULT_MODE}, + {CompilerMode.DEFAULT_JAVA7_MODE}, + {CompilerMode.FAST_INIT_MODE}, + // FastInit with Java7 is the mode that motivated this test, but do the other + // modes anyway for completeness. + {CompilerMode.FAST_INIT_JAVA7_MODE} + }); + } + + @Rule public GoldenFileRule goldenFileRule = new GoldenFileRule(); + + private final CompilerMode compilerMode; + + public InaccessibleTypeBindsTest(CompilerMode compilerMode) { + this.compilerMode = compilerMode; + } + + // Interface is accessible, but the impl is not. Use with a scoped binds to make sure type issues + // are handled from doing an assignment to the Provider from DoubleCheck.provider(fooImpl). + @Test + public void scopedInaccessibleTypeBound() throws Exception { + JavaFileObject foo = + JavaFileObjects.forSourceLines( + "test.Foo", + "package test;", + "", + "public interface Foo {", + "}"); + JavaFileObject fooImpl = + JavaFileObjects.forSourceLines( + "other.FooImpl", + "package other;", + "", + "import javax.inject.Inject;", + "import test.Foo;", + "", + "final class FooImpl implements Foo {", + " @Inject FooImpl() {}", + "}"); + JavaFileObject module = + JavaFileObjects.forSourceLines( + "other.TestModule", + "package other;", + "", + "import dagger.Module;", + "import dagger.Binds;", + "import javax.inject.Singleton;", + "import test.Foo;", + "", + "@Module", + "public interface TestModule {", + " @Binds", + " @Singleton", + " Foo bind(FooImpl impl);", + "}"); + JavaFileObject component = + JavaFileObjects.forSourceLines( + "test.TestComponent", + "package test;", + "", + "import dagger.Component;", + "import javax.inject.Provider;", + "import javax.inject.Singleton;", + "import other.TestModule;", + "", + "@Singleton", + "@Component(modules = TestModule.class)", + "interface TestComponent {", + " Foo getFoo();", + "}"); + + Compilation compilation = + compilerWithOptions(compilerMode) + .compile(foo, fooImpl, module, component); + assertThat(compilation).succeeded(); + assertThat(compilation) + .generatedSourceFile("test.DaggerTestComponent") + .hasSourceEquivalentTo(goldenFileRule.goldenFile("test.DaggerTestComponent")); + } + + // Interface is accessible, but the impl is not. Used with a binds in a loop to see if there are + // type issues from doing an assignment to the delegate factory e.g. + // DelegateFactory.setDelegate(provider, new SwitchingProvider(...)); + @Test + public void inaccessibleTypeBoundInALoop() throws Exception { + JavaFileObject foo = + JavaFileObjects.forSourceLines( + "test.Foo", + "package test;", + "", + "public interface Foo {", + "}"); + JavaFileObject fooImpl = + JavaFileObjects.forSourceLines( + "other.FooImpl", + "package other;", + "", + "import javax.inject.Inject;", + "import javax.inject.Provider;", + "import test.Foo;", + "", + "final class FooImpl implements Foo {", + " @Inject FooImpl(Provider fooProvider) {}", + "}"); + // Use another entry point to make FooImpl be the first requested class, that way FooImpl's + // provider is the one that is delegated. + JavaFileObject otherEntryPoint = + JavaFileObjects.forSourceLines( + "other.OtherEntryPoint", + "package other;", + "", + "import javax.inject.Inject;", + "", + "public final class OtherEntryPoint {", + " @Inject OtherEntryPoint(FooImpl impl) {}", + "}"); + JavaFileObject module = + JavaFileObjects.forSourceLines( + "other.TestModule", + "package other;", + "", + "import dagger.Module;", + "import dagger.Binds;", + "import test.Foo;", + "", + "@Module", + "public interface TestModule {", + " @Binds", + " Foo bind(FooImpl impl);", + "}"); + JavaFileObject component = + JavaFileObjects.forSourceLines( + "test.TestComponent", + "package test;", + "", + "import dagger.Component;", + "import other.OtherEntryPoint;", + "import other.TestModule;", + "", + "@Component(modules = TestModule.class)", + "interface TestComponent {", + " OtherEntryPoint getOtherEntryPoint();", + "}"); + + Compilation compilation = + compilerWithOptions(compilerMode) + .compile(foo, fooImpl, otherEntryPoint, module, component); + assertThat(compilation).succeeded(); + assertThat(compilation) + .generatedSourceFile("test.DaggerTestComponent") + .hasSourceEquivalentTo(goldenFileRule.goldenFile("test.DaggerTestComponent")); + } + + // Same as above but with the binding scoped. + @Test + public void inaccessibleTypeBoundInALoopScoped() throws Exception { + JavaFileObject foo = + JavaFileObjects.forSourceLines( + "test.Foo", + "package test;", + "", + "public interface Foo {", + "}"); + JavaFileObject fooImpl = + JavaFileObjects.forSourceLines( + "other.FooImpl", + "package other;", + "", + "import javax.inject.Inject;", + "import javax.inject.Provider;", + "import test.Foo;", + "", + "final class FooImpl implements Foo {", + " @Inject FooImpl(Provider fooProvider) {}", + "}"); + // Use another entry point to make FooImpl be the first requested class, that way FooImpl's + // provider is the one that is delegated. + JavaFileObject otherEntryPoint = + JavaFileObjects.forSourceLines( + "other.OtherEntryPoint", + "package other;", + "", + "import javax.inject.Inject;", + "", + "public final class OtherEntryPoint {", + " @Inject OtherEntryPoint(FooImpl impl) {}", + "}"); + JavaFileObject module = + JavaFileObjects.forSourceLines( + "other.TestModule", + "package other;", + "", + "import dagger.Module;", + "import dagger.Binds;", + "import javax.inject.Singleton;", + "import test.Foo;", + "", + "@Module", + "public interface TestModule {", + " @Binds", + " @Singleton", + " Foo bind(FooImpl impl);", + "}"); + JavaFileObject component = + JavaFileObjects.forSourceLines( + "test.TestComponent", + "package test;", + "", + "import dagger.Component;", + "import javax.inject.Singleton;", + "import other.OtherEntryPoint;", + "import other.TestModule;", + "", + "@Singleton", + "@Component(modules = TestModule.class)", + "interface TestComponent {", + " OtherEntryPoint getOtherEntryPoint();", + "}"); + + Compilation compilation = + compilerWithOptions(compilerMode) + .compile(foo, fooImpl, otherEntryPoint, module, component); + assertThat(compilation).succeeded(); + assertThat(compilation) + .generatedSourceFile("test.DaggerTestComponent") + .hasSourceEquivalentTo(goldenFileRule.goldenFile("test.DaggerTestComponent")); + } +} diff --git a/javatests/dagger/internal/codegen/goldens/AssistedFactoryTest_testAssistedFactoryCycle_FAST_INIT_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/AssistedFactoryTest_testAssistedFactoryCycle_FAST_INIT_MODE_test.DaggerTestComponent index 614aae3701a..48f517401b9 100644 --- a/javatests/dagger/internal/codegen/goldens/AssistedFactoryTest_testAssistedFactoryCycle_FAST_INIT_MODE_test.DaggerTestComponent +++ b/javatests/dagger/internal/codegen/goldens/AssistedFactoryTest_testAssistedFactoryCycle_FAST_INIT_MODE_test.DaggerTestComponent @@ -1,6 +1,7 @@ package test; import dagger.internal.DaggerGenerated; +import dagger.internal.DelegateFactory; import dagger.internal.SingleCheck; import javax.annotation.processing.Generated; import javax.inject.Provider; @@ -54,7 +55,8 @@ final class DaggerTestComponent { @SuppressWarnings("unchecked") private void initialize() { - this.fooFactoryProvider = SingleCheck.provider(new SwitchingProvider(testComponentImpl, 0)); + this.fooFactoryProvider = new DelegateFactory<>(); + DelegateFactory.setDelegate(fooFactoryProvider, SingleCheck.provider(new SwitchingProvider(testComponentImpl, 0))); } @Override diff --git a/javatests/dagger/internal/codegen/goldens/ComponentShardTest_testNewShardCreated_FAST_INIT_MODE_dagger.internal.codegen.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/ComponentShardTest_testNewShardCreated_FAST_INIT_MODE_dagger.internal.codegen.DaggerTestComponent index cc167c3f67a..06c68ee0be5 100644 --- a/javatests/dagger/internal/codegen/goldens/ComponentShardTest_testNewShardCreated_FAST_INIT_MODE_dagger.internal.codegen.DaggerTestComponent +++ b/javatests/dagger/internal/codegen/goldens/ComponentShardTest_testNewShardCreated_FAST_INIT_MODE_dagger.internal.codegen.DaggerTestComponent @@ -1,6 +1,7 @@ package dagger.internal.codegen; import dagger.internal.DaggerGenerated; +import dagger.internal.DelegateFactory; import dagger.internal.DoubleCheck; import javax.annotation.processing.Generated; import javax.inject.Provider; @@ -176,9 +177,10 @@ final class DaggerTestComponent { @SuppressWarnings("unchecked") private void initialize() { this.binding5Provider = DoubleCheck.provider(new SwitchingProvider(testComponentImpl, 3)); + this.binding2Provider = new DelegateFactory<>(); this.binding4Provider = DoubleCheck.provider(new SwitchingProvider(testComponentImpl, 2)); this.binding3Provider = DoubleCheck.provider(new SwitchingProvider(testComponentImpl, 1)); - this.binding2Provider = DoubleCheck.provider(new SwitchingProvider(testComponentImpl, 0)); + DelegateFactory.setDelegate(binding2Provider, DoubleCheck.provider(new SwitchingProvider(testComponentImpl, 0))); } private static final class SwitchingProvider implements Provider { @@ -250,5 +252,4 @@ final class DaggerTestComponent { } } } -} - +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_DEFAULT_JAVA7_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_DEFAULT_JAVA7_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..9e10117e4ba --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_DEFAULT_JAVA7_MODE_test.DaggerTestComponent @@ -0,0 +1,74 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DelegateFactory; +import dagger.internal.DoubleCheck; +import javax.annotation.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; +import other.OtherEntryPoint; +import other.OtherEntryPoint_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + private Provider bindProvider; + + @SuppressWarnings("rawtypes") + private Provider fooImplProvider; + + private TestComponentImpl() { + + initialize(); + + } + + private Object fooImpl() { + return FooImpl_Factory.newInstance(bindProvider); + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.bindProvider = new DelegateFactory<>(); + this.fooImplProvider = FooImpl_Factory.create(bindProvider); + DelegateFactory.setDelegate(bindProvider, DoubleCheck.provider((Provider) fooImplProvider)); + } + + @Override + public OtherEntryPoint getOtherEntryPoint() { + return OtherEntryPoint_Factory.newInstance(fooImpl()); + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_DEFAULT_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_DEFAULT_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..3a297299ed1 --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_DEFAULT_MODE_test.DaggerTestComponent @@ -0,0 +1,74 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DelegateFactory; +import dagger.internal.DoubleCheck; +import javax.annotation.processing.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; +import other.OtherEntryPoint; +import other.OtherEntryPoint_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + private Provider bindProvider; + + @SuppressWarnings("rawtypes") + private Provider fooImplProvider; + + private TestComponentImpl() { + + initialize(); + + } + + private Object fooImpl() { + return FooImpl_Factory.newInstance(bindProvider); + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.bindProvider = new DelegateFactory<>(); + this.fooImplProvider = FooImpl_Factory.create(bindProvider); + DelegateFactory.setDelegate(bindProvider, DoubleCheck.provider((Provider) fooImplProvider)); + } + + @Override + public OtherEntryPoint getOtherEntryPoint() { + return OtherEntryPoint_Factory.newInstance(fooImpl()); + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..9642f338144 --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent @@ -0,0 +1,96 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DelegateFactory; +import dagger.internal.DoubleCheck; +import javax.annotation.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; +import other.OtherEntryPoint; +import other.OtherEntryPoint_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + private Provider bindProvider; + + @SuppressWarnings("rawtypes") + private Provider fooImplProvider; + + private TestComponentImpl() { + + initialize(); + + } + + private Object fooImpl() { + return FooImpl_Factory.newInstance(bindProvider); + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.bindProvider = new DelegateFactory<>(); + this.fooImplProvider = new SwitchingProvider(testComponentImpl, 0); + DelegateFactory.setDelegate(bindProvider, DoubleCheck.provider((Provider) fooImplProvider)); + } + + @Override + public OtherEntryPoint getOtherEntryPoint() { + return OtherEntryPoint_Factory.newInstance(fooImpl()); + } + + private static final class SwitchingProvider implements Provider { + private final TestComponentImpl testComponentImpl; + + private final int id; + + SwitchingProvider(TestComponentImpl testComponentImpl, int id) { + this.testComponentImpl = testComponentImpl; + this.id = id; + } + + @SuppressWarnings("unchecked") + @Override + public T get() { + switch (id) { + case 0: // other.FooImpl + return (T) FooImpl_Factory.newInstance(testComponentImpl.bindProvider); + + default: throw new AssertionError(id); + } + } + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_FAST_INIT_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_FAST_INIT_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..fd92c6d025a --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoopScoped_FAST_INIT_MODE_test.DaggerTestComponent @@ -0,0 +1,96 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DelegateFactory; +import dagger.internal.DoubleCheck; +import javax.annotation.processing.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; +import other.OtherEntryPoint; +import other.OtherEntryPoint_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + private Provider bindProvider; + + @SuppressWarnings("rawtypes") + private Provider fooImplProvider; + + private TestComponentImpl() { + + initialize(); + + } + + private Object fooImpl() { + return FooImpl_Factory.newInstance(bindProvider); + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.bindProvider = new DelegateFactory<>(); + this.fooImplProvider = new SwitchingProvider<>(testComponentImpl, 0); + DelegateFactory.setDelegate(bindProvider, DoubleCheck.provider((Provider) fooImplProvider)); + } + + @Override + public OtherEntryPoint getOtherEntryPoint() { + return OtherEntryPoint_Factory.newInstance(fooImpl()); + } + + private static final class SwitchingProvider implements Provider { + private final TestComponentImpl testComponentImpl; + + private final int id; + + SwitchingProvider(TestComponentImpl testComponentImpl, int id) { + this.testComponentImpl = testComponentImpl; + this.id = id; + } + + @SuppressWarnings("unchecked") + @Override + public T get() { + switch (id) { + case 0: // other.FooImpl + return (T) FooImpl_Factory.newInstance(testComponentImpl.bindProvider); + + default: throw new AssertionError(id); + } + } + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_DEFAULT_JAVA7_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_DEFAULT_JAVA7_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..e377365d422 --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_DEFAULT_JAVA7_MODE_test.DaggerTestComponent @@ -0,0 +1,70 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DelegateFactory; +import javax.annotation.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; +import other.OtherEntryPoint; +import other.OtherEntryPoint_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + @SuppressWarnings("rawtypes") + private Provider fooImplProvider; + + private TestComponentImpl() { + + initialize(); + + } + + private Object fooImpl() { + return FooImpl_Factory.newInstance(fooImplProvider); + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.fooImplProvider = new DelegateFactory<>(); + DelegateFactory.setDelegate(fooImplProvider, FooImpl_Factory.create(fooImplProvider)); + } + + @Override + public OtherEntryPoint getOtherEntryPoint() { + return OtherEntryPoint_Factory.newInstance(fooImpl()); + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_DEFAULT_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_DEFAULT_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..8e032111205 --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_DEFAULT_MODE_test.DaggerTestComponent @@ -0,0 +1,70 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DelegateFactory; +import javax.annotation.processing.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; +import other.OtherEntryPoint; +import other.OtherEntryPoint_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + @SuppressWarnings("rawtypes") + private Provider fooImplProvider; + + private TestComponentImpl() { + + initialize(); + + } + + private Object fooImpl() { + return FooImpl_Factory.newInstance(fooImplProvider); + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.fooImplProvider = new DelegateFactory<>(); + DelegateFactory.setDelegate(fooImplProvider, FooImpl_Factory.create(fooImplProvider)); + } + + @Override + public OtherEntryPoint getOtherEntryPoint() { + return OtherEntryPoint_Factory.newInstance(fooImpl()); + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..c6db8da9b34 --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent @@ -0,0 +1,92 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DelegateFactory; +import javax.annotation.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; +import other.OtherEntryPoint; +import other.OtherEntryPoint_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + @SuppressWarnings("rawtypes") + private Provider fooImplProvider; + + private TestComponentImpl() { + + initialize(); + + } + + private Object fooImpl() { + return FooImpl_Factory.newInstance(fooImplProvider); + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.fooImplProvider = new DelegateFactory<>(); + DelegateFactory.setDelegate(fooImplProvider, new SwitchingProvider(testComponentImpl, 0)); + } + + @Override + public OtherEntryPoint getOtherEntryPoint() { + return OtherEntryPoint_Factory.newInstance(fooImpl()); + } + + private static final class SwitchingProvider implements Provider { + private final TestComponentImpl testComponentImpl; + + private final int id; + + SwitchingProvider(TestComponentImpl testComponentImpl, int id) { + this.testComponentImpl = testComponentImpl; + this.id = id; + } + + @SuppressWarnings("unchecked") + @Override + public T get() { + switch (id) { + case 0: // other.FooImpl + return (T) FooImpl_Factory.newInstance(testComponentImpl.fooImplProvider); + + default: throw new AssertionError(id); + } + } + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_FAST_INIT_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_FAST_INIT_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..137cbcfe22e --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_inaccessibleTypeBoundInALoop_FAST_INIT_MODE_test.DaggerTestComponent @@ -0,0 +1,92 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DelegateFactory; +import javax.annotation.processing.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; +import other.OtherEntryPoint; +import other.OtherEntryPoint_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + @SuppressWarnings("rawtypes") + private Provider fooImplProvider; + + private TestComponentImpl() { + + initialize(); + + } + + private Object fooImpl() { + return FooImpl_Factory.newInstance(fooImplProvider); + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.fooImplProvider = new DelegateFactory<>(); + DelegateFactory.setDelegate(fooImplProvider, new SwitchingProvider<>(testComponentImpl, 0)); + } + + @Override + public OtherEntryPoint getOtherEntryPoint() { + return OtherEntryPoint_Factory.newInstance(fooImpl()); + } + + private static final class SwitchingProvider implements Provider { + private final TestComponentImpl testComponentImpl; + + private final int id; + + SwitchingProvider(TestComponentImpl testComponentImpl, int id) { + this.testComponentImpl = testComponentImpl; + this.id = id; + } + + @SuppressWarnings("unchecked") + @Override + public T get() { + switch (id) { + case 0: // other.FooImpl + return (T) FooImpl_Factory.newInstance(testComponentImpl.fooImplProvider); + + default: throw new AssertionError(id); + } + } + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_DEFAULT_JAVA7_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_DEFAULT_JAVA7_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..d39656c9ba2 --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_DEFAULT_JAVA7_MODE_test.DaggerTestComponent @@ -0,0 +1,62 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DoubleCheck; +import javax.annotation.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + private Provider bindProvider; + + private TestComponentImpl() { + + initialize(); + + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.bindProvider = DoubleCheck.provider((Provider) FooImpl_Factory.create()); + } + + @Override + public Foo getFoo() { + return bindProvider.get(); + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_DEFAULT_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_DEFAULT_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..19d8352ccc9 --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_DEFAULT_MODE_test.DaggerTestComponent @@ -0,0 +1,62 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DoubleCheck; +import javax.annotation.processing.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + private Provider bindProvider; + + private TestComponentImpl() { + + initialize(); + + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.bindProvider = DoubleCheck.provider((Provider) FooImpl_Factory.create()); + } + + @Override + public Foo getFoo() { + return bindProvider.get(); + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..7c0c68df2ff --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent @@ -0,0 +1,88 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DoubleCheck; +import javax.annotation.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + @SuppressWarnings("rawtypes") + private Provider fooImplProvider; + + private Provider bindProvider; + + private TestComponentImpl() { + + initialize(); + + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.fooImplProvider = new SwitchingProvider(testComponentImpl, 0); + this.bindProvider = DoubleCheck.provider((Provider) fooImplProvider); + } + + @Override + public Foo getFoo() { + return bindProvider.get(); + } + + private static final class SwitchingProvider implements Provider { + private final TestComponentImpl testComponentImpl; + + private final int id; + + SwitchingProvider(TestComponentImpl testComponentImpl, int id) { + this.testComponentImpl = testComponentImpl; + this.id = id; + } + + @SuppressWarnings("unchecked") + @Override + public T get() { + switch (id) { + case 0: // other.FooImpl + return (T) FooImpl_Factory.newInstance(); + + default: throw new AssertionError(id); + } + } + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_FAST_INIT_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_FAST_INIT_MODE_test.DaggerTestComponent new file mode 100644 index 00000000000..922d2938d92 --- /dev/null +++ b/javatests/dagger/internal/codegen/goldens/InaccessibleTypeBindsTest_scopedInaccessibleTypeBound_FAST_INIT_MODE_test.DaggerTestComponent @@ -0,0 +1,88 @@ +package test; + +import dagger.internal.DaggerGenerated; +import dagger.internal.DoubleCheck; +import javax.annotation.processing.Generated; +import javax.inject.Provider; +import other.FooImpl_Factory; + +@DaggerGenerated +@Generated( + value = "dagger.internal.codegen.ComponentProcessor", + comments = "https://dagger.dev" +) +@SuppressWarnings({ + "unchecked", + "rawtypes", + "KotlinInternal", + "KotlinInternalInJava" +}) +final class DaggerTestComponent { + private DaggerTestComponent() { + } + + public static Builder builder() { + return new Builder(); + } + + public static TestComponent create() { + return new Builder().build(); + } + + static final class Builder { + private Builder() { + } + + public TestComponent build() { + return new TestComponentImpl(); + } + } + + private static final class TestComponentImpl implements TestComponent { + private final TestComponentImpl testComponentImpl = this; + + @SuppressWarnings("rawtypes") + private Provider fooImplProvider; + + private Provider bindProvider; + + private TestComponentImpl() { + + initialize(); + + } + + @SuppressWarnings("unchecked") + private void initialize() { + this.fooImplProvider = new SwitchingProvider<>(testComponentImpl, 0); + this.bindProvider = DoubleCheck.provider((Provider) fooImplProvider); + } + + @Override + public Foo getFoo() { + return bindProvider.get(); + } + + private static final class SwitchingProvider implements Provider { + private final TestComponentImpl testComponentImpl; + + private final int id; + + SwitchingProvider(TestComponentImpl testComponentImpl, int id) { + this.testComponentImpl = testComponentImpl; + this.id = id; + } + + @SuppressWarnings("unchecked") + @Override + public T get() { + switch (id) { + case 0: // other.FooImpl + return (T) FooImpl_Factory.newInstance(); + + default: throw new AssertionError(id); + } + } + } + } +} \ No newline at end of file diff --git a/javatests/dagger/internal/codegen/goldens/OptionalBindingRequestFulfillmentTest_inlinedOptionalBindings_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent b/javatests/dagger/internal/codegen/goldens/OptionalBindingRequestFulfillmentTest_inlinedOptionalBindings_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent index f72599e2b1f..f99b125ccc6 100644 --- a/javatests/dagger/internal/codegen/goldens/OptionalBindingRequestFulfillmentTest_inlinedOptionalBindings_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent +++ b/javatests/dagger/internal/codegen/goldens/OptionalBindingRequestFulfillmentTest_inlinedOptionalBindings_FAST_INIT_JAVA7_MODE_test.DaggerTestComponent @@ -65,7 +65,7 @@ final class DaggerTestComponent { @SuppressWarnings("unchecked") private void initialize() { - this.provideMaybeProvider = new SwitchingProvider<>(testComponentImpl, 0); + this.provideMaybeProvider = new SwitchingProvider(testComponentImpl, 0); } @Override