Skip to content

Commit

Permalink
Merge ComponentImplementationBuilder into ComponentImplementation.
Browse files Browse the repository at this point in the history
This CL moves all of the ComponentImplementation generation logic into ComponentImplementation and deletes ComponentImplementationBuilder. Before this CL, the generation logic was split across both files, making it difficult to find and understand the order in which things are generated into the component TypeSpec.

RELNOTES=N/A
PiperOrigin-RevId: 377978631
  • Loading branch information
bcorso authored and Dagger Team committed Jun 7, 2021
1 parent 627dc7a commit d3fccc3
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 346 deletions.
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package dagger.internal.codegen.componentgenerator;
package dagger.internal.codegen.binding;

import static dagger.internal.codegen.extension.DaggerStreams.toImmutableList;

Expand All @@ -31,15 +31,15 @@

/** A class that defines proper {@code equals} and {@code hashcode} for a method signature. */
@AutoValue
abstract class MethodSignature {
public abstract class MethodSignature {

abstract String name();

abstract ImmutableList<? extends Equivalence.Wrapper<? extends TypeMirror>> parameterTypes();

abstract ImmutableList<? extends Equivalence.Wrapper<? extends TypeMirror>> thrownTypes();

static MethodSignature forComponentMethod(
public static MethodSignature forComponentMethod(
ComponentMethodDescriptor componentMethod, DeclaredType componentType, DaggerTypes types) {
ExecutableType methodType =
MoreTypes.asExecutable(types.asMemberOf(componentType, componentMethod.methodElement()));
Expand Down
Expand Up @@ -26,23 +26,24 @@
import dagger.internal.codegen.binding.BindingGraph;
import dagger.internal.codegen.langmodel.DaggerElements;
import dagger.internal.codegen.writing.ComponentImplementation;
import java.util.Optional;
import javax.annotation.processing.Filer;
import javax.inject.Inject;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;

/** Generates the implementation of the abstract types annotated with {@link Component}. */
final class ComponentGenerator extends SourceFileGenerator<BindingGraph> {
private final ComponentImplementationFactory componentImplementationFactory;
private final TopLevelImplementationComponent.Factory topLevelImplementationComponentFactory;

@Inject
ComponentGenerator(
Filer filer,
DaggerElements elements,
SourceVersion sourceVersion,
ComponentImplementationFactory componentImplementationFactory) {
TopLevelImplementationComponent.Factory topLevelImplementationComponentFactory) {
super(filer, elements, sourceVersion);
this.componentImplementationFactory = componentImplementationFactory;
this.topLevelImplementationComponentFactory = topLevelImplementationComponentFactory;
}

@Override
Expand All @@ -53,7 +54,15 @@ public Element originatingElement(BindingGraph input) {
@Override
public ImmutableList<TypeSpec.Builder> topLevelTypes(BindingGraph bindingGraph) {
ComponentImplementation componentImplementation =
componentImplementationFactory.createComponentImplementation(bindingGraph);
topLevelImplementationComponentFactory
.create(bindingGraph)
.currentImplementationSubcomponentBuilder()
.bindingGraph(bindingGraph)
.parentImplementation(Optional.empty())
.parentBindingExpressions(Optional.empty())
.parentRequirementExpressions(Optional.empty())
.build()
.componentImplementation();
verify(
componentImplementation
.name()
Expand Down
Expand Up @@ -45,6 +45,7 @@
import dagger.internal.codegen.binding.ComponentCreatorKind;
import dagger.internal.codegen.binding.ComponentDescriptor;
import dagger.internal.codegen.binding.ComponentRequirement;
import dagger.internal.codegen.binding.MethodSignature;
import dagger.internal.codegen.kotlin.KotlinMetadataUtil;
import dagger.internal.codegen.langmodel.DaggerElements;
import dagger.internal.codegen.langmodel.DaggerTypes;
Expand Down

This file was deleted.

0 comments on commit d3fccc3

Please sign in to comment.