DiagnosticReporterImpl(BindingGraph graph, String plugin) { this.graph = graph; this.plugin = plugin; this.rootComponent = graph.rootComponentNode().componentPath().currentComponent(); }
TypeElement componentContainingEntryPoint(DependencyEdge entryPoint) { return source(entryPoint).componentPath().currentComponent(); }
@Override public String visitVariable(VariableElement variable, DependencyRequest request) { TypeMirror requestedType = requestType(request.kind(), request.key().type(), types); return INDENT + formatQualifier(request.key().qualifier()) + requestedType + " is injected at\n" + DOUBLE_INDENT + elementToString(variable); }
@Override public String toString() { String string = dependencyRequest .requestElement() .map(DaggerElements::elementToString) .orElseGet( () -> "synthetic request for " + dependencyRequest.kind().format(dependencyRequest.key())); return entryPoint ? string + " (entry point)" : string; } }
private boolean dependencyCanUseProduction(DependencyEdge edge, BindingGraph bindingGraph) { return edge.isEntryPoint() ? entryPointCanUseProduction(edge.dependencyRequest().kind()) : bindingRequestingDependency(edge, bindingGraph).isProduction(); }
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); }
private void appendComponentPathUnlessAtRoot(StringBuilder message, Node node) { if (!node.componentPath().equals(graph.rootComponentNode().componentPath())) { new Formatter(message).format(" [%s]", node.componentPath()); } }
private String entryPointErrorMessage(DependencyEdge entryPoint) { return String.format( "%s is a provision entry-point, which cannot depend on a production.", entryPoint.dependencyRequest().key()); }
/** * 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()); }
/** * 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); } }
private ComponentNode rootComponentNode(Network<Node, Edge> network) { return (ComponentNode) Iterables.find( network.nodes(), node -> node instanceof ComponentNode && node.componentPath().atRoot()); }
private static boolean isAsyncDependency(DependencyRequest dependency) { switch (dependency.kind()) { case INSTANCE: case PRODUCED: return true; default: return false; } }