/** * 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; }
private static List<String> extractOrderKey(DAGEdge<Component,Dependency> node) { Desire desire = node.getLabel().getInitialDesire(); InjectionPoint ip = desire.getInjectionPoint(); List<String> key = new ArrayList<>(4); Member member = ip.getMember(); if (member instanceof Constructor) { key.add("0: constructor"); key.add(Integer.toString(ip.getParameterIndex())); } else if (member instanceof Method) { key.add("1: setter"); key.add(member.getName()); key.add(Integer.toString(ip.getParameterIndex())); } else if (member instanceof Field) { key.add("2: field"); key.add(member.getName()); } else if (ip instanceof SimpleInjectionPoint) { key.add("5: simple"); } else { key.add("9: unknown"); key.add(ip.getClass().getName()); } return key; }
/** * Determine whether a desire is transient. * * @param d The desire to test. * @return {@code true} if the desire is transient. */ public static boolean desireIsTransient(@Nonnull Desire d) { InjectionPoint ip = d.getInjectionPoint(); return ip.getAttribute(Transient.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; } }
Type providerType = desire.getInjectionPoint().getType(); if (providerType instanceof ParameterizedType) { Desire providedDesire = Desires.create(desire.getInjectionPoint().getQualifier(), providedType, desire.getInjectionPoint().isNullable());
/** * @return The Class type that could not be instantiated, or configured by * injection. */ public Class<?> getType() { if (type != null) { return type; } else if (injectionPoint != null) { Member target = injectionPoint.getMember(); if (target != null) { return target.getDeclaringClass(); } } return null; }
Preconditions.isAssignable(injectPoint.getErasedType(), desiredType); if (satisfaction != null) { Preconditions.isAssignable(desiredType, satisfaction.getErasedType()); satisfaction = new ClassSatisfaction(desiredType); } else if (injectPoint.isNullable()) {
/** * Create a ReflectionDesire that immediately wraps the given * InjectionPoint. The desired type equals the type declared by the * injection point. The created desire will have a satisfaction if the * injection point's type is satisfiable. * * @param injectPoint The injection point to wrap * @throws NullPointerException if injectPoint is null */ public ReflectionDesire(InjectionPoint injectPoint) { this(injectPoint.getErasedType(), injectPoint, null); }
protected String format(InjectionPoint ip) { return format(ip, ip.getErasedType()); }
/** * 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); } }
private static List<String> extractOrderKey(DAGEdge<Component,Dependency> node) { Desire desire = node.getLabel().getInitialDesire(); InjectionPoint ip = desire.getInjectionPoint(); List<String> key = new ArrayList<>(4); Member member = ip.getMember(); if (member instanceof Constructor) { key.add("0: constructor"); key.add(Integer.toString(ip.getParameterIndex())); } else if (member instanceof Method) { key.add("1: setter"); key.add(member.getName()); key.add(Integer.toString(ip.getParameterIndex())); } else if (member instanceof Field) { key.add("2: field"); key.add(member.getName()); } else if (ip instanceof SimpleInjectionPoint) { key.add("5: simple"); } else { key.add("9: unknown"); key.add(ip.getClass().getName()); } return key; }
/** * Determine whether a desire is transient. * * @param d The desire to test. * @return {@code true} if the desire is transient. */ public static boolean desireIsTransient(@Nonnull Desire d) { InjectionPoint ip = d.getInjectionPoint(); return ip.getAttribute(Transient.class) != 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) {
@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) {