102 * empty set if there were none
103 */
104 @DefinedBy(Api.ANNOTATION_PROCESSING)
105 public Set<? extends Element> getRootElements() {
106 return rootElements;
107 }
108
109 /**
110 * Returns the elements annotated with the given annotation type.
111 * Only type elements <i>included</i> in this round of annotation
112 * processing, or declarations of members, parameters, type
113 * parameters, or record components declared within those, are returned.
114 * Included type elements are {@linkplain #getRootElements specified
115 * types} and any types nested within them.
116 *
117 * @param a annotation type being requested
118 * @return the elements annotated with the given annotation type,
119 * or an empty set if there are none
120 */
121 @DefinedBy(Api.ANNOTATION_PROCESSING)
122 @SuppressWarnings("removal")
123 public Set<? extends Element> getElementsAnnotatedWith(TypeElement a) {
124 throwIfNotAnnotation(a);
125
126 Set<Element> result = Collections.emptySet();
127 ElementScanner14<Set<Element>, TypeElement> scanner =
128 new AnnotationSetScanner(result);
129
130 for (Element element : rootElements)
131 result = scanner.scan(element, a);
132
133 return result;
134 }
135
136 @DefinedBy(Api.ANNOTATION_PROCESSING)
137 @SuppressWarnings("removal")
138 public Set<? extends Element> getElementsAnnotatedWithAny(TypeElement... annotations) {
139 // Don't bother to special-case annotations.length == 1 as
140 // return getElementsAnnotatedWith(annotations[0]);
141
142 Set<TypeElement> annotationSet = new LinkedHashSet<>(annotations.length);
143 for (TypeElement annotation : annotations) {
144 throwIfNotAnnotation(annotation);
145 annotationSet.add(annotation);
146 }
147
148 Set<Element> result = Collections.emptySet();
149 ElementScanner14<Set<Element>, Set<TypeElement>> scanner =
150 new AnnotationSetMultiScanner(result);
151
152 for (Element element : rootElements)
153 result = scanner.scan(element, annotationSet);
154
155 return result;
156 }
157
208 break;
209 }
210 }
211 e.accept(this, annotations);
212 return annotatedElements;
213 }
214
215 @Override @DefinedBy(Api.LANGUAGE_MODEL)
216 public Set<Element> visitModule(ModuleElement e, Set<TypeElement> annotations) {
217 // Do not scan a module
218 return annotatedElements;
219 }
220
221 @Override @DefinedBy(Api.LANGUAGE_MODEL)
222 public Set<Element> visitPackage(PackageElement e, Set<TypeElement> annotations) {
223 // Do not scan a package
224 return annotatedElements;
225 }
226 }
227
228 @SuppressWarnings("removal")
229 private static abstract class ElementScanningIncludingTypeParameters<R, P>
230 extends ElementScanner14<R, P> {
231
232 protected ElementScanningIncludingTypeParameters(R defaultValue) {
233 super(defaultValue);
234 }
235
236 @Override @DefinedBy(Api.LANGUAGE_MODEL)
237 public R visitType(TypeElement e, P p) {
238 // Type parameters are not considered to be enclosed by a type
239 scan(e.getTypeParameters(), p);
240 return super.visitType(e, p);
241 }
242
243 @Override @DefinedBy(Api.LANGUAGE_MODEL)
244 public R visitExecutable(ExecutableElement e, P p) {
245 // Type parameters are not considered to be enclosed by an executable
246 scan(e.getTypeParameters(), p);
247 return super.visitExecutable(e, p);
248 }
|
102 * empty set if there were none
103 */
104 @DefinedBy(Api.ANNOTATION_PROCESSING)
105 public Set<? extends Element> getRootElements() {
106 return rootElements;
107 }
108
109 /**
110 * Returns the elements annotated with the given annotation type.
111 * Only type elements <i>included</i> in this round of annotation
112 * processing, or declarations of members, parameters, type
113 * parameters, or record components declared within those, are returned.
114 * Included type elements are {@linkplain #getRootElements specified
115 * types} and any types nested within them.
116 *
117 * @param a annotation type being requested
118 * @return the elements annotated with the given annotation type,
119 * or an empty set if there are none
120 */
121 @DefinedBy(Api.ANNOTATION_PROCESSING)
122 @SuppressWarnings("preview")
123 public Set<? extends Element> getElementsAnnotatedWith(TypeElement a) {
124 throwIfNotAnnotation(a);
125
126 Set<Element> result = Collections.emptySet();
127 ElementScanner14<Set<Element>, TypeElement> scanner =
128 new AnnotationSetScanner(result);
129
130 for (Element element : rootElements)
131 result = scanner.scan(element, a);
132
133 return result;
134 }
135
136 @DefinedBy(Api.ANNOTATION_PROCESSING)
137 @SuppressWarnings("preview")
138 public Set<? extends Element> getElementsAnnotatedWithAny(TypeElement... annotations) {
139 // Don't bother to special-case annotations.length == 1 as
140 // return getElementsAnnotatedWith(annotations[0]);
141
142 Set<TypeElement> annotationSet = new LinkedHashSet<>(annotations.length);
143 for (TypeElement annotation : annotations) {
144 throwIfNotAnnotation(annotation);
145 annotationSet.add(annotation);
146 }
147
148 Set<Element> result = Collections.emptySet();
149 ElementScanner14<Set<Element>, Set<TypeElement>> scanner =
150 new AnnotationSetMultiScanner(result);
151
152 for (Element element : rootElements)
153 result = scanner.scan(element, annotationSet);
154
155 return result;
156 }
157
208 break;
209 }
210 }
211 e.accept(this, annotations);
212 return annotatedElements;
213 }
214
215 @Override @DefinedBy(Api.LANGUAGE_MODEL)
216 public Set<Element> visitModule(ModuleElement e, Set<TypeElement> annotations) {
217 // Do not scan a module
218 return annotatedElements;
219 }
220
221 @Override @DefinedBy(Api.LANGUAGE_MODEL)
222 public Set<Element> visitPackage(PackageElement e, Set<TypeElement> annotations) {
223 // Do not scan a package
224 return annotatedElements;
225 }
226 }
227
228 @SuppressWarnings("preview")
229 private static abstract class ElementScanningIncludingTypeParameters<R, P>
230 extends ElementScanner14<R, P> {
231
232 protected ElementScanningIncludingTypeParameters(R defaultValue) {
233 super(defaultValue);
234 }
235
236 @Override @DefinedBy(Api.LANGUAGE_MODEL)
237 public R visitType(TypeElement e, P p) {
238 // Type parameters are not considered to be enclosed by a type
239 scan(e.getTypeParameters(), p);
240 return super.visitType(e, p);
241 }
242
243 @Override @DefinedBy(Api.LANGUAGE_MODEL)
244 public R visitExecutable(ExecutableElement e, P p) {
245 // Type parameters are not considered to be enclosed by an executable
246 scan(e.getTypeParameters(), p);
247 return super.visitExecutable(e, p);
248 }
|