A request to inject the instance fields and methods of an instance. Requests are created explicitly in a module using com.google.inject.Binder#requestInjection(Object) requestInjection() statements: requestInjection(serviceInstance); @author mikeward@google.com (Mike Ward)
| 36 | * @since 2.0 |
| 37 | */ |
| 38 | public final class InjectionRequest<T> implements Element { |
| 39 | |
| 40 | private final Object source; |
| 41 | private final TypeLiteral<T> type; |
| 42 | private final T instance; |
| 43 | |
| 44 | public InjectionRequest(Object source, TypeLiteral<T> type, T instance) { |
| 45 | this.source = checkNotNull(source, "source"); |
| 46 | this.type = checkNotNull(type, "type"); |
| 47 | this.instance = instance; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public Object getSource() { |
| 52 | return source; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the instance that injection is being requested on. This may be null for injection |
| 57 | * requests returned from an Injector, to allow the injector to reclaim memory. |
| 58 | */ |
| 59 | public T getInstance() { |
| 60 | return instance; |
| 61 | } |
| 62 | |
| 63 | public TypeLiteral<T> getType() { |
| 64 | return type; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Returns the instance methods and fields of {@code instance} that will be injected to fulfill |
| 69 | * this request. |
| 70 | * |
| 71 | * @return a possibly empty set of injection points. The set has a specified iteration order. All |
| 72 | * fields are returned and then all methods. Within the fields, supertype fields are returned |
| 73 | * before subtype fields. Similarly, supertype methods are returned before subtype methods. |
| 74 | * @throws ConfigurationException if there is a malformed injection point on the class of {@code |
| 75 | * instance}, such as a field with multiple binding annotations. The exception's {@link |
| 76 | * ConfigurationException#getPartialValue() partial value} is a {@code Set<InjectionPoint>} of |
| 77 | * the valid injection points. |
| 78 | */ |
| 79 | public Set<InjectionPoint> getInjectionPoints() throws ConfigurationException { |
| 80 | return InjectionPoint.forInstanceMethodsAndFields(type); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public <R> R acceptVisitor(ElementVisitor<R> visitor) { |
| 85 | return visitor.visit(this); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public void applyTo(Binder binder) { |
| 90 | binder.withSource(getSource()).requestInjection(type, instance); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public boolean equals(Object obj) { |
| 95 | return obj instanceof InjectionRequest |
nothing calls this directly
no outgoing calls
no test coverage detected