public DAGNode<Component, Dependency> processNode(@Nonnull DAGNode<Component, Dependency> node, @Nonnull DAGNode<Component, Dependency> original) { Component label = node.getLabel(); if (!label.getSatisfaction().hasInstance()) { Satisfaction instanceSat = Satisfactions.nullOfType(label.getSatisfaction().getErasedType()); Component newLbl = Component.create(instanceSat, label.getCachePolicy()); // build new node with replacement label DAGNodeBuilder<Component,Dependency> bld = DAGNode.newBuilder(newLbl); // retain all non-transient edges for (DAGEdge<Component,Dependency> edge: node.getOutgoingEdges()) { if (!GraphtUtils.edgeIsTransient(edge)) { bld.addEdge(edge.getTail(), edge.getLabel()); } } DAGNode<Component,Dependency> repl = bld.build(); logger.debug("simulating instantiation of {}", node); return repl; } else { return node; } } }
Component label = node.getLabel(); if (label.getSatisfaction().hasInstance()) { logger.trace("node {} shareable because it has an instance", node); return true; Class<?> type = label.getSatisfaction().getErasedType(); logger.trace("node {} has satisfaction type {}", node, type); if (type.getAnnotation(Shareable.class) != null) { return label.getSatisfaction().visit(new AbstractSatisfactionVisitor<Boolean>() { @Override public Boolean visitDefault() {
@Nullable private Optional<Object> getDiskCachedObject(Path file, DAGNode<Component,Dependency> node) { if (file != null && Files.exists(file)) { logger.debug("reading object for {} from cache (key {})", node.getLabel().getSatisfaction(), key); Object obj = readCompressedObject(file, node.getLabel().getSatisfaction().getErasedType()); logger.debug("read object {} from key {}", obj, key); return Optional.fromNullable(obj); } else { return null; } }
private static boolean satIsNull(Satisfaction sat) { return sat.visit(new AbstractSatisfactionVisitor<Boolean>(false) { @Override public Boolean visitNull() { return true; } }); } }
@Override public MatchElement apply(Pair<Satisfaction, InjectionPoint> n) { // we must check for nulls in case it is a synthetic satisfaction Satisfaction sat = n.getLeft(); boolean typeMatches; if (type == null) { typeMatches = sat == null || sat.getErasedType() == null || sat.getType().equals(Void.TYPE); } else { typeMatches = sat != null && sat.getErasedType() != null && type.isAssignableFrom(sat.getErasedType()); } if (typeMatches && qualifier.matches(n.getRight().getQualifier())) { return new MatchElem(sat == null ? null : sat.getErasedType(), type, qualifier); } else { return null; } }
for (Desire d: sat.getDependencies()) { logger.debug("Attempting to resolve deferred dependency {} of {}", d, sat);
policy = chain.getCurrentDesire().getSatisfaction().getDefaultCachePolicy(); if (policy.equals(CachePolicy.NO_PREFERENCE)) { policy = defaultPolicy;
/** * Find a node with a satisfaction for a specified type. Does a breadth-first * search to find the closest matching one. * * @param type The type to look for. * @return A node whose satisfaction is compatible with {@code type}. */ @Nullable public static DAGNode<Component,Dependency> findSatisfyingNode(DAGNode<Component,Dependency> graph, final QualifierMatcher qmatch, final Class<?> type) { Optional<DAGEdge<Component, Dependency>> edge = graph.breadthFirstEdges() .filter(e -> type.isAssignableFrom(e.getTail() .getLabel() .getSatisfaction() .getErasedType())) .filter(e -> qmatch.apply(e.getLabel() .getInitialDesire() .getInjectionPoint() .getQualifier())) .findFirst(); return edge.map(DAGEdge::getTail) .orElse(null); } }
Satisfaction sat = csat.getSatisfaction(); try { tgt = sat.visit(new Visitor(node, id)); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) {
for (Desire d: result.satisfaction.getDependencies()) {
public DAGNode<Component, Dependency> processNode(@Nonnull DAGNode<Component, Dependency> node, @Nonnull DAGNode<Component, Dependency> original) { Component label = node.getLabel(); Satisfaction satisfaction = label.getSatisfaction(); if (satisfaction.hasInstance()) { return node; } Object obj = instantiator.apply(node); Satisfaction instanceSat; if (obj == null) { instanceSat = Satisfactions.nullOfType(satisfaction.getErasedType()); } else { instanceSat = Satisfactions.instance(obj); } Component newLabel = Component.create(instanceSat, label.getCachePolicy()); // build new node with replacement label DAGNodeBuilder<Component,Dependency> bld = DAGNode.newBuilder(newLabel); // retain all non-transient edges for (DAGEdge<Component, Dependency> edge: node.getOutgoingEdges()) { if (!GraphtUtils.edgeIsTransient(edge)) { bld.addEdge(edge.getTail(), edge.getLabel()); } } return bld.build(); } }
/** * Check a graph for placeholder satisfactions. * * @param graph The graph to check. * @throws RecommenderConfigurationException if the graph has a placeholder satisfaction. */ public static void checkForPlaceholders(DAGNode<Component, Dependency> graph, Logger logger) throws RecommenderConfigurationException { Set<DAGNode<Component, Dependency>> placeholders = getPlaceholderNodes(graph); Satisfaction sat = null; for (DAGNode<Component,Dependency> node: placeholders) { Component csat = node.getLabel(); // special-case DAOs for non-checking if (DataAccessObject.class.isAssignableFrom(csat.getSatisfaction().getErasedType())) { logger.debug("found DAO placeholder {}", csat.getSatisfaction()); } else { // all other placeholders are bad if (sat == null) { sat = csat.getSatisfaction(); } logger.error("placeholder {} not removed", csat.getSatisfaction()); } } if (sat != null) { throw new RecommenderConfigurationException("placeholder " + sat + " not removed"); } }
Component label = node.getLabel(); if (label.getSatisfaction().hasInstance()) { logger.trace("node {} shareable because it has an instance", node); return true; Class<?> type = label.getSatisfaction().getErasedType(); logger.trace("node {} has satisfaction type {}", node, type); if (type.getAnnotation(Shareable.class) != null) { return label.getSatisfaction().visit(new AbstractSatisfactionVisitor<Boolean>() { @Override public Boolean visitDefault() {
@Override public void describe(DAGNode<Component, Dependency> node, DescriptionWriter description) { node.getLabel().getSatisfaction().visit(new LabelDescriptionVisitor(description)); description.putField("cachePolicy", node.getLabel().getCachePolicy().name()); List<DAGNode<Component, Dependency>> edges = node.getOutgoingEdges() .stream() .sorted(GraphtUtils.DEP_EDGE_ORDER) .map(DAGEdge::getTail) .collect(Collectors.toList()); description.putList("dependencies", edges, INSTANCE); } }
if (satisfaction.hasInstance()) { return node; instanceSat = Satisfactions.nullOfType(satisfaction.getErasedType()); } else { instanceSat = Satisfactions.instance(obj);
/** * Create a provided node from the current node, and queue an edge for it. * * @param pid The ID of the provider node for targeting the provision edge. * @return The provided node and the edge connect it to the provider node. */ private Pair<GVNode, GVEdge> providedNode(String pid) { GVNode pNode = ComponentNodeBuilder.create(nodeId, satisfaction.getErasedType()) .setShareable(GraphtUtils.isShareable(currentNode)) .setShared(!unsharedNodes.contains(currentNode)) .setIsProvided(true) .build(); GVEdge pEdge = EdgeBuilder.create(pNode.getTarget() + ":e", pid) .set("style", "dotted") .set("dir", "back") .set("arrowhead", "vee") .build(); return Pair.of(pNode, pEdge); }
assert tcsat != null; Satisfaction tsat = tcsat.getSatisfaction(); Object val = tsat.visit(new AbstractSatisfactionVisitor<Object>(null) { @Override public Object visitInstance(Object instance) {
public DAGNode<Component, Dependency> processNode(@Nonnull DAGNode<Component, Dependency> node, @Nonnull DAGNode<Component, Dependency> original) { Component label = node.getLabel(); if (!label.getSatisfaction().hasInstance()) { Satisfaction instanceSat = Satisfactions.nullOfType(label.getSatisfaction().getErasedType()); Component newLbl = Component.create(instanceSat, label.getCachePolicy()); // build new node with replacement label DAGNodeBuilder<Component,Dependency> bld = DAGNode.newBuilder(newLbl); // retain all non-transient edges for (DAGEdge<Component,Dependency> edge: node.getOutgoingEdges()) { if (!GraphtUtils.edgeIsTransient(edge)) { bld.addEdge(edge.getTail(), edge.getLabel()); } } DAGNode<Component,Dependency> repl = bld.build(); logger.debug("simulating instantiation of {}", node); return repl; } else { return node; } } }
@Override public Desire restrict(Satisfaction satis) { return new ReflectionDesire(satis.getErasedType(), injectPoint, satis); }
private static boolean satIsNull(Satisfaction sat) { return sat.visit(new AbstractSatisfactionVisitor<Boolean>(false) { @Override public Boolean visitNull() { return true; } }); } }