src/share/classes/javax/annotation/processing/AbstractProcessor.java

Print this page




  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
  23  * questions.
  24  */
  25 
  26 package javax.annotation.processing;
  27 
  28 import java.util.Set;
  29 import java.util.HashSet;
  30 import java.util.Collections;

  31 import javax.lang.model.element.*;
  32 import javax.lang.model.SourceVersion;
  33 import javax.tools.Diagnostic;
  34 
  35 /**
  36  * An abstract annotation processor designed to be a convenient
  37  * superclass for most concrete annotation processors.  This class
  38  * examines annotation values to compute the {@linkplain
  39  * #getSupportedOptions options}, {@linkplain
  40  * #getSupportedAnnotationTypes annotations}, and {@linkplain
  41  * #getSupportedSourceVersion source version} supported by its
  42  * subtypes.
  43  *
  44  * <p>The getter methods may {@linkplain Messager#printMessage issue
  45  * warnings} about noteworthy conditions using the facilities available
  46  * after the processor has been {@linkplain #isInitialized
  47  * initialized}.
  48  *
  49  * <p>Subclasses are free to override the implementation and
  50  * specification of any of the methods in this class as long as the


 129         } else
 130             sv = ssv.value();
 131         return sv;
 132     }
 133 
 134 
 135     /**
 136      * Initializes the processor with the processing environment by
 137      * setting the {@code processingEnv} field to the value of the
 138      * {@code processingEnv} argument.  An {@code
 139      * IllegalStateException} will be thrown if this method is called
 140      * more than once on the same object.
 141      *
 142      * @param processingEnv environment to access facilities the tool framework
 143      * provides to the processor
 144      * @throws IllegalStateException if this method is called more than once.
 145      */
 146     public synchronized void init(ProcessingEnvironment processingEnv) {
 147         if (initialized)
 148             throw new IllegalStateException("Cannot call init more than once.");
 149         if (processingEnv == null)
 150             throw new NullPointerException("Tool provided null ProcessingEnvironment");
 151 
 152         this.processingEnv = processingEnv;
 153         initialized = true;
 154     }
 155 
 156     /**
 157      * {@inheritDoc}
 158      */
 159     public abstract boolean process(Set<? extends TypeElement> annotations,
 160                                     RoundEnvironment roundEnv);
 161 
 162     /**
 163      * Returns an empty iterable of completions.
 164      *
 165      * @param element {@inheritDoc}
 166      * @param annotation {@inheritDoc}
 167      * @param member {@inheritDoc}
 168      * @param userText {@inheritDoc}
 169      */
 170     public Iterable<? extends Completion> getCompletions(Element element,




  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
  23  * questions.
  24  */
  25 
  26 package javax.annotation.processing;
  27 
  28 import java.util.Set;
  29 import java.util.HashSet;
  30 import java.util.Collections;
  31 import java.util.Objects;
  32 import javax.lang.model.element.*;
  33 import javax.lang.model.SourceVersion;
  34 import javax.tools.Diagnostic;
  35 
  36 /**
  37  * An abstract annotation processor designed to be a convenient
  38  * superclass for most concrete annotation processors.  This class
  39  * examines annotation values to compute the {@linkplain
  40  * #getSupportedOptions options}, {@linkplain
  41  * #getSupportedAnnotationTypes annotations}, and {@linkplain
  42  * #getSupportedSourceVersion source version} supported by its
  43  * subtypes.
  44  *
  45  * <p>The getter methods may {@linkplain Messager#printMessage issue
  46  * warnings} about noteworthy conditions using the facilities available
  47  * after the processor has been {@linkplain #isInitialized
  48  * initialized}.
  49  *
  50  * <p>Subclasses are free to override the implementation and
  51  * specification of any of the methods in this class as long as the


 130         } else
 131             sv = ssv.value();
 132         return sv;
 133     }
 134 
 135 
 136     /**
 137      * Initializes the processor with the processing environment by
 138      * setting the {@code processingEnv} field to the value of the
 139      * {@code processingEnv} argument.  An {@code
 140      * IllegalStateException} will be thrown if this method is called
 141      * more than once on the same object.
 142      *
 143      * @param processingEnv environment to access facilities the tool framework
 144      * provides to the processor
 145      * @throws IllegalStateException if this method is called more than once.
 146      */
 147     public synchronized void init(ProcessingEnvironment processingEnv) {
 148         if (initialized)
 149             throw new IllegalStateException("Cannot call init more than once.");
 150         Objects.requireNonNull(processingEnv, "Tool provided null ProcessingEnvironment");

 151 
 152         this.processingEnv = processingEnv;
 153         initialized = true;
 154     }
 155 
 156     /**
 157      * {@inheritDoc}
 158      */
 159     public abstract boolean process(Set<? extends TypeElement> annotations,
 160                                     RoundEnvironment roundEnv);
 161 
 162     /**
 163      * Returns an empty iterable of completions.
 164      *
 165      * @param element {@inheritDoc}
 166      * @param annotation {@inheritDoc}
 167      * @param member {@inheritDoc}
 168      * @param userText {@inheritDoc}
 169      */
 170     public Iterable<? extends Completion> getCompletions(Element element,