Skip to content

Commit

Permalink
Remove unnecessary abstraction in SwitchingProviders#build().
Browse files Browse the repository at this point in the history
This was left around from when SwitchingProviders was had multiple implementations, but it isn't needed anymore.

RELNOTES=N/A
PiperOrigin-RevId: 373428747
  • Loading branch information
bcorso authored and Dagger Team committed May 12, 2021
1 parent 1411eee commit ee969fb
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions java/dagger/internal/codegen/writing/SwitchingProviders.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,6 @@ Expression getDependencyExpression(ClassName requestingClass) {
};
}

/** Returns the {@link TypeSpec} for a {@code SwitchingProvider} based on the given builder. */
TypeSpec createSwitchingProviderType(TypeSpec.Builder builder) {
return builder
.addModifiers(PRIVATE, FINAL)
.addField(TypeName.INT, "id", PRIVATE, FINAL)
.addMethod(
MethodSpec.constructorBuilder()
.addParameter(TypeName.INT, "id")
.addStatement("this.id = id")
.build())
.build();
}

private SwitchingProviderBuilder getSwitchingProviderBuilder() {
if (switchingProviderBuilders.size() % MAX_CASES_PER_CLASS == 0) {
String name = switchingProviderNames.getUniqueName("SwitchingProvider");
Expand Down Expand Up @@ -175,11 +162,18 @@ private CodeBlock createSwitchCaseCodeBlock(Key key) {
}

private TypeSpec build() {
return createSwitchingProviderType(
classBuilder(switchingProviderType)
.addTypeVariable(T)
.addSuperinterface(providerOf(T))
.addMethods(getMethods()));
return classBuilder(switchingProviderType)
.addTypeVariable(T)
.addSuperinterface(providerOf(T))
.addMethods(getMethods())
.addModifiers(PRIVATE, FINAL)
.addField(TypeName.INT, "id", PRIVATE, FINAL)
.addMethod(
MethodSpec.constructorBuilder()
.addParameter(TypeName.INT, "id")
.addStatement("this.id = id")
.build())
.build();
}

private ImmutableList<MethodSpec> getMethods() {
Expand Down

0 comments on commit ee969fb

Please sign in to comment.