View Javadoc

1   /*
2    * Grapht, an open source dependency injector.
3    * Copyright 2014-2015 various contributors (see CONTRIBUTORS.txt)
4    * Copyright 2010-2014 Regents of the University of Minnesota
5    *
6    * This program is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU Lesser General Public License as
8    * published by the Free Software Foundation; either version 2.1 of the
9    * License, or (at your option) any later version.
10   *
11   * This program is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14   * details.
15   *
16   * You should have received a copy of the GNU General Public License along with
17   * this program; if not, write to the Free Software Foundation, Inc., 51
18   * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19   */
20  package org.grouplens.grapht.reflect;
21  
22  import javax.annotation.Nonnull;
23  import javax.annotation.Nullable;
24  import java.io.Serializable;
25  import java.lang.annotation.Annotation;
26  import java.lang.reflect.Member;
27  import java.lang.reflect.Type;
28  import java.util.Collection;
29  
30  
31  /**
32   * InjectionPoint represents a point of injection for an instantiable type.
33   * Examples include a constructor parameter, a setter method, or a field.
34   *
35   * @author <a href="http://grouplens.org">GroupLens Research</a>
36   */
37  public interface InjectionPoint extends Serializable {
38      /**
39       * Return the type required to satisfy the injection point.
40       *
41       * @return The type of the injection point
42       */
43      Type getType();
44  
45      /**
46       * @return Return the erased type of {@link #getType()}
47       */
48      Class<?> getErasedType();
49  
50      /**
51       * Return the qualifier annotation added to the injection point. The
52       * returned annotation's type will have been annotated with
53       * {@link javax.inject.Qualifier}. If the injection point is not qualified, this will
54       * return null.
55       *
56       * @return Any qualifier applied to the injection point
57       */
58      @Nullable
59      Annotation getQualifier();
60  
61      /**
62       * Return the attribute of type A that is applied to the injection point. If
63       * the injection point does not have an attribute of type {@code A}, then null is
64       * returned.
65       *
66       * @param atype Attribute annotation type.  It must be annotated with {@link org.grouplens.grapht.annotation.Attribute}.
67       * @return The instance of A applied to the injection point, or null
68       * @throws NullPointerException if atype is null
69       */
70      @Nullable <A extends Annotation> A getAttribute(Class<A> atype);
71  
72      /**
73       * @return Immutable collection of attribute annotations (does not include
74       *         the qualifier)
75       */
76      @Nonnull
77      Collection<Annotation> getAttributes();
78  
79      /**
80       * Return the Member that produced this injection point. Synthetic injection
81       * points can have a null member.
82       *
83       * @return The Member that produces this injection point
84       */
85      @Nullable Member getMember();
86  
87      /**
88       * @return True if this injection point accepts null values
89       */
90      boolean isNullable();
91  }