1 /*
2 * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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
86 * created.
87 *
88 * @param a annotation type being requested
89 * @return the elements annotated with the given annotation type,
90 * or an empty set if there are none
91 * @throws IllegalArgumentException if the argument does not
92 * represent an annotation type
93 */
94 Set<? extends Element> getElementsAnnotatedWith(TypeElement a);
95
96 /**
97 * Returns the elements annotated with one or more of the given
98 * annotation types.
99 *
100 * @apiNote This method may be useful when processing repeating
101 * annotations by looking for an annotation type and its
102 * containing annotation type at the same time.
103 *
104 * @implSpec The default implementation of this method creates an
105 * empty result set, iterates over the annotations in the argument
106 * set calling {@link #getElementsAnnotatedWith(TypeElement)} on
107 * each annotation and adding those results to the result
108 * set. Finally, the contents of the result set are returned as an
109 * unmodifiable set.
110 *
111 * @param annotations annotation types being requested
112 * @return the elements annotated with one or more of the given
113 * annotation types, or an empty set if there are none
114 * @throws IllegalArgumentException if the any elements of the
115 * argument set do not represent an annotation type
116 * @jls 9.6.3 Repeatable Annotation Types
117 * @since 9
118 */
119 default Set<? extends Element> getElementsAnnotatedWithAny(TypeElement... annotations){
120 // Use LinkedHashSet rather than HashSet for predictability
121 Set<Element> result = new LinkedHashSet<>();
122 for (TypeElement annotation : annotations) {
123 result.addAll(getElementsAnnotatedWith(annotation));
124 }
125 return Collections.unmodifiableSet(result);
126 }
|
1 /*
2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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
86 * created.
87 *
88 * @param a annotation type being requested
89 * @return the elements annotated with the given annotation type,
90 * or an empty set if there are none
91 * @throws IllegalArgumentException if the argument does not
92 * represent an annotation type
93 */
94 Set<? extends Element> getElementsAnnotatedWith(TypeElement a);
95
96 /**
97 * Returns the elements annotated with one or more of the given
98 * annotation types.
99 *
100 * @apiNote This method may be useful when processing repeating
101 * annotations by looking for an annotation type and its
102 * containing annotation type at the same time.
103 *
104 * @implSpec The default implementation of this method creates an
105 * empty result set, iterates over the annotations in the argument
106 * array calling {@link #getElementsAnnotatedWith(TypeElement)} on
107 * each annotation and adding those results to the result
108 * set. Finally, the contents of the result set are returned as an
109 * unmodifiable set.
110 *
111 * @param annotations annotation types being requested
112 * @return the elements annotated with one or more of the given
113 * annotation types, or an empty set if there are none
114 * @throws IllegalArgumentException if the any elements of the
115 * argument set do not represent an annotation type
116 * @jls 9.6.3 Repeatable Annotation Types
117 * @since 9
118 */
119 default Set<? extends Element> getElementsAnnotatedWithAny(TypeElement... annotations){
120 // Use LinkedHashSet rather than HashSet for predictability
121 Set<Element> result = new LinkedHashSet<>();
122 for (TypeElement annotation : annotations) {
123 result.addAll(getElementsAnnotatedWith(annotation));
124 }
125 return Collections.unmodifiableSet(result);
126 }
|