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 com.google.common.base.Predicate;
23
24 import javax.annotation.Nullable;
25 import javax.inject.Qualifier;
26 import java.io.Serializable;
27 import java.lang.annotation.Annotation;
28
29
30 /**
31 * <p>
32 * QualifierMatcher encapsulates the logic used to determine if a BindRule or
33 * ContextElementMatcher match a particular Qualifier. Common qualifier matching rules
34 * are:
35 * <ol>
36 * <li>Any qualifier</li>
37 * <li>No qualifier</li>
38 * <li>Annotation type</li>
39 * <li>Annotation instance equality</li>
40 * </ol>
41 * All QualifierMatchers created by the same InjectSPI must be comparable,
42 * matchers from different SPIs do not need to be comparable.
43 *
44 * @author <a href="http://grouplens.org">GroupLens Research</a>
45 */
46 public interface QualifierMatcher extends Predicate<Annotation>, Comparable<QualifierMatcher>, Serializable {
47 /**
48 * Return true if this matcher matches the given qualifier annotation. It
49 * can be assumed that the annotation type has been annotated with
50 * {@link Qualifier}. The qualifier will be null if the injection point
51 * being matched did not have a qualifier.
52 *
53 * @param q The qualifier to match
54 * @return True if matched
55 */
56 boolean matches(@Nullable Annotation q);
57
58 /**
59 * Return true if this matcher matches the given qualifier annotation. It
60 * can be assumed that the annotation type has been annotated with
61 * {@link Qualifier}. The qualifier will be null if the injection point
62 * being matched did not have a qualifier.
63 *
64 * @param q The qualifier to match
65 * @return True if matched
66 */
67 @Override
68 boolean apply(@Nullable Annotation q);
69
70 /**
71 * Get the priority of this matcher. Lower priority values have precedence in selecting
72 * the final bind rule. All Grapht matchers have priorities of at least 0; negative
73 * priority values are reserved for custom extensions.
74 *
75 * @return The priority.
76 */
77 int getPriority();
78 }