Skip to content

Commit

Permalink
[Refactor]: This CL refactors a few things in ComponentDescriptor.
Browse files Browse the repository at this point in the history
  * Moves `abstract` methods in `ComponentDescriptor` to the top of the class so that it's easier to tell which methods contributes to the AutoValue equals/hashcode.
  * Moves `ComponentDescriptorFactory` directly to a nested class, `ComponentDescriptor.Factory`, to be more consistent with how structure other descriptors like `ModuleDescriptor`/`ModuleDescriptor.Factory`.
  * Moves `CancellationPolicy` class definition out of `ComponentDescriptor` since it's not directly related to that class.

RELNOTES=N/A
PiperOrigin-RevId: 568890232
  • Loading branch information
bcorso authored and Dagger Team committed Sep 27, 2023
1 parent e8f5f2b commit 5cc209c
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 357 deletions.
39 changes: 39 additions & 0 deletions java/dagger/internal/codegen/binding/CancellationPolicy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2023 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dagger.internal.codegen.binding;

import static com.google.common.base.Preconditions.checkArgument;
import static dagger.internal.codegen.xprocessing.XElements.getSimpleName;

import androidx.room.compiler.processing.XAnnotation;
import dagger.internal.codegen.javapoet.TypeNames;
import dagger.internal.codegen.xprocessing.XAnnotations;

/**
* The cancellation policy for a {@link dagger.producers.ProductionComponent}.
*
* <p>@see dagger.producers.CancellationPolicy
*/
public enum CancellationPolicy {
PROPAGATE,
IGNORE;

static CancellationPolicy from(XAnnotation annotation) {
checkArgument(XAnnotations.getClassName(annotation).equals(TypeNames.CANCELLATION_POLICY));
return valueOf(getSimpleName(annotation.getAsEnum("fromSubcomponents")));
}
}
359 changes: 262 additions & 97 deletions java/dagger/internal/codegen/binding/ComponentDescriptor.java

Large diffs are not rendered by default.

241 changes: 0 additions & 241 deletions java/dagger/internal/codegen/binding/ComponentDescriptorFactory.java

This file was deleted.

2 changes: 0 additions & 2 deletions java/dagger/internal/codegen/javac/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ java_library(
plugins = ["//java/dagger/internal/codegen:component-codegen"],
deps = [
"//java/dagger:core",
"//java/dagger/internal/codegen/binding",
"//java/dagger/internal/codegen/compileroption",
"//java/dagger/internal/codegen/langmodel",
"//java/dagger/internal/codegen/xprocessing",
"//third_party/java/guava/collect",
],
Expand Down
6 changes: 2 additions & 4 deletions java/dagger/internal/codegen/javac/JavacPluginModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.internal.codegen.binding.BindingGraphFactory;
import dagger.internal.codegen.binding.ComponentDescriptorFactory;
import dagger.internal.codegen.compileroption.CompilerOptions;
import javax.lang.model.util.Elements; // ALLOW_TYPES_ELEMENTS
import javax.lang.model.util.Types; // ALLOW_TYPES_ELEMENTS

/**
* A module that provides a {@link BindingGraphFactory} and {@link ComponentDescriptorFactory} for
* use in {@code javac} plugins. Requires a binding for the {@code javac} {@link Context}.
* A module that provides a {@link XMessager}, {@link XProcessingEnv}, and {@link CompilerOptions}
* for use in {@code javac} plugins. Requires a binding for the {@code javac} {@link Context}.
*/
@Module(includes = JavacPluginModule.BindsModule.class)
public final class JavacPluginModule {
Expand Down
4 changes: 2 additions & 2 deletions java/dagger/internal/codegen/kythe/DaggerKythePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import dagger.internal.codegen.binding.BindingDeclaration;
import dagger.internal.codegen.binding.BindingGraphFactory;
import dagger.internal.codegen.binding.BindingNode;
import dagger.internal.codegen.binding.ComponentDescriptorFactory;
import dagger.internal.codegen.binding.ComponentDescriptor;
import dagger.internal.codegen.binding.ModuleDescriptor;
import dagger.internal.codegen.javac.JavacPluginModule;
import dagger.internal.codegen.javapoet.TypeNames;
Expand All @@ -64,7 +64,7 @@ public class DaggerKythePlugin extends Plugin.Scanner<Void, Void> {
// TODO(ronshapiro): use flogger
private static final Logger logger = Logger.getLogger(DaggerKythePlugin.class.getCanonicalName());
private FactEmitter emitter;
@Inject ComponentDescriptorFactory componentDescriptorFactory;
@Inject ComponentDescriptor.Factory componentDescriptorFactory;
@Inject BindingGraphFactory bindingGraphFactory;
@Inject XProcessingEnv xProcessingEnv;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import dagger.internal.codegen.base.SourceFileGenerator;
import dagger.internal.codegen.binding.BindingGraph;
import dagger.internal.codegen.binding.ComponentDescriptor;
import dagger.internal.codegen.binding.ComponentDescriptorFactory;
import dagger.internal.codegen.validation.ComponentCreatorValidator;
import dagger.internal.codegen.validation.ComponentValidator;
import dagger.internal.codegen.validation.ValidationReport;
Expand All @@ -52,15 +51,15 @@ final class ComponentHjarProcessingStep extends TypeCheckingProcessingStep<XType
private final XMessager messager;
private final ComponentValidator componentValidator;
private final ComponentCreatorValidator creatorValidator;
private final ComponentDescriptorFactory componentDescriptorFactory;
private final ComponentDescriptor.Factory componentDescriptorFactory;
private final SourceFileGenerator<ComponentDescriptor> componentGenerator;

@Inject
ComponentHjarProcessingStep(
XMessager messager,
ComponentValidator componentValidator,
ComponentCreatorValidator creatorValidator,
ComponentDescriptorFactory componentDescriptorFactory,
ComponentDescriptor.Factory componentDescriptorFactory,
SourceFileGenerator<ComponentDescriptor> componentGenerator) {
this.messager = messager;
this.componentValidator = componentValidator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import dagger.internal.codegen.binding.BindingGraph;
import dagger.internal.codegen.binding.BindingGraphFactory;
import dagger.internal.codegen.binding.ComponentDescriptor;
import dagger.internal.codegen.binding.ComponentDescriptorFactory;
import dagger.internal.codegen.validation.BindingGraphValidator;
import dagger.internal.codegen.validation.ComponentCreatorValidator;
import dagger.internal.codegen.validation.ComponentDescriptorValidator;
Expand All @@ -52,7 +51,7 @@ final class ComponentProcessingStep extends TypeCheckingProcessingStep<XTypeElem
private final ComponentValidator componentValidator;
private final ComponentCreatorValidator creatorValidator;
private final ComponentDescriptorValidator componentDescriptorValidator;
private final ComponentDescriptorFactory componentDescriptorFactory;
private final ComponentDescriptor.Factory componentDescriptorFactory;
private final BindingGraphFactory bindingGraphFactory;
private final SourceFileGenerator<BindingGraph> componentGenerator;
private final BindingGraphValidator bindingGraphValidator;
Expand All @@ -63,7 +62,7 @@ final class ComponentProcessingStep extends TypeCheckingProcessingStep<XTypeElem
ComponentValidator componentValidator,
ComponentCreatorValidator creatorValidator,
ComponentDescriptorValidator componentDescriptorValidator,
ComponentDescriptorFactory componentDescriptorFactory,
ComponentDescriptor.Factory componentDescriptorFactory,
BindingGraphFactory bindingGraphFactory,
SourceFileGenerator<BindingGraph> componentGenerator,
BindingGraphValidator bindingGraphValidator) {
Expand Down Expand Up @@ -132,7 +131,10 @@ private void processSubcomponent(XTypeElement subcomponent) {
return;
}
BindingGraph fullBindingGraph = bindingGraphFactory.create(subcomponentDescriptor, true);
boolean isValid = bindingGraphValidator.isValid(fullBindingGraph.topLevelBindingGraph());
// In this case, we don't actually care about the return value. The important part here is that
// BindingGraphValidator#isValid() runs all of the SPI plugins and reports any errors.
// TODO(bcorso): Add a separate API with no return value for this particular case.
boolean unusedIsValid = bindingGraphValidator.isValid(fullBindingGraph.topLevelBindingGraph());
}

private void generateComponent(BindingGraph bindingGraph) {
Expand Down
Loading

0 comments on commit 5cc209c

Please sign in to comment.