/** * Add a dependency of this component. * @param dep The dependency. * @return The builder (for chaining). */ public ComponentNodeBuilder addDependency(Desire dep) { Annotation q = dep.getInjectionPoint().getQualifier(); Class<?> type = dep.getDesiredType(); if (q == null) { dependencies.add(shortClassName(type)); } else { dependencies.add(shortAnnotation(q) + ": " + shortClassName(type)); } return this; }
/** * 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); } }
for (DAGEdge<Component, Dependency> e: edges) { Desire dep = e.getLabel().getInitialDesire(); Annotation q = dep.getInjectionPoint().getQualifier(); DAGNode<Component, Dependency> targetNode = e.getTail(); if (q != null && q.annotationType().getAnnotation(Parameter.class) != null) {
protected String format(InjectionPoint ip, Class<?> type) { if (type == null) { type = ip.getErasedType(); } String base = (ip.getQualifier() != null ? ip.getQualifier() + ":" : ""); String name = type == null ? null : type.getName(); return base + name; } }
@Override public boolean matches(Desire desire) { // bind rules match type by equality if (desire.getDesiredType().equals(depType)) { // if the type is equal, then rely on the qualifier matcher return qualifier.matches(desire.getInjectionPoint().getQualifier()); } // the type and {@link Qualifier}s are not a match, so return false return false; }
/** * Add a dependency of this component. * @param dep The dependency. * @return The builder (for chaining). */ public ComponentNodeBuilder addDependency(Desire dep) { Annotation q = dep.getInjectionPoint().getQualifier(); Class<?> type = dep.getDesiredType(); if (q == null) { dependencies.add(shortClassName(type)); } else { dependencies.add(shortAnnotation(q) + ": " + shortClassName(type)); } return this; }
@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; } }
/** * 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); } }
BindingResult result = null; Annotation qualifier = desire.getInjectionPoint().getQualifier();
for (DAGEdge<Component, Dependency> e: edges) { Desire dep = e.getLabel().getInitialDesire(); Annotation q = dep.getInjectionPoint().getQualifier(); DAGNode<Component, Dependency> targetNode = e.getTail(); if (q != null && q.annotationType().getAnnotation(Parameter.class) != null) {
Desire providedDesire = Desires.create(desire.getInjectionPoint().getQualifier(), providedType, desire.getInjectionPoint().isNullable());