Skip to content

Commit

Permalink
Remove producer dependency from Dagger's compiler.
Browse files Browse the repository at this point in the history
There's no technical reason for Dagger's compiler to depend on Dagger Producers. In all of these cases we were pulling in producers just for either the class name or javadoc.

RELNOTES=N/A
PiperOrigin-RevId: 575923018
  • Loading branch information
bcorso authored and Dagger Team committed Oct 26, 2023
1 parent 877a2df commit 2bf1327
Show file tree
Hide file tree
Showing 27 changed files with 72 additions and 121 deletions.
1 change: 0 additions & 1 deletion java/dagger/internal/codegen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ gen_maven_artifact(
],
artifact_target_maven_deps = [
"com.google.code.findbugs:jsr305",
"com.google.dagger:dagger-producers",
"com.google.dagger:dagger-spi",
"com.google.dagger:dagger",
"com.google.devtools.ksp:symbol-processing-api",
Expand Down
3 changes: 0 additions & 3 deletions java/dagger/internal/codegen/binding/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ java_library(
"//java/dagger/internal/codegen/extension",
"//java/dagger/internal/codegen/javapoet",
"//java/dagger/internal/codegen/kotlin",
"//java/dagger/internal/codegen/langmodel",
"//java/dagger/internal/codegen/model",
"//java/dagger/internal/codegen/xprocessing",
"//java/dagger/producers",
"//third_party/java/auto:common",
"//third_party/java/auto:value",
"//third_party/java/error_prone:annotations",
"//third_party/java/guava/base",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import dagger.internal.codegen.model.Key;
import dagger.internal.codegen.model.Scope;
import dagger.internal.codegen.xprocessing.XTypeElements;
import dagger.producers.internal.ProductionExecutorModule;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
Expand Down Expand Up @@ -292,7 +291,7 @@ private ModuleDescriptor descriptorForMonitoringModule(XTypeElement componentDef
processingEnv, generatedMonitoringModuleName(componentDefinitionType)));
}

/** Returns a descriptor {@link ProductionExecutorModule}. */
/** Returns a descriptor {@code ProductionExecutorModule}. */
private ModuleDescriptor descriptorForProductionExecutorModule() {
return moduleDescriptorFactory.create(
processingEnv.findTypeElement(TypeNames.PRODUCTION_EXECTUTOR_MODULE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
import androidx.room.compiler.processing.XElement;
import androidx.room.compiler.processing.XProcessingEnv;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import dagger.Provides;
import dagger.internal.codegen.base.Formatter;
import dagger.internal.codegen.model.DaggerAnnotation;
import dagger.internal.codegen.model.DependencyRequest;
import dagger.internal.codegen.xprocessing.XTypes;
import dagger.producers.Produces;
import java.util.Optional;
import javax.inject.Inject;

Expand All @@ -43,8 +41,7 @@
* <dd>{@code @Qualifier SomeType is provided at\n ComponentType.method()}
* <dt>For component injection methods
* <dd>{@code SomeType is injected at\n ComponentType.method(foo)}
* <dt>For parameters to {@link Provides @Provides}, {@link Produces @Produces}, or {@link
* Inject @Inject} methods:
* <dt>For parameters to {@code @Provides}, {@code @Produces}, or {@code @Inject} methods:
* <dd>{@code @Qualified ResolvedType is injected at\n EnclosingType.method([…, ]param[, …])}
* <dt>For parameters to {@link Inject @Inject} constructors:
* <dd>{@code @Qualified ResolvedType is injected at\n EnclosingType([…, ]param[, …])}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import static dagger.internal.codegen.binding.BindingType.PRODUCTION;

import dagger.internal.codegen.model.RequestKind;
import dagger.producers.Producer;
import javax.inject.Provider;

/**
* A mapper for associating a {@link RequestKind} to a {@link FrameworkType}, dependent on the type
* of code to be generated (e.g., for {@link Provider} or {@link Producer}).
* of code to be generated (e.g., for {@code Provider} or {@code Producer}).
*/
public enum FrameworkTypeMapper {
FOR_PROVIDER() {
Expand Down
2 changes: 2 additions & 0 deletions java/dagger/internal/codegen/javapoet/TypeNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public final class TypeNames {
// Dagger Producers classnames
public static final ClassName ABSTRACT_PRODUCER =
ClassName.get("dagger.producers.internal", "AbstractProducer");
public static final ClassName ABSTRACT_PRODUCES_METHOD_PRODUCER =
ClassName.get("dagger.producers.internal", "AbstractProducesMethodProducer");
public static final ClassName CANCELLATION_LISTENER =
ClassName.get("dagger.producers.internal", "CancellationListener");
public static final ClassName CANCELLATION_POLICY =
Expand Down
2 changes: 0 additions & 2 deletions java/dagger/internal/codegen/model/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ java_library(
"//java/dagger:core",
"//java/dagger/internal/codegen/extension",
"//java/dagger/internal/codegen/xprocessing",
"//java/dagger/producers",
"//java/dagger/spi",
"//third_party/java/auto:common",
"//third_party/java/auto:value",
"//third_party/java/guava/base",
Expand Down
15 changes: 5 additions & 10 deletions java/dagger/internal/codegen/model/RequestKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;

import dagger.Lazy;
import dagger.producers.Produced;
import dagger.producers.Producer;
import javax.inject.Provider;

/**
* Represents the different kinds of {@link javax.lang.model.type.TypeMirror types} that may be
* requested as dependencies for the same key. For example, {@code String}, {@code
Expand All @@ -35,13 +30,13 @@ public enum RequestKind {
/** A default request for an instance. E.g.: {@code FooType} */
INSTANCE,

/** A request for a {@link Provider}. E.g.: {@code Provider<FooType>} */
/** A request for a {@code Provider}. E.g.: {@code Provider<FooType>} */
PROVIDER,

/** A request for a {@link Lazy}. E.g.: {@code Lazy<FooType>} */
/** A request for a {@code Lazy}. E.g.: {@code Lazy<FooType>} */
LAZY,

/** A request for a {@link Provider} of a {@link Lazy}. E.g.: {@code Provider<Lazy<FooType>>} */
/** A request for a {@code Provider} of a {@code Lazy}. E.g.: {@code Provider<Lazy<FooType>>}. */
PROVIDER_OF_LAZY,

/**
Expand All @@ -50,10 +45,10 @@ public enum RequestKind {
*/
MEMBERS_INJECTION,

/** A request for a {@link Producer}. E.g.: {@code Producer<FooType>} */
/** A request for a {@code Producer}. E.g.: {@code Producer<FooType>} */
PRODUCER,

/** A request for a {@link Produced}. E.g.: {@code Produced<FooType>} */
/** A request for a {@code Produced}. E.g.: {@code Produced<FooType>} */
PRODUCED,

/**
Expand Down
2 changes: 0 additions & 2 deletions java/dagger/internal/codegen/writing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ java_library(
"//java/dagger/internal/codegen/compileroption",
"//java/dagger/internal/codegen/extension",
"//java/dagger/internal/codegen/javapoet",
"//java/dagger/internal/codegen/kotlin",
"//java/dagger/internal/codegen/langmodel",
"//java/dagger/internal/codegen/model",
"//java/dagger/internal/codegen/xprocessing",
"//java/dagger/producers",
"//third_party/java/auto:common",
"//third_party/java/auto:value",
"//third_party/java/error_prone:annotations",
Expand Down
11 changes: 5 additions & 6 deletions java/dagger/internal/codegen/writing/OptionalFactories.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,12 @@
import dagger.internal.codegen.javapoet.AnnotationSpecs;
import dagger.internal.codegen.javapoet.TypeNames;
import dagger.internal.codegen.model.RequestKind;
import dagger.producers.Producer;
import dagger.producers.internal.Producers;
import java.util.Comparator;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Provider;

/** The nested class and static methods required by the component to implement optional bindings. */
// TODO(dpb): Name members simply if a component uses only one of Guava or JDK Optional.
Expand Down Expand Up @@ -193,7 +190,7 @@ private FieldSpec absentOptionalProviderField(OptionalKind optionalKind) {
/** Information about the type of a factory for present bindings. */
@AutoValue
abstract static class PresentFactorySpec {
/** Whether the factory is a {@link Provider} or a {@link Producer}. */
/** Whether the factory is a {@code Provider} or a {@code Producer}. */
abstract FrameworkType frameworkType();

/** What kind of {@code Optional} is returned. */
Expand Down Expand Up @@ -302,7 +299,7 @@ private static PresentFactorySpec of(ContributionBinding binding) {
* {@code Producer<Optional<Produced<T>>>}.
* </ul>
*
* @param delegateFactory an expression for a {@link Provider} or {@link Producer} of the
* @param delegateFactory an expression for a {@code Provider} or {@code Producer} of the
* underlying type
*/
CodeBlock presentOptionalFactory(ContributionBinding binding, CodeBlock delegateFactory) {
Expand Down Expand Up @@ -415,7 +412,9 @@ private MethodSpec presentOptionalFactoryGetMethod(
spec.optionalKind(),
spec.valueType(),
CodeBlock.of(
"$T.createFutureProduced($N.get())", Producers.class, delegateField)))
"$T.createFutureProduced($N.get())",
TypeNames.PRODUCERS,
delegateField)))
.build();

default:
Expand Down
14 changes: 5 additions & 9 deletions java/dagger/internal/codegen/writing/ProducerEntryPointView.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@
import dagger.internal.codegen.javapoet.TypeNames;
import dagger.internal.codegen.model.RequestKind;
import dagger.internal.codegen.writing.ComponentImplementation.ShardImplementation;
import dagger.producers.Producer;
import dagger.producers.internal.CancellationListener;
import dagger.producers.internal.Producers;
import java.util.Optional;

/**
* A factory of {@linkplain Producers#entryPointViewOf(Producer, CancellationListener) entry point
* views} of {@link Producer}s.
* A factory of {@code Producers#entryPointViewOf(Producer, CancellationListener)} of
* {@code Producer}s.
*/
final class ProducerEntryPointView {
private final ShardImplementation shardImplementation;
Expand All @@ -50,9 +47,8 @@ final class ProducerEntryPointView {
}

/**
* Returns an expression for an {@linkplain Producers#entryPointViewOf(Producer,
* CancellationListener) entry point view} of a producer if the component method returns a {@link
* Producer} or {@link com.google.common.util.concurrent.ListenableFuture}.
* Returns an expression for an {@code Producers#entryPointViewOf(Producer, CancellationListener)}
* of a producer if the component method returns a {@code Producer} or {@code ListenableFuture}.
*
* <p>This is intended to be a replacement implementation for {@link
* dagger.internal.codegen.writing.RequestRepresentation#getDependencyExpressionForComponentMethod(ComponentMethodDescriptor,
Expand Down Expand Up @@ -97,7 +93,7 @@ private MemberSelect createField(
CodeBlock.of(
"this.$N = $T.entryPointViewOf($L, $L);",
field,
Producers.class,
TypeNames.PRODUCERS,
producerExpression.getDependencyExpression(shardImplementation.name()).codeBlock(),
// Always pass in the componentShard reference here rather than the owning shard for
// this key because this needs to be the root CancellationListener.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,13 @@
import dagger.internal.codegen.model.DependencyRequest;
import dagger.internal.codegen.model.Key;
import dagger.internal.codegen.model.RequestKind;
import dagger.producers.Producer;
import dagger.producers.internal.AbstractProducesMethodProducer;
import dagger.producers.internal.Producers;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
import javax.inject.Inject;

/** Generates {@link Producer} implementations from {@link ProductionBinding} instances. */
/** Generates {@code Producer} implementations from {@link ProductionBinding} instances. */
public final class ProducerFactoryGenerator extends SourceFileGenerator<ProductionBinding> {
private final CompilerOptions compilerOptions;
private final KeyFactory keyFactory;
Expand Down Expand Up @@ -219,7 +216,7 @@ public ImmutableList<TypeSpec.Builder> topLevelTypes(ProductionBinding binding)
factoryBuilder
.superclass(
ParameterizedTypeName.get(
ClassName.get(AbstractProducesMethodProducer.class),
TypeNames.ABSTRACT_PRODUCES_METHOD_PRODUCER,
futureTransform.applyArgType(),
providedTypeName))
.addMethod(constructor)
Expand Down Expand Up @@ -264,7 +261,7 @@ private static CodeBlock fieldAssignment(FieldSpec field, ParameterizedTypeName
CodeBlock.Builder statement = CodeBlock.builder();
if (type != null && type.rawType.equals(TypeNames.PRODUCER)) {
statement.addStatement(
"this.$1N = $2T.nonCancellationPropagatingViewOf($1N)", field, Producers.class);
"this.$1N = $2T.nonCancellationPropagatingViewOf($1N)", field, TypeNames.PRODUCERS);
} else {
statement.addStatement("this.$1N = $1N", field);
}
Expand All @@ -275,7 +272,7 @@ private static void assignField(
MethodSpec.Builder constructorBuilder, FieldSpec field, ParameterizedTypeName type) {
if (type != null && type.rawType.equals(TypeNames.PRODUCER)) {
constructorBuilder.addStatement(
"this.$1N = $2T.nonCancellationPropagatingViewOf($1N)", field, Producers.class);
"this.$1N = $2T.nonCancellationPropagatingViewOf($1N)", field, TypeNames.PRODUCERS);
} else {
constructorBuilder.addStatement("this.$1N = $1N", field);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
import dagger.internal.codegen.javapoet.TypeNames;
import dagger.internal.codegen.model.RequestKind;
import dagger.internal.codegen.writing.FrameworkFieldInitializer.FrameworkInstanceCreationExpression;
import dagger.producers.Producer;
import java.util.Optional;

/** An {@link Producer} creation expression for provision bindings. */
/** An {@code Producer} creation expression for provision bindings. */
final class ProducerFromProviderCreationExpression implements FrameworkInstanceCreationExpression {
private final RequestRepresentation providerRequestRepresentation;
private final ClassName requestingClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import dagger.internal.codegen.binding.ContributionBinding;
import dagger.internal.codegen.binding.FrameworkType;
import dagger.internal.codegen.javapoet.Expression;
import dagger.internal.codegen.javapoet.TypeNames;
import dagger.internal.codegen.model.Key;
import dagger.internal.codegen.writing.ComponentImplementation.ShardImplementation;
import dagger.producers.internal.Producers;

/** Binding expression for producer node instances. */
final class ProducerNodeInstanceRequestRepresentation
Expand Down Expand Up @@ -61,7 +61,7 @@ Expression getDependencyExpression(ClassName requestingClass) {
key,
CodeBlock.of(
"$T.cancel($L, $N);",
Producers.class,
TypeNames.PRODUCERS,
result.codeBlock(),
ComponentImplementation.MAY_INTERRUPT_IF_RUNNING_PARAM));
return result;
Expand Down
1 change: 0 additions & 1 deletion java/dagger/model/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ java_library(
deps = [
"//java/dagger:core",
"//java/dagger/internal/codegen/extension",
"//java/dagger/producers",
"//third_party/java/auto:common",
"//third_party/java/auto:value",
"//third_party/java/error_prone:annotations",
Expand Down
15 changes: 7 additions & 8 deletions java/dagger/model/BindingGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@
* <p>A {@link BindingGraph} represents one of the following:
*
* <ul>
* <li>an entire component hierarchy rooted at a {@link dagger.Component} or {@link
* dagger.producers.ProductionComponent}
* <li>a partial component hierarchy rooted at a {@link dagger.Subcomponent} or {@link
* dagger.producers.ProductionSubcomponent} (only when the value of {@code
* -Adagger.fullBindingGraphValidation} is not {@code NONE})
* <li>the bindings installed by a {@link Module} or {@link dagger.producers.ProducerModule},
* including all subcomponents generated by {@link Module#subcomponents()} ()} and {@link
* dagger.producers.ProducerModule#subcomponents()} ()}
* <li>an entire component hierarchy rooted at a {@code Component} or {@code ProductionComponent}
* <li>a partial component hierarchy rooted at a {@code Subcomponent} or
* {@code ProductionSubcomponent} (only when the value of
* {@code -Adagger.fullBindingGraphValidation} is not {@code NONE})
* <li>the bindings installed by a {@code Module} or {@code ProducerModule},
* including all subcomponents generated by {@code Module#subcomponents()} and
* {@code ProducerModule#subcomponents()}
* </ul>
*
* In the case of a {@link BindingGraph} representing a module, the root {@link ComponentNode} will
Expand Down
12 changes: 5 additions & 7 deletions java/dagger/model/BindingKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public enum BindingKind {
ASSISTED_FACTORY,

/**
* An implicit binding for a {@link dagger.Component}- or {@link
* dagger.producers.ProductionComponent}-annotated type.
* An implicit binding for a {@code Component}- or {@code ProductionComponent}-annotated type.
*/
COMPONENT,

Expand Down Expand Up @@ -65,14 +64,13 @@ public enum BindingKind {
/** A binding for a {@link dagger.BindsInstance}-annotated builder method. */
BOUND_INSTANCE,

/** A binding for a {@link dagger.producers.Produces}-annotated method. */
/** A binding for a {@code Produces}-annotated method. */
PRODUCTION,

/**
* A binding for a production method on a production component's {@linkplain
* dagger.producers.ProductionComponent#dependencies()} dependency} that returns a {@link
* com.google.common.util.concurrent.ListenableFuture} or {@link
* com.google.common.util.concurrent.FluentFuture}. Methods on production component dependencies
* A binding for a production method on a production component's
* {@code ProductionComponent#dependencies()} that returns a {@code ListenableFuture} or
* {@code FluentFuture}. Methods on production component dependencies
* that don't return a future are considered {@linkplain #COMPONENT_PROVISION component provision
* bindings}.
*/
Expand Down
3 changes: 1 addition & 2 deletions java/dagger/model/ComponentPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public static ComponentPath create(Iterable<TypeElement> components) {
public abstract ImmutableList<TypeElement> components();

/**
* Returns the root {@link dagger.Component}- or {@link
* dagger.producers.ProductionComponent}-annotated type
* Returns the root {@code Component}- or {@code ProductionComponent}-annotated type
*/
public final TypeElement rootComponent() {
return components().get(0);
Expand Down
Loading

0 comments on commit 2bf1327

Please sign in to comment.