Diagnostic.Kind diagnosticKind = ERROR; StringBuilder message = new StringBuilder(componentNode.componentPath().currentComponent().getQualifiedName()); if (bindingGraph.isModuleBindingGraph() && componentNode.componentPath().atRoot()) { } else if (componentNode.scopes().isEmpty()) { message.append(" (unscoped) may not reference scoped bindings:"); } else { .append(" scoped with ") .append( componentNode.scopes().stream().map(Scopes::getReadableSource).collect(joining(" "))) .append(" may not reference bindings with different scopes:");
@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)); }
@Override protected void visitComponent(BindingGraph graph) { ComponentNode grandparentComponent = parentComponent; parentComponent = currentComponent; currentComponent = ComponentNodeImpl.create( componentTreePath().toComponentPath(), graph.componentDescriptor()); network.addNode(currentComponent); for (ResolvedBindings resolvedBindings : graph.resolvedBindings()) { ImmutableSet<TypeElement> declaringModules = subcomponentDeclaringModules(resolvedBindings); for (BindingNode binding : bindingNodes(resolvedBindings)) { addBinding(binding); if (binding.kind().equals(SUBCOMPONENT_BUILDER) && binding.componentPath().equals(currentComponent.componentPath())) { network.addEdge( binding, subcomponentNode(binding.key().type(), graph), new SubcomponentBuilderBindingEdgeImpl(declaringModules)); } } } super.visitComponent(graph); currentComponent = parentComponent; parentComponent = grandparentComponent; }
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()); }
private ImmutableSet<TypeElement> subgraphFactoryMethodParameters( ChildFactoryMethodEdge edge, BindingGraph bindingGraph) { ComponentNode parent = (ComponentNode) bindingGraph.network().incidentNodes(edge).source(); DeclaredType parentType = asDeclared(parent.componentPath().currentComponent().asType()); ExecutableType factoryMethodType = asExecutable(types.asMemberOf(parentType, edge.factoryMethod())); return asTypeElements(factoryMethodType.getParameterTypes()); }
DiagnosticReporterImpl(BindingGraph graph, String plugin) { this.graph = graph; this.plugin = plugin; this.rootComponent = graph.rootComponentNode().componentPath().currentComponent(); }
private void appendComponentPathUnlessAtRoot(StringBuilder message, Node node) { if (!node.componentPath().equals(graph.rootComponentNode().componentPath())) { new Formatter(message).format(" [%s]", node.componentPath()); } }
private Function<ComponentNode, Set<TypeElement>> uncachedInheritedModules(BindingGraph graph) { return componentNode -> componentNode.componentPath().atRoot() ? ImmutableSet.of() : graph .componentNode(componentNode.componentPath().parent()) .map(parent -> union(ownedModules(parent, graph), inheritedModules(parent, graph))) .get(); }