--- old/src/java.compiler/share/classes/javax/annotation/processing/RoundEnvironment.java 2016-05-24 00:15:21.265929589 -0700 +++ new/src/java.compiler/share/classes/javax/annotation/processing/RoundEnvironment.java 2016-05-24 00:15:21.181929591 -0700 @@ -27,6 +27,8 @@ import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; +import java.util.LinkedHashSet; +import java.util.Collections; import java.util.Set; import java.lang.annotation.Annotation; @@ -92,6 +94,38 @@ Set 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 + * set 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 getElementsAnnotatedWithAny(TypeElement... annotations){ + // Use LinkedHashSet rather than HashSet for predictability + Set 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 and type elements included in this @@ -110,4 +144,36 @@ * represent an annotation type */ Set getElementsAnnotatedWith(Class 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 getElementsAnnotatedWithAny(Set> annotations){ + // Use LinkedHashSet rather than HashSet for predictability + Set result = new LinkedHashSet<>(); + for (Class annotation : annotations) { + result.addAll(getElementsAnnotatedWith(annotation)); + } + return Collections.unmodifiableSet(result); + } }