duke@1: /* darcy@232: * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. Sun designates this duke@1: * particular file as subject to the "Classpath" exception as provided duke@1: * by Sun in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * duke@1: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: * CA 95054 USA or visit www.sun.com if you need additional information or duke@1: * have any questions. duke@1: */ duke@1: duke@1: package com.sun.tools.javac.processing; duke@1: duke@1: import java.lang.annotation.Annotation; duke@1: import com.sun.tools.javac.tree.JCTree.*; duke@1: import javax.annotation.processing.*; duke@1: import javax.lang.model.element.*; duke@1: import javax.lang.model.type.DeclaredType; duke@1: import javax.lang.model.type.TypeMirror; duke@1: import javax.lang.model.util.*; duke@1: import java.util.*; duke@1: duke@1: /** duke@1: * Object providing state about a prior round of annotation processing. duke@1: * duke@1: *
This is NOT part of any API supported by Sun Microsystems.
duke@1: * If you write code that depends on this, you do so at your own risk.
duke@1: * This code and its internal interfaces are subject to change or
duke@1: * deletion without notice.
duke@1: */
duke@1: public class JavacRoundEnvironment implements RoundEnvironment {
duke@1: // Default equals and hashCode methods are okay.
duke@1:
duke@1: private final boolean processingOver;
duke@1: private final boolean errorRaised;
duke@1: private final ProcessingEnvironment processingEnv;
duke@1:
duke@1: // Caller must pass in an immutable set
duke@1: private final Set extends Element> rootElements;
duke@1:
duke@1: JavacRoundEnvironment(boolean processingOver,
duke@1: boolean errorRaised,
duke@1: Set extends Element> rootElements,
duke@1: ProcessingEnvironment processingEnv) {
duke@1: this.processingOver = processingOver;
duke@1: this.errorRaised = errorRaised;
duke@1: this.rootElements = rootElements;
duke@1: this.processingEnv = processingEnv;
duke@1: }
duke@1:
duke@1: public String toString() {
duke@1: return String.format("[errorRaised=%b, rootElements=%s, processingOver=%b]",
duke@1: errorRaised,
duke@1: rootElements,
duke@1: processingOver);
duke@1: }
duke@1:
duke@1: public boolean processingOver() {
duke@1: return processingOver;
duke@1: }
duke@1:
duke@1: /**
duke@1: * Returns {@code true} if an error was raised in the prior round
duke@1: * of processing; returns {@code false} otherwise.
duke@1: *
duke@1: * @return {@code true} if an error was raised in the prior round
duke@1: * of processing; returns {@code false} otherwise.
duke@1: */
duke@1: public boolean errorRaised() {
duke@1: return errorRaised;
duke@1: }
duke@1:
duke@1: /**
duke@1: * Returns the type elements specified by the prior round.
duke@1: *
duke@1: * @return the types elements specified by the prior round, or an
duke@1: * empty set if there were none
duke@1: */
duke@1: public Set extends Element> getRootElements() {
duke@1: return rootElements;
duke@1: }
duke@1:
duke@1: private static final String NOT_AN_ANNOTATION_TYPE =
duke@1: "The argument does not represent an annotation type: ";
duke@1:
duke@1: /**
duke@1: * Returns the elements annotated with the given annotation type.
duke@1: * Only type elements included in this round of annotation
duke@1: * processing, or declarations of members, parameters, or type
duke@1: * parameters declared within those, are returned. Included type
duke@1: * elements are {@linkplain #getSpecifiedTypeElements specified
duke@1: * types} and any types nested within them.
duke@1: *
duke@1: * @param a annotation type being requested
duke@1: * @return the elements annotated with the given annotation type,
duke@1: * or an empty set if there are none
duke@1: */
duke@1: public Set extends Element> getElementsAnnotatedWith(TypeElement a) {
duke@1: Set