Skip to content

Commit

Permalink
Internal changes
Browse files Browse the repository at this point in the history
RELNOTES=N/A
PiperOrigin-RevId: 585693139
  • Loading branch information
bcorso authored and Dagger Team committed Nov 27, 2023
1 parent 7121b67 commit 0896fbe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
25 changes: 13 additions & 12 deletions java/dagger/internal/codegen/binding/BindingGraphFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -921,7 +921,7 @@ private ResolvedBindings getResolvedMembersInjectionBindings(Key key) {
return resolvedMembersInjectionBindings.get(key);
}

private final class LocalDependencyChecker {
private final class RequiresResolutionChecker {
private final Set<Object> cycleChecker = new HashSet<>();

/**
Expand All @@ -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);
}

/**
Expand All @@ -954,40 +954,41 @@ private boolean dependsOnLocalBindings(Key key) {
* <p>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",
Resolver.this,
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;
}
}
Expand Down
3 changes: 3 additions & 0 deletions java/dagger/internal/codegen/kythe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
5 changes: 0 additions & 5 deletions java/dagger/internal/codegen/kythe/DaggerKythePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ public class DaggerKythePlugin extends Plugin.Scanner<Void, Void> {
@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) {
Expand Down
4 changes: 3 additions & 1 deletion javatests/dagger/functional/basic/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down

0 comments on commit 0896fbe

Please sign in to comment.