@Override public void visitGraph(BindingGraph graph, DiagnosticReporter diagnosticReporter) { for (Binding binding : graph.bindings()) { if (isDispatchingAndroidInjector(binding)) { validateMapKeyUniqueness(binding, graph, diagnosticReporter); } } }
private ImmutableList<dagger.model.Binding> nullableBindings(BindingGraph bindingGraph) { return bindingGraph.bindings().stream() .filter(binding -> binding.isNullable()) .collect(toImmutableList()); }
private Stream<DependencyEdge> provisionDependenciesOnProductionBindings( BindingGraph bindingGraph) { return bindingGraph.bindings().stream() .filter(binding -> binding.isProduction()) .flatMap(binding -> incomingDependencies(binding, bindingGraph)) .filter(edge -> !dependencyCanUseProduction(edge, bindingGraph)); }
@Override public void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter) { bindingGraph.bindings().stream() .filter(binding -> binding.kind().equals(INJECTION)) // TODO(dpb): Move to BindingGraph .forEach(binding -> validateInjectionBinding(binding, diagnosticReporter)); }
private static ImmutableSet<ImmutableSet<Binding>> groupBindingsByKey(BindingGraph bindingGraph) { return valueSetsForEachKey( bindingGraph.bindings().stream() .filter(binding -> !binding.kind().equals(MEMBERS_INJECTION)) .collect(toImmutableSetMultimap(Binding::key, binding -> binding))); }
private String missingBindingErrorMessage(MissingBinding missingBinding, BindingGraph graph) { Key key = missingBinding.key(); StringBuilder errorMessage = new StringBuilder(); // Wildcards should have already been checked by DependencyRequestValidator. verify(!key.type().getKind().equals(TypeKind.WILDCARD), "unexpected wildcard request: %s", key); // TODO(ronshapiro): replace "provided" with "satisfied"? errorMessage.append(key).append(" cannot be provided without "); if (isValidImplicitProvisionKey(key, types)) { errorMessage.append("an @Inject constructor or "); } errorMessage.append("an @Provides-"); // TODO(dpb): s/an/a if (allIncomingDependenciesCanUseProduction(missingBinding, graph)) { errorMessage.append(" or @Produces-"); } errorMessage.append("annotated method."); if (isValidMembersInjectionKey(key) && typeHasInjectionSites(key)) { errorMessage.append( " This type supports members injection but cannot be implicitly provided."); } graph.bindings(key).stream() .map(binding -> binding.componentPath().currentComponent()) .distinct() .forEach( component -> errorMessage .append("\nA binding with matching key exists in component: ") .append(component.getQualifiedName())); return errorMessage.toString(); }
private ImmutableSet<TypeElement> findMissingModules( ChildFactoryMethodEdge edge, BindingGraph graph) { ImmutableSet<TypeElement> factoryMethodParameters = subgraphFactoryMethodParameters(edge, graph); ComponentNode child = (ComponentNode) graph.network().incidentNodes(edge).target(); SetView<TypeElement> modulesOwnedByChild = ownedModules(child, graph); return graph.bindings().stream() // bindings owned by child .filter(binding -> binding.componentPath().equals(child.componentPath())) // that require a module instance .filter(binding -> binding.requiresModuleInstance()) .map(binding -> binding.contributingModule().get()) .distinct() // module owned by child .filter(module -> modulesOwnedByChild.contains(module)) // module not in the method parameters .filter(module -> !factoryMethodParameters.contains(module)) // module doesn't have an accessible no-arg constructor .filter(moduleType -> !componentCanMakeNewInstances(moduleType)) .collect(toImmutableSet()); }
@Override public void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter) { ImmutableSetMultimap.Builder<ComponentNode, dagger.model.Binding> incompatibleBindings = ImmutableSetMultimap.builder(); for (dagger.model.Binding binding : bindingGraph.bindings()) { binding .scope() .filter(scope -> !scope.isReusable()) .ifPresent( scope -> { ComponentNode componentNode = bindingGraph.componentNode(binding.componentPath()).get(); if (!componentNode.scopes().contains(scope)) { // @Inject bindings in module binding graphs will appear at the properly scoped // ancestor component, so ignore them here. if (binding.kind().equals(INJECTION) && bindingGraph.isModuleBindingGraph()) { return; } incompatibleBindings.put(componentNode, binding); } }); } Multimaps.asMap(incompatibleBindings.build()) .forEach( (componentNode, bindings) -> report(componentNode, bindings, bindingGraph, diagnosticReporter)); }
bindingGraph.bindings().stream() .filter(node -> node.kind().equals(MULTIBOUND_MAP)) .collect(toImmutableSetMultimap(dagger.model.Binding::key, node -> node));