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(); }
/** * Returns a comparator that sorts entry points in components whose paths from the root are * shorter first. */ Comparator<DependencyEdge> rootComponentFirst() { return comparingInt(entryPoint -> source(entryPoint).componentPath().components().size()); }
/** Converts this {@link ComponentTreePath} into a {@link ComponentPath}. */ ComponentPath toComponentPath() { return ComponentPath.create( graphsInPath().stream().map(BindingGraph::componentTypeElement).collect(toList())); }
TypeElement componentContainingEntryPoint(DependencyEdge entryPoint) { return source(entryPoint).componentPath().currentComponent(); }
Diagnostic.Kind diagnosticKind = ERROR; StringBuilder message = new StringBuilder(componentNode.componentPath().currentComponent().getQualifiedName()); if (bindingGraph.isModuleBindingGraph() && componentNode.componentPath().atRoot()) {
private ComponentNode rootComponentNode(Network<Node, Edge> network) { return (ComponentNode) Iterables.find( network.nodes(), node -> node instanceof ComponentNode && node.componentPath().atRoot()); }
@Override public final String toString() { return componentPath().toString(); } }
DiagnosticReporterImpl(BindingGraph graph, String plugin) { this.graph = graph; this.plugin = plugin; this.rootComponent = graph.rootComponentNode().componentPath().currentComponent(); }
if (!componentPath.atRoot() || !requestElement.getEnclosingElement().equals(rootComponent)) { message.append(String.format(" [%s]", componentPath));
/** * Returns the subsets of the input set that contain bindings that are all visible from the same * component. A binding is visible from its component and all its descendants. */ private static ImmutableSet<ImmutableSet<Binding>> mutuallyVisibleSubsets( Set<Binding> duplicateBindings) { ImmutableListMultimap<ComponentPath, Binding> bindingsByComponentPath = Multimaps.index(duplicateBindings, Binding::componentPath); ImmutableSetMultimap.Builder<ComponentPath, Binding> mutuallyVisibleBindings = ImmutableSetMultimap.builder(); bindingsByComponentPath .asMap() .forEach( (componentPath, bindings) -> { mutuallyVisibleBindings.putAll(componentPath, bindings); for (ComponentPath ancestor = componentPath; !ancestor.atRoot(); ) { ancestor = ancestor.parent(); ImmutableList<Binding> bindingsInAncestor = bindingsByComponentPath.get(ancestor); mutuallyVisibleBindings.putAll(componentPath, bindingsInAncestor); } }); return valueSetsForEachKey(mutuallyVisibleBindings.build()); }
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 void reportMissingModuleParameters( ChildFactoryMethodEdge edge, ImmutableSet<TypeElement> missingModules, BindingGraph graph, DiagnosticReporter diagnosticReporter) { diagnosticReporter.reportSubcomponentFactoryMethod( ERROR, edge, "%s requires modules which have no visible default constructors. " + "Add the following modules as parameters to this method: %s", graph .network() .incidentNodes(edge) .target() .componentPath() .currentComponent() .getQualifiedName(), Joiner.on(", ").join(missingModules)); } }
private ResolvedBindings resolvedDependencies( Node source, DependencyRequest dependencyRequest) { return componentTreePath() .pathFromRootToAncestor(source.componentPath().currentComponent()) .currentGraph() .resolvedBindings(bindingRequest(dependencyRequest)); }
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()); }