Skip to content

Commit

Permalink
[Refactor]: Move FrameworkInstanceSupplier logic directly into `Pro…
Browse files Browse the repository at this point in the history
…viderInstanceRequestRepresentation`.

In this case there's no need to pass in the `FrameworkInstanceSupplier` as an assisted parameter since we can derive it directly in `ProviderInstanceRequestRepresentation` using other injected objects.

RELNOTES=N/A
PiperOrigin-RevId: 573928235
  • Loading branch information
bcorso authored and Dagger Team committed Oct 16, 2023
1 parent 740a7c6 commit d7dd656
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ final class FrameworkInstanceBindingRepresentation {
FrameworkInstanceBindingRepresentation(
@Assisted ProvisionBinding binding,
BindingGraph graph,
@Assisted FrameworkInstanceSupplier providerField,
ComponentImplementation componentImplementation,
DelegateRequestRepresentation.Factory delegateRequestRepresentationFactory,
DerivedFromFrameworkInstanceRequestRepresentation.Factory
Expand All @@ -65,7 +64,7 @@ final class FrameworkInstanceBindingRepresentation {
this.providerRequestRepresentation =
binding.kind().equals(DELEGATE) && !needsCaching(binding, graph)
? delegateRequestRepresentationFactory.create(binding, RequestKind.PROVIDER)
: providerInstanceRequestRepresentationFactory.create(binding, providerField);
: providerInstanceRequestRepresentationFactory.create(binding);
this.producerFromProviderRepresentation =
producerNodeInstanceRequestRepresentationFactory.create(
binding,
Expand Down Expand Up @@ -108,7 +107,6 @@ private RequestRepresentation getRequestRepresentationUncached(BindingRequest re

@AssistedFactory
static interface Factory {
FrameworkInstanceBindingRepresentation create(
ProvisionBinding binding, FrameworkInstanceSupplier providerField);
FrameworkInstanceBindingRepresentation create(ProvisionBinding binding);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,57 @@
import dagger.assisted.Assisted;
import dagger.assisted.AssistedFactory;
import dagger.assisted.AssistedInject;
import dagger.internal.codegen.binding.ContributionBinding;
import dagger.internal.codegen.binding.FrameworkType;
import dagger.internal.codegen.binding.ProvisionBinding;

/** Binding expression for provider instances. */
final class ProviderInstanceRequestRepresentation extends FrameworkInstanceRequestRepresentation {

@AssistedInject
ProviderInstanceRequestRepresentation(
@Assisted ContributionBinding binding,
@Assisted FrameworkInstanceSupplier frameworkInstanceSupplier,
@Assisted ProvisionBinding binding,
SwitchingProviderInstanceSupplier.Factory switchingProviderInstanceSupplierFactory,
StaticFactoryInstanceSupplier.Factory staticFactoryInstanceSupplierFactory,
ProviderInstanceSupplier.Factory providerInstanceSupplierFactory,
ComponentImplementation componentImplementation,
XProcessingEnv processingEnv) {
super(binding, frameworkInstanceSupplier, processingEnv);
super(
binding,
frameworkInstanceSupplier(
binding,
switchingProviderInstanceSupplierFactory,
staticFactoryInstanceSupplierFactory,
providerInstanceSupplierFactory,
componentImplementation),
processingEnv);
}

@Override
protected FrameworkType frameworkType() {
return FrameworkType.PROVIDER;
}

private static FrameworkInstanceSupplier frameworkInstanceSupplier(
ProvisionBinding binding,
SwitchingProviderInstanceSupplier.Factory switchingProviderInstanceSupplierFactory,
StaticFactoryInstanceSupplier.Factory staticFactoryInstanceSupplierFactory,
ProviderInstanceSupplier.Factory providerInstanceSupplierFactory,
ComponentImplementation componentImplementation) {
FrameworkInstanceKind frameworkInstanceKind =
FrameworkInstanceKind.from(binding, componentImplementation.compilerMode());
switch (frameworkInstanceKind) {
case SWITCHING_PROVIDER:
return switchingProviderInstanceSupplierFactory.create(binding);
case STATIC_FACTORY:
return staticFactoryInstanceSupplierFactory.create(binding);
case PROVIDER_FIELD:
return providerInstanceSupplierFactory.create(binding);
}
throw new AssertionError("Unexpected FrameworkInstanceKind: " + frameworkInstanceKind);
}

@AssistedFactory
static interface Factory {
ProviderInstanceRequestRepresentation create(
ContributionBinding binding, FrameworkInstanceSupplier frameworkInstanceSupplier);
ProviderInstanceRequestRepresentation create(ProvisionBinding binding);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import dagger.internal.codegen.binding.BindingGraph;
import dagger.internal.codegen.binding.BindingRequest;
import dagger.internal.codegen.binding.ProvisionBinding;
import dagger.internal.codegen.compileroption.CompilerOptions;
import dagger.internal.codegen.model.RequestKind;
import dagger.internal.codegen.writing.ComponentImplementation.CompilerMode;

Expand All @@ -43,33 +42,17 @@ final class ProvisionBindingRepresentation implements BindingRepresentation {
@AssistedInject
ProvisionBindingRepresentation(
@Assisted ProvisionBinding binding,
BindingGraph graph,
ComponentImplementation componentImplementation,
DirectInstanceBindingRepresentation.Factory directInstanceBindingRepresentationFactory,
FrameworkInstanceBindingRepresentation.Factory frameworkInstanceBindingRepresentationFactory,
SwitchingProviderInstanceSupplier.Factory switchingProviderInstanceSupplierFactory,
ProviderInstanceSupplier.Factory providerInstanceSupplierFactory,
StaticFactoryInstanceSupplier.Factory staticFactoryInstanceSupplierFactory,
CompilerOptions compilerOptions) {
BindingGraph graph,
ComponentImplementation componentImplementation) {
this.binding = binding;
this.graph = graph;
this.compilerMode = componentImplementation.compilerMode();
this.directInstanceBindingRepresentation =
directInstanceBindingRepresentationFactory.create(binding);
FrameworkInstanceSupplier frameworkInstanceSupplier = null;
switch (FrameworkInstanceKind.from(binding, compilerMode)) {
case SWITCHING_PROVIDER:
frameworkInstanceSupplier = switchingProviderInstanceSupplierFactory.create(binding);
break;
case STATIC_FACTORY:
frameworkInstanceSupplier = staticFactoryInstanceSupplierFactory.create(binding);
break;
case PROVIDER_FIELD:
frameworkInstanceSupplier = providerInstanceSupplierFactory.create(binding);
break;
}
this.frameworkInstanceBindingRepresentation =
frameworkInstanceBindingRepresentationFactory.create(binding, frameworkInstanceSupplier);
frameworkInstanceBindingRepresentationFactory.create(binding);
}

@Override
Expand Down

0 comments on commit d7dd656

Please sign in to comment.