From 0896fbe532e7649ce56d66467a865d345beb93b3 Mon Sep 17 00:00:00 2001 From: Brad Corso Date: Mon, 27 Nov 2023 10:32:45 -0800 Subject: [PATCH] Internal changes RELNOTES=N/A PiperOrigin-RevId: 585693139 --- .../codegen/binding/BindingGraphFactory.java | 25 ++++++++++--------- java/dagger/internal/codegen/kythe/BUILD | 3 +++ .../codegen/kythe/DaggerKythePlugin.java | 5 ---- javatests/dagger/functional/basic/BUILD | 4 ++- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/java/dagger/internal/codegen/binding/BindingGraphFactory.java b/java/dagger/internal/codegen/binding/BindingGraphFactory.java index 7e23c2c1607..72eb17d80c0 100644 --- a/java/dagger/internal/codegen/binding/BindingGraphFactory.java +++ b/java/dagger/internal/codegen/binding/BindingGraphFactory.java @@ -649,7 +649,7 @@ private ContributionBinding createDelegateBinding(DelegateDeclaration delegateDe */ private XTypeElement getOwningComponent(Key requestKey, ContributionBinding binding) { if (isResolvedInParent(requestKey, binding) - && !new LocalDependencyChecker().dependsOnLocalBindings(binding)) { + && !new RequiresResolutionChecker().requiresResolution(binding)) { ResolvedBindings parentResolvedBindings = parentResolver.get().resolvedContributionBindings.get(requestKey); return parentResolvedBindings.owningComponent(binding); @@ -876,7 +876,7 @@ void resolve(Key key) { previouslyResolvedBindings.bindings().stream() .anyMatch(binding -> binding.kind() == BindingKind.ASSISTED_INJECTION); if (!isAssistedInjectionBinding - && !new LocalDependencyChecker().dependsOnLocalBindings(key) + && !new RequiresResolutionChecker().requiresResolution(key) && getLocalExplicitBindings(key).isEmpty()) { /* Cache the inherited parent component's bindings in case resolving at the parent found * bindings in some component between this one and the previously-resolved one. */ @@ -921,7 +921,7 @@ private ResolvedBindings getResolvedMembersInjectionBindings(Key key) { return resolvedMembersInjectionBindings.get(key); } - private final class LocalDependencyChecker { + private final class RequiresResolutionChecker { private final Set cycleChecker = new HashSet<>(); /** @@ -935,14 +935,14 @@ private final class LocalDependencyChecker { * * @throws IllegalArgumentException if {@link #getPreviouslyResolvedBindings(Key)} is empty */ - private boolean dependsOnLocalBindings(Key key) { + private boolean requiresResolution(Key key) { // Don't recur infinitely if there are valid cycles in the dependency graph. // http://b/23032377 if (!cycleChecker.add(key)) { return false; } return reentrantComputeIfAbsent( - keyDependsOnLocalBindingsCache, key, this::dependsOnLocalBindingsUncached); + keyDependsOnLocalBindingsCache, key, this::requiresResolutionUncached); } /** @@ -954,15 +954,15 @@ private boolean dependsOnLocalBindings(Key key) { *

We don't care about non-reusable scoped dependencies because they will never depend on * multibindings with contributions from subcomponents. */ - private boolean dependsOnLocalBindings(Binding binding) { + private boolean requiresResolution(Binding binding) { if (!cycleChecker.add(binding)) { return false; } return reentrantComputeIfAbsent( - bindingDependsOnLocalBindingsCache, binding, this::dependsOnLocalBindingsUncached); + bindingDependsOnLocalBindingsCache, binding, this::requiresResolutionUncached); } - private boolean dependsOnLocalBindingsUncached(Key key) { + private boolean requiresResolutionUncached(Key key) { checkArgument( getPreviouslyResolvedBindings(key).isPresent(), "no previously resolved bindings in %s for %s", @@ -970,24 +970,25 @@ private boolean dependsOnLocalBindingsUncached(Key key) { key); ResolvedBindings previouslyResolvedBindings = getPreviouslyResolvedBindings(key).get(); if (hasLocalMultibindingContributions(key) - || hasLocalOptionalBindingContribution(previouslyResolvedBindings)) { + || hasLocalOptionalBindingContribution(previouslyResolvedBindings) + ) { return true; } for (Binding binding : previouslyResolvedBindings.bindings()) { - if (dependsOnLocalBindings(binding)) { + if (requiresResolution(binding)) { return true; } } return false; } - private boolean dependsOnLocalBindingsUncached(Binding binding) { + private boolean requiresResolutionUncached(Binding binding) { if ((!binding.scope().isPresent() || binding.scope().get().isReusable()) // TODO(beder): Figure out what happens with production subcomponents. && !binding.bindingType().equals(BindingType.PRODUCTION)) { for (DependencyRequest dependency : binding.dependencies()) { - if (dependsOnLocalBindings(dependency.key())) { + if (requiresResolution(dependency.key())) { return true; } } diff --git a/java/dagger/internal/codegen/kythe/BUILD b/java/dagger/internal/codegen/kythe/BUILD index 2ddc1b40ad3..217627d785a 100644 --- a/java/dagger/internal/codegen/kythe/BUILD +++ b/java/dagger/internal/codegen/kythe/BUILD @@ -26,13 +26,16 @@ java_library( deps = [ ":kythe_plugin", "//java/dagger:core", + "//java/dagger/internal/codegen/base", "//java/dagger/internal/codegen/binding", "//java/dagger/internal/codegen/javac", "//java/dagger/internal/codegen/javapoet", + "//java/dagger/internal/codegen/kotlin", "//java/dagger/internal/codegen/model", "//java/dagger/internal/codegen/validation", "//java/dagger/internal/codegen/xprocessing", "//third_party/java/auto:service", + "//third_party/java/error_prone:annotations", "//third_party/java/guava/collect", "//third_party/java/jsr330_inject", ], diff --git a/java/dagger/internal/codegen/kythe/DaggerKythePlugin.java b/java/dagger/internal/codegen/kythe/DaggerKythePlugin.java index 904015f7032..0b8a5024bf1 100644 --- a/java/dagger/internal/codegen/kythe/DaggerKythePlugin.java +++ b/java/dagger/internal/codegen/kythe/DaggerKythePlugin.java @@ -68,11 +68,6 @@ public class DaggerKythePlugin extends Plugin.Scanner { @Inject BindingGraphFactory bindingGraphFactory; @Inject XProcessingEnv xProcessingEnv; - @Override - public String getName() { // SUPPRESS_GET_NAME_CHECK - return "dagger_plugin"; - } - @Override public Void visitClassDef(JCClassDecl tree, Void p) { if (tree.sym != null) { diff --git a/javatests/dagger/functional/basic/BUILD b/javatests/dagger/functional/basic/BUILD index 18be5e1b2cf..9ed6fc213d1 100644 --- a/javatests/dagger/functional/basic/BUILD +++ b/javatests/dagger/functional/basic/BUILD @@ -26,7 +26,9 @@ package(default_visibility = ["//:src"]) GenJavaTests( name = "basic", - srcs = glob(["*.java"]), + srcs = glob( + ["*.java"], + ), gen_library_deps = [ "//javatests/dagger/functional/basic/subpackage", ],