/** * Returns a comparator that sorts dependency edges lexicographically by the qualified name of * the type that contains them. Only appropriate for edges with request elements. */ Comparator<DependencyEdge> requestEnclosingTypeName() { return comparing( edge -> closestEnclosingTypeElement(edge.dependencyRequest().requestElement().get()) .getQualifiedName() .toString()); }
private boolean hasDependencyEdge( Node source, Node dependency, DependencyRequest dependencyRequest) { return network .edgesConnecting(source, dependency) .stream() .flatMap(instancesOf(DependencyEdge.class)) .anyMatch(edge -> edge.dependencyRequest().equals(dependencyRequest)); }
/** * Returns a comparator that sorts edges in the order in which their request elements were * declared in their declaring type. * * <p>Only useful to compare edges whose request elements were declared in the same type. */ Comparator<DependencyEdge> requestElementDeclarationOrder() { return comparing( edge -> edge.dependencyRequest().requestElement().get(), DECLARATION_ORDER); } }
dependencyTrace.forEach( edge -> dependencyRequestFormatter.appendFormatLine(message, edge.dependencyRequest())); if (!dependencyTrace.isEmpty()) { appendComponentPathUnlessAtRoot(message, source(getLast(dependencyTrace))); !printingEntryPoints || (!request.isEntryPoint() && !isTracedRequest(request))) .map(request -> request.dependencyRequest().requestElement()) .flatMap(presentValues()) .collect(toImmutableSet()); entryPoint -> { message.append("\n "); Element requestElement = entryPoint.dependencyRequest().requestElement().get(); message.append(elementToString(requestElement));
private boolean breaksCycle(DependencyEdge edge, BindingGraph graph) { if (edge.dependencyRequest().key().multibindingContributionIdentifier().isPresent()) { return false; } if (breaksCycle(edge.dependencyRequest().key().type(), edge.dependencyRequest().kind())) { return true; } Node target = graph.network().incidentNodes(edge).target(); if (target instanceof dagger.model.Binding && ((dagger.model.Binding) target).kind().equals(BindingKind.OPTIONAL)) { /* For @BindsOptionalOf bindings, unwrap the type inside the Optional. If the unwrapped type * breaks the cycle, so does the optional binding. */ TypeMirror optionalValueType = OptionalType.from(edge.dependencyRequest().key()).valueType(); RequestKind requestKind = getRequestKind(optionalValueType); return breaksCycle(extractKeyType(requestKind, optionalValueType), requestKind); } return false; }
private boolean dependencyCanBeProduction(DependencyEdge edge, BindingGraph graph) { Node source = graph.network().incidentNodes(edge).source(); if (source instanceof ComponentNode) { return entryPointCanUseProduction(edge.dependencyRequest().kind()); } if (source instanceof dagger.model.Binding) { return ((dagger.model.Binding) source).isProduction(); } throw new IllegalArgumentException( "expected a dagger.model.Binding or ComponentNode: " + source); }
/** Returns all the nonsynthetic dependency requests for a binding. */ ImmutableSet<DependencyEdge> requests(MaybeBinding binding) { return graph.network().inEdges(binding).stream() .flatMap(instancesOf(DependencyEdge.class)) .filter(edge -> edge.dependencyRequest().requestElement().isPresent()) .sorted(requestEnclosingTypeName().thenComparing(requestElementDeclarationOrder())) .collect(toImmutableSet()); }
private boolean dependencyCanUseProduction(DependencyEdge edge, BindingGraph bindingGraph) { return edge.isEntryPoint() ? entryPointCanUseProduction(edge.dependencyRequest().kind()) : bindingRequestingDependency(edge, bindingGraph).isProduction(); }
TypeElement typeDeclaringEntryPoint(DependencyEdge entryPoint) { return MoreElements.asType( entryPoint.dependencyRequest().requestElement().get().getEnclosingElement()); }
private String entryPointErrorMessage(DependencyEdge entryPoint) { return String.format( "%s is a provision entry-point, which cannot depend on a production.", entryPoint.dependencyRequest().key()); }
private ImmutableSet<DependencyEdge> nonNullableDependencies( BindingGraph bindingGraph, dagger.model.Binding binding) { return bindingGraph.network().inEdges(binding).stream() .flatMap(instancesOf(DependencyEdge.class)) .filter(edge -> !edge.dependencyRequest().isNullable()) .collect(toImmutableSet()); }