Add static switching providers to androidExperimentalAndroidMode2
In order to share some of the logic with the previous SwitchingProviders implementation, I've refactored the core logic into SwitchingProviders and the implementation specific logic into two separate classes: InnerSwitchingProviders and StaticSwitchingProviders.
RELNOTES=n/a
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=193934094
diff --git a/java/dagger/internal/codegen/ComponentBindingExpressions.java b/java/dagger/internal/codegen/ComponentBindingExpressions.java
index e86a856..57a23ed 100644
--- a/java/dagger/internal/codegen/ComponentBindingExpressions.java
+++ b/java/dagger/internal/codegen/ComponentBindingExpressions.java
@@ -68,7 +68,8 @@
private final DaggerElements elements;
private final CompilerOptions compilerOptions;
private final MembersInjectionMethods membersInjectionMethods;
- private final SwitchingProviders switchingProviders;
+ private final InnerSwitchingProviders innerSwitchingProviders;
+ private final StaticSwitchingProviders staticSwitchingProviders;
private final Table<Key, RequestKind, BindingExpression> expressions = HashBasedTable.create();
ComponentBindingExpressions(
@@ -87,6 +88,7 @@
subcomponentNames,
componentRequirementFields,
new ReferenceReleasingManagerFields(graph, generatedComponentModel),
+ new StaticSwitchingProviders(generatedComponentModel, types),
optionalFactories,
types,
elements,
@@ -100,6 +102,7 @@
SubcomponentNames subcomponentNames,
ComponentRequirementFields componentRequirementFields,
ReferenceReleasingManagerFields referenceReleasingManagerFields,
+ StaticSwitchingProviders staticSwitchingProviders,
OptionalFactories optionalFactories,
DaggerTypes types,
DaggerElements elements,
@@ -116,7 +119,9 @@
this.compilerOptions = checkNotNull(compilerOptions);
this.membersInjectionMethods =
new MembersInjectionMethods(generatedComponentModel, this, graph, elements, types);
- this.switchingProviders = new SwitchingProviders(generatedComponentModel, this, types);
+ this.innerSwitchingProviders =
+ new InnerSwitchingProviders(generatedComponentModel, this, types);
+ this.staticSwitchingProviders = staticSwitchingProviders;
}
/**
@@ -133,6 +138,7 @@
subcomponentNames,
childComponentRequirementFields,
referenceReleasingManagerFields,
+ staticSwitchingProviders,
optionalFactories,
types,
elements,
@@ -355,7 +361,9 @@
case INJECTION:
case PROVISION:
- return new InjectionOrProvisionProviderCreationExpression(binding, this);
+ return compilerOptions.experimentalAndroidMode2()
+ ? staticSwitchingProviders.newCreationExpression(binding, this)
+ : new InjectionOrProvisionProviderCreationExpression(binding, this);
case COMPONENT_PRODUCTION:
return new DependencyMethodProducerCreationExpression(
@@ -589,7 +597,8 @@
* {@code SetFactory}.
*/
private boolean useStaticFactoryCreation(ContributionBinding binding) {
- return !compilerOptions.experimentalAndroidMode()
+ return !(compilerOptions.experimentalAndroidMode2()
+ || compilerOptions.experimentalAndroidMode())
|| binding.kind().equals(MULTIBOUND_MAP)
|| binding.kind().equals(MULTIBOUND_SET);
}
@@ -630,7 +639,7 @@
return wrapInMethod(
resolvedBindings,
RequestKind.PROVIDER,
- switchingProviders.newBindingExpression(resolvedBindings.contributionBinding()));
+ innerSwitchingProviders.newBindingExpression(resolvedBindings.contributionBinding()));
}
} else if (resolvedBindings.contributionBinding().kind().equals(DELEGATE)
&& !needsCaching(resolvedBindings)) {