-
Notifications
You must be signed in to change notification settings - Fork 669
/
Copy pathRoundEnvironment.java
197 lines (187 loc) · 8.76 KB
/
RoundEnvironment.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.annotation.processing;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
/**
* An annotation processing tool framework will {@linkplain
* Processor#process provide an annotation processor with an object
* implementing this interface} so that the processor can query for
* information about a round of annotation processing.
*
* @author Joseph D. Darcy
* @author Scott Seligman
* @author Peter von der Ahé
* @since 1.6
*/
/*
* 代表上一轮处理之后余下的待处理信息
* 在第一轮处理之前,会有一个虚拟的第0轮处理,代表注解未经处理的原始状态
*/
public interface RoundEnvironment {
/**
* Returns {@code true} if types generated by this round will not
* be subject to a subsequent round of annotation processing;
* returns {@code false} otherwise.
*
* @return {@code true} if types generated by this round will not
* be subject to a subsequent round of annotation processing;
* returns {@code false} otherwise
*/
// 如果此轮生成的类型不受后续轮注解处理的影响,则返回true,否则返回false。
boolean processingOver();
/**
* Returns {@code true} if an error was raised in the prior round
* of processing; returns {@code false} otherwise.
*
* @return {@code true} if an error was raised in the prior round
* of processing; returns {@code false} otherwise
*/
// 如果在前一轮处理中引发错误,则返回true;否则返回false。
boolean errorRaised();
/**
* Returns the {@linkplain Processor root elements} for annotation processing generated
* by the prior round.
*
* @return the root elements for annotation processing generated
* by the prior round, or an empty set if there were none
*/
// 返回前一轮生成的根元素(本轮可以使用的根元素,包括类、包,有没有注解都算)
Set<? extends Element> getRootElements();
/**
* Returns the elements annotated with the given annotation type.
* The annotation may appear directly or be inherited. Only
* package elements, module elements, and type elements <i>included</i> in this
* round of annotation processing, or declarations of members,
* constructors, parameters, or type parameters declared within
* those, are returned. Included type elements are {@linkplain
* #getRootElements root types} and any member types nested within
* them. Elements of a package are not considered included simply
* because a {@code package-info} file for that package was
* created.
* Likewise, elements of a module are not considered included
* simply because a {@code module-info} file for that module was
* created
*
* @param a annotation type being requested
* @return the elements annotated with the given annotation type,
* or an empty set if there are none
* @throws IllegalArgumentException if the argument does not
* represent an annotation type
*/
// 返回使用给定注解类型注解的元素(检测不到局部类)
Set<? extends Element> getElementsAnnotatedWith(TypeElement a);
/**
* Returns the elements annotated with one or more of the given
* annotation types.
*
* @apiNote This method may be useful when processing repeating
* annotations by looking for an annotation type and its
* containing annotation type at the same time.
*
* @implSpec The default implementation of this method creates an
* empty result set, iterates over the annotations in the argument
* array calling {@link #getElementsAnnotatedWith(TypeElement)} on
* each annotation and adding those results to the result
* set. Finally, the contents of the result set are returned as an
* unmodifiable set.
*
* @param annotations annotation types being requested
* @return the elements annotated with one or more of the given
* annotation types, or an empty set if there are none
* @throws IllegalArgumentException if the any elements of the
* argument set do not represent an annotation type
* @jls 9.6.3 Repeatable Annotation Types
* @since 9
*/
// 返回任一使用给定注解类型注解的元素(检测不到局部类)
default Set<? extends Element> getElementsAnnotatedWithAny(TypeElement... annotations){
// Use LinkedHashSet rather than HashSet for predictability
Set<Element> result = new LinkedHashSet<>();
for (TypeElement annotation : annotations) {
result.addAll(getElementsAnnotatedWith(annotation));
}
return Collections.unmodifiableSet(result);
}
/**
* Returns the elements annotated with the given annotation type.
* The annotation may appear directly or be inherited. Only
* package elements, module elements, and type elements <i>included</i> in this
* round of annotation processing, or declarations of members,
* constructors, parameters, or type parameters declared within
* those, are returned. Included type elements are {@linkplain
* #getRootElements root types} and any member types nested within
* them. Elements in a package are not considered included simply
* because a {@code package-info} file for that package was
* created.
* Likewise, elements of a module are not considered included
* simply because a {@code module-info} file for that module was
* created
*
* @param a annotation type being requested
* @return the elements annotated with the given annotation type,
* or an empty set if there are none
* @throws IllegalArgumentException if the argument does not
* represent an annotation type
*/
// 返回使用给定注解类型注解的元素(检测不到局部类)
Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a);
/**
* Returns the elements annotated with one or more of the given
* annotation types.
*
* @apiNote This method may be useful when processing repeating
* annotations by looking for an annotation type and its
* containing annotation type at the same time.
*
* @implSpec The default implementation of this method creates an
* empty result set, iterates over the annotations in the argument
* set calling {@link #getElementsAnnotatedWith(Class)} on
* each annotation and adding those results to the result
* set. Finally, the contents of the result set are returned as an
* unmodifiable set.
*
* @param annotations annotation types being requested
* @return the elements annotated with one or more of the given
* annotation types, or an empty set if there are none
* @throws IllegalArgumentException if the any elements of the
* argument set do not represent an annotation type
* @jls 9.6.3 Repeatable Annotation Types
* @since 9
*/
// 返回任一使用给定注解类型注解的元素(检测不到局部类)
default Set<? extends Element> getElementsAnnotatedWithAny(Set<Class<? extends Annotation>> annotations){
// Use LinkedHashSet rather than HashSet for predictability
Set<Element> result = new LinkedHashSet<>();
for (Class<? extends Annotation> annotation : annotations) {
result.addAll(getElementsAnnotatedWith(annotation));
}
return Collections.unmodifiableSet(result);
}
}