author | jlahoda |
Tue, 13 Dec 2016 10:49:28 +0100 | |
changeset 42815 | 050370edaade |
parent 38919 | 88f6e6f58798 |
child 43567 | d0d89c3da7be |
permissions | -rw-r--r-- |
10 | 1 |
/* |
38919
88f6e6f58798
8159378: Correct wording of RoundEnvironment.getElementsAnnotatedWithAny
darcy
parents:
38606
diff
changeset
|
2 |
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package javax.annotation.processing; |
|
27 |
||
28 |
import javax.lang.model.element.Element; |
|
29 |
import javax.lang.model.element.TypeElement; |
|
38606
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
30 |
import java.util.LinkedHashSet; |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
31 |
import java.util.Collections; |
10 | 32 |
import java.util.Set; |
33 |
import java.lang.annotation.Annotation; |
|
34 |
||
35 |
/** |
|
36 |
* An annotation processing tool framework will {@linkplain |
|
37 |
* Processor#process provide an annotation processor with an object |
|
38 |
* implementing this interface} so that the processor can query for |
|
39 |
* information about a round of annotation processing. |
|
40 |
* |
|
41 |
* @author Joseph D. Darcy |
|
42 |
* @author Scott Seligman |
|
43 |
* @author Peter von der Ahé |
|
44 |
* @since 1.6 |
|
45 |
*/ |
|
46 |
public interface RoundEnvironment { |
|
47 |
/** |
|
48 |
* Returns {@code true} if types generated by this round will not |
|
49 |
* be subject to a subsequent round of annotation processing; |
|
50 |
* returns {@code false} otherwise. |
|
51 |
* |
|
52 |
* @return {@code true} if types generated by this round will not |
|
53 |
* be subject to a subsequent round of annotation processing; |
|
54 |
* returns {@code false} otherwise |
|
55 |
*/ |
|
56 |
boolean processingOver(); |
|
57 |
||
58 |
/** |
|
59 |
* Returns {@code true} if an error was raised in the prior round |
|
60 |
* of processing; returns {@code false} otherwise. |
|
61 |
* |
|
62 |
* @return {@code true} if an error was raised in the prior round |
|
63 |
* of processing; returns {@code false} otherwise |
|
64 |
*/ |
|
65 |
boolean errorRaised(); |
|
66 |
||
67 |
/** |
|
68 |
* Returns the root elements for annotation processing generated |
|
69 |
* by the prior round. |
|
70 |
* |
|
71 |
* @return the root elements for annotation processing generated |
|
72 |
* by the prior round, or an empty set if there were none |
|
73 |
*/ |
|
74 |
Set<? extends Element> getRootElements(); |
|
75 |
||
76 |
/** |
|
77 |
* Returns the elements annotated with the given annotation type. |
|
78 |
* The annotation may appear directly or be inherited. Only |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
38919
diff
changeset
|
79 |
* package elements, module elements, and type elements <i>included</i> in this |
10 | 80 |
* round of annotation processing, or declarations of members, |
81 |
* constructors, parameters, or type parameters declared within |
|
82 |
* those, are returned. Included type elements are {@linkplain |
|
83 |
* #getRootElements root types} and any member types nested within |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
38919
diff
changeset
|
84 |
* them. Elements of a package are not considered included simply |
10 | 85 |
* because a {@code package-info} file for that package was |
86 |
* created. |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
38919
diff
changeset
|
87 |
* Likewise, elements of a module are not considered included |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
38919
diff
changeset
|
88 |
* simply because a {@code module-info} file for that module was |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
38919
diff
changeset
|
89 |
* created |
10 | 90 |
* |
91 |
* @param a annotation type being requested |
|
92 |
* @return the elements annotated with the given annotation type, |
|
93 |
* or an empty set if there are none |
|
94 |
* @throws IllegalArgumentException if the argument does not |
|
95 |
* represent an annotation type |
|
96 |
*/ |
|
97 |
Set<? extends Element> getElementsAnnotatedWith(TypeElement a); |
|
98 |
||
99 |
/** |
|
38606
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
100 |
* Returns the elements annotated with one or more of the given |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
101 |
* annotation types. |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
102 |
* |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
103 |
* @apiNote This method may be useful when processing repeating |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
104 |
* annotations by looking for an annotation type and its |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
105 |
* containing annotation type at the same time. |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
106 |
* |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
107 |
* @implSpec The default implementation of this method creates an |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
108 |
* empty result set, iterates over the annotations in the argument |
38919
88f6e6f58798
8159378: Correct wording of RoundEnvironment.getElementsAnnotatedWithAny
darcy
parents:
38606
diff
changeset
|
109 |
* array calling {@link #getElementsAnnotatedWith(TypeElement)} on |
38606
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
110 |
* each annotation and adding those results to the result |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
111 |
* set. Finally, the contents of the result set are returned as an |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
112 |
* unmodifiable set. |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
113 |
* |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
114 |
* @param annotations annotation types being requested |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
115 |
* @return the elements annotated with one or more of the given |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
116 |
* annotation types, or an empty set if there are none |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
117 |
* @throws IllegalArgumentException if the any elements of the |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
118 |
* argument set do not represent an annotation type |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
119 |
* @jls 9.6.3 Repeatable Annotation Types |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
120 |
* @since 9 |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
121 |
*/ |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
122 |
default Set<? extends Element> getElementsAnnotatedWithAny(TypeElement... annotations){ |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
123 |
// Use LinkedHashSet rather than HashSet for predictability |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
124 |
Set<Element> result = new LinkedHashSet<>(); |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
125 |
for (TypeElement annotation : annotations) { |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
126 |
result.addAll(getElementsAnnotatedWith(annotation)); |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
127 |
} |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
128 |
return Collections.unmodifiableSet(result); |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
129 |
} |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
130 |
|
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
131 |
/** |
10 | 132 |
* Returns the elements annotated with the given annotation type. |
133 |
* The annotation may appear directly or be inherited. Only |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
38919
diff
changeset
|
134 |
* package elements, module elements, and type elements <i>included</i> in this |
10 | 135 |
* round of annotation processing, or declarations of members, |
136 |
* constructors, parameters, or type parameters declared within |
|
137 |
* those, are returned. Included type elements are {@linkplain |
|
138 |
* #getRootElements root types} and any member types nested within |
|
139 |
* them. Elements in a package are not considered included simply |
|
140 |
* because a {@code package-info} file for that package was |
|
141 |
* created. |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
38919
diff
changeset
|
142 |
* Likewise, elements of a module are not considered included |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
38919
diff
changeset
|
143 |
* simply because a {@code module-info} file for that module was |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
38919
diff
changeset
|
144 |
* created |
10 | 145 |
* |
146 |
* @param a annotation type being requested |
|
147 |
* @return the elements annotated with the given annotation type, |
|
148 |
* or an empty set if there are none |
|
149 |
* @throws IllegalArgumentException if the argument does not |
|
150 |
* represent an annotation type |
|
151 |
*/ |
|
152 |
Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a); |
|
38606
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
153 |
|
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
154 |
/** |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
155 |
* Returns the elements annotated with one or more of the given |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
156 |
* annotation types. |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
157 |
* |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
158 |
* @apiNote This method may be useful when processing repeating |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
159 |
* annotations by looking for an annotation type and its |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
160 |
* containing annotation type at the same time. |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
161 |
* |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
162 |
* @implSpec The default implementation of this method creates an |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
163 |
* empty result set, iterates over the annotations in the argument |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
164 |
* set calling {@link #getElementsAnnotatedWith(Class)} on |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
165 |
* each annotation and adding those results to the result |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
166 |
* set. Finally, the contents of the result set are returned as an |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
167 |
* unmodifiable set. |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
168 |
* |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
169 |
* @param annotations annotation types being requested |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
170 |
* @return the elements annotated with one or more of the given |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
171 |
* annotation types, or an empty set if there are none |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
172 |
* @throws IllegalArgumentException if the any elements of the |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
173 |
* argument set do not represent an annotation type |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
174 |
* @jls 9.6.3 Repeatable Annotation Types |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
175 |
* @since 9 |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
176 |
*/ |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
177 |
default Set<? extends Element> getElementsAnnotatedWithAny(Set<Class<? extends Annotation>> annotations){ |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
178 |
// Use LinkedHashSet rather than HashSet for predictability |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
179 |
Set<Element> result = new LinkedHashSet<>(); |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
180 |
for (Class<? extends Annotation> annotation : annotations) { |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
181 |
result.addAll(getElementsAnnotatedWith(annotation)); |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
182 |
} |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
183 |
return Collections.unmodifiableSet(result); |
6b708cd90241
8032230: Enhance javax.a.p.RoundEnvironment after repeating annotations
darcy
parents:
25874
diff
changeset
|
184 |
} |
10 | 185 |
} |