langtools/src/share/classes/javax/annotation/processing/Processor.java
author poonam
Tue, 26 Feb 2013 08:58:20 -0800
changeset 15808 c75f11af1033
parent 9303 eae35c201e19
child 18669 99572d59c916
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     2
 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package javax.annotation.processing;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import javax.lang.model.element.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import javax.lang.model.SourceVersion;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * The interface for an annotation processor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * <p>Annotation processing happens in a sequence of {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * javax.annotation.processing.RoundEnvironment rounds}.  On each
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * round, a processor may be asked to {@linkplain #process process} a
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * subset of the annotations found on the source and class files
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * produced by a prior round.  The inputs to the first round of
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * processing are the initial inputs to a run of the tool; these
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * initial inputs can be regarded as the output of a virtual zeroth
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * round of processing.  If a processor was asked to process on a
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * given round, it will be asked to process on subsequent rounds,
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * including the last round, even if there are no annotations for it
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * to process.  The tool infrastructure may also ask a processor to
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * process files generated implicitly by the tool's operation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * <p> Each implementation of a {@code Processor} must provide a
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * public no-argument constructor to be used by tools to instantiate
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * the processor.  The tool infrastructure will interact with classes
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * implementing this interface as follows:
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * <ol>
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 * <li>If an existing {@code Processor} object is not being used, to
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 * create an instance of a processor the tool calls the no-arg
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 * constructor of the processor class.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 * <li>Next, the tool calls the {@link #init init} method with
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 * an appropriate {@code ProcessingEnvironment}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 * <li>Afterwards, the tool calls {@link #getSupportedAnnotationTypes
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 * getSupportedAnnotationTypes}, {@link #getSupportedOptions
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 * getSupportedOptions}, and {@link #getSupportedSourceVersion
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 * getSupportedSourceVersion}.  These methods are only called once per
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 * run, not on each round.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 * <li>As appropriate, the tool calls the {@link #process process}
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 * method on the {@code Processor} object; a new {@code Processor}
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 * object is <em>not</em> created for each round.
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 * </ol>
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 * If a processor object is created and used without the above
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 * protocol being followed, then the processor's behavior is not
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 * defined by this interface specification.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
 * <p> The tool uses a <i>discovery process</i> to find annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 * processors and decide whether or not they should be run.  By
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 * configuring the tool, the set of potential processors can be
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 * controlled.  For example, for a {@link javax.tools.JavaCompiler
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 * JavaCompiler} the list of candidate processors to run can be
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
 * {@linkplain javax.tools.JavaCompiler.CompilationTask#setProcessors
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
 * set directly} or controlled by a {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
 * javax.tools.StandardLocation#ANNOTATION_PROCESSOR_PATH search path}
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
 * used for a {@linkplain java.util.ServiceLoader service-style}
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
 * lookup.  Other tool implementations may have different
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
 * configuration mechanisms, such as command line options; for
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
 * details, refer to the particular tool's documentation.  Which
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
 * processors the tool asks to {@linkplain #process run} is a function
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
 * of what annotations are present on the {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
 * RoundEnvironment#getRootElements root elements}, what {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
 * #getSupportedAnnotationTypes annotation types a processor
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
 * processes}, and whether or not a processor {@linkplain #process
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
 * claims the annotations it processes}.  A processor will be asked to
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
 * process a subset of the annotation types it supports, possibly an
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
 * empty set.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
 * For a given round, the tool computes the set of annotation types on
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
 * the root elements.  If there is at least one annotation type
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
 * present, as processors claim annotation types, they are removed
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
 * from the set of unmatched annotations.  When the set is empty or no
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
 * more processors are available, the round has run to completion.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
 * there are no annotation types present, annotation processing still
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
 * occurs but only <i>universal processors</i> which support
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
 * processing {@code "*"} can claim the (empty) set of annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
 * types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
 * <p>Note that if a processor supports {@code "*"} and returns {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
 * true}, all annotations are claimed.  Therefore, a universal
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
 * processor being used to, for example, implement additional validity
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
 * checks should return {@code false} so as to not prevent other such
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
 * checkers from being able to run.
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
 * <p>If a processor throws an uncaught exception, the tool may cease
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
 * other active annotation processors.  If a processor raises an
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
 * error, the current round will run to completion and the subsequent
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
 * round will indicate an {@linkplain RoundEnvironment#errorRaised
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
 * error was raised}.  Since annotation processors are run in a
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
 * cooperative environment, a processor should throw an uncaught
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
 * exception only in situations where no error recovery or reporting
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
 * is feasible.
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
 * <p>The tool environment is not required to support annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
 * processors that access environmental resources, either {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
 * RoundEnvironment per round} or {@linkplain ProcessingEnvironment
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
 * cross-round}, in a multi-threaded fashion.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
 * <p>If the methods that return configuration information about the
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
 * annotation processor return {@code null}, return other invalid
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
 * input, or throw an exception, the tool infrastructure must treat
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
 * this as an error condition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
 * <p>To be robust when running in different tool implementations, an
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
 * annotation processor should have the following properties:
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
 * <ol>
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
 * <li>The result of processing a given input is not a function of the presence or absence
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
 * of other inputs (orthogonality).
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
 * <li>Processing the same input produces the same output (consistency).
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
 * <li>Processing input <i>A</i> followed by processing input <i>B</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
 * is equivalent to processing <i>B</i> then <i>A</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
 * (commutativity)
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
 * <li>Processing an input does not rely on the presence of the output
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
 * of other annotation processors (independence)
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
 * </ol>
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
 * <p>The {@link Filer} interface discusses restrictions on how
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
 * processors can operate on files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
 * <p>Note that implementors of this interface may find it convenient
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
 * to extend {@link AbstractProcessor} rather than implementing this
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
 * interface directly.
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
 * @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
public interface Processor {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * Returns the options recognized by this processor.  An
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     * implementation of the processing tool must provide a way to
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     * pass processor-specific options distinctly from options passed
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * to the tool itself, see {@link ProcessingEnvironment#getOptions
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * getOptions}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * <p>Each string returned in the set must be a period separated
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * sequence of {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * javax.lang.model.SourceVersion#isIdentifier identifiers}:
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     * <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     * <dl>
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * <dt><i>SupportedOptionString:</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     * <dd><i>Identifiers</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * <dt><i>Identifiers:</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     * <dd> <i>Identifier</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     * <dd> <i>Identifier</i> {@code .} <i>Identifiers</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     * <dt><i>Identifier:</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     * <dd>Syntactic identifier, including keywords and literals
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     * </dl>
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     * <p> A tool might use this information to determine if any
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     * options provided by a user are unrecognized by any processor,
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     * in which case it may wish to report a warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     * @return the options recognized by this processor or an
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     *         empty collection if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     * @see javax.annotation.processing.SupportedOptions
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    Set<String> getSupportedOptions();
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     * Returns the names of the annotation types supported by this
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     * processor.  An element of the result may be the canonical
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     * (fully qualified) name of a supported annotation type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     * Alternately it may be of the form &quot;<tt><i>name</i>.*</tt>&quot;
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     * representing the set of all annotation types with canonical
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     * names beginning with &quot;<tt><i>name.</i></tt>&quot;.  Finally, {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
     * "*"} by itself represents the set of all annotation types,
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     * including the empty set.  Note that a processor should not
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     * claim {@code "*"} unless it is actually processing all files;
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     * claiming unnecessary annotations may cause a performance
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     * slowdown in some environments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     * <p>Each string returned in the set must be accepted by the
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * following grammar:
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     * <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     * <dl>
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     * <dt><i>SupportedAnnotationTypeString:</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     * <dd><i>TypeName</i> <i>DotStar</i><sub><i>opt</i></sub>
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     * <dd><tt>*</tt>
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
     * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     * <dt><i>DotStar:</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
     * <dd><tt>.</tt> <tt>*</tt>
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     * </dl>
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     * </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     *
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
   228
     * where <i>TypeName</i> is as defined in
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
   229
     * <cite>The Java&trade; Language Specification</cite>.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     * @return the names of the annotation types supported by this processor
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     * @see javax.annotation.processing.SupportedAnnotationTypes
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
   233
     * @jls 3.8 Identifiers
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
   234
     * @jls 6.5.5 Meaning of Type Names
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    Set<String> getSupportedAnnotationTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     * Returns the latest source version supported by this annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     * processor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     * @return the latest source version supported by this annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     * processor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     * @see javax.annotation.processing.SupportedSourceVersion
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     * @see ProcessingEnvironment#getSourceVersion
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    SourceVersion getSupportedSourceVersion();
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     * Initializes the processor with the processing environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     * @param processingEnv environment for facilities the tool framework
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     * provides to the processor
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    void init(ProcessingEnvironment processingEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     * Processes a set of annotation types on type elements
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     * originating from the prior round and returns whether or not
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     * these annotations are claimed by this processor.  If {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     * true} is returned, the annotations are claimed and subsequent
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     * processors will not be asked to process them; if {@code false}
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     * is returned, the annotations are unclaimed and subsequent
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     * processors may be asked to process them.  A processor may
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     * always return the same boolean value or may vary the result
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     * based on chosen criteria.
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * <p>The input set will be empty if the processor supports {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     * "*"} and the root elements have no annotations.  A {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     * Processor} must gracefully handle an empty set of annotations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     * @param annotations the annotation types requested to be processed
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     * @param roundEnv  environment for information about the current and prior round
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     * @return whether or not the set of annotations are claimed by this processor
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    boolean process(Set<? extends TypeElement> annotations,
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
                    RoundEnvironment roundEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
   /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    * Returns to the tool infrastructure an iterable of suggested
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
    * completions to an annotation.  Since completions are being asked
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    * for, the information provided about the annotation may be
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
    * incomplete, as if for a source code fragment. A processor may
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    * return an empty iterable.  Annotation processors should focus
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
    * their efforts on providing completions for annotation members
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    * with additional validity constraints known to the processor, for
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
    * example an {@code int} member whose value should lie between 1
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    * and 10 or a string member that should be recognized by a known
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    * grammar, such as a regular expression or a URL.
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
    * <p>Since incomplete programs are being modeled, some of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
    * parameters may only have partial information or may be {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
    * null}.  At least one of {@code element} and {@code userText}
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    * must be non-{@code null}.  If {@code element} is non-{@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    * null}, {@code annotation} and {@code member} may be {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    * null}.  Processors may not throw a {@code NullPointerException}
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    * if some parameters are {@code null}; if a processor has no
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    * completions to offer based on the provided information, an
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
    * empty iterable can be returned.  The processor may also return
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
    * a single completion with an empty value string and a message
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
    * describing why there are no completions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    * <p>Completions are informative and may reflect additional
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
    * validity checks performed by annotation processors.  For
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
    * example, consider the simple annotation:
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
    * <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
    * &#064;MersennePrime {
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    *    int value();
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
    * }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
    * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
    * </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
    * (A Mersenne prime is prime number of the form
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    * 2<sup><i>n</i></sup> - 1.) Given an {@code AnnotationMirror}
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    * for this annotation type, a list of all such primes in the
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    * {@code int} range could be returned without examining any other
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    * arguments to {@code getCompletions}:
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    * <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
    * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    * import static javax.annotation.processing.Completions.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
    * ...
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    * return Arrays.asList({@link Completions#of(String) of}(&quot;3&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
    *                      of(&quot;7&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    *                      of(&quot;31&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
    *                      of(&quot;127&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
    *                      of(&quot;8191&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
    *                      of(&quot;131071&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
    *                      of(&quot;524287&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    *                      of(&quot;2147483647&quot;));
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
    * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    * </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
    * A more informative set of completions would include the number
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    * of each prime:
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
    * <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
    * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
    * return Arrays.asList({@link Completions#of(String, String) of}(&quot;3&quot;,          &quot;M2&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
    *                      of(&quot;7&quot;,          &quot;M3&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
    *                      of(&quot;31&quot;,         &quot;M5&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
    *                      of(&quot;127&quot;,        &quot;M7&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
    *                      of(&quot;8191&quot;,       &quot;M13&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
    *                      of(&quot;131071&quot;,     &quot;M17&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
    *                      of(&quot;524287&quot;,     &quot;M19&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
    *                      of(&quot;2147483647&quot;, &quot;M31&quot;));
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
    * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
    * </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    * However, if the {@code userText} is available, it can be checked
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
    * to see if only a subset of the Mersenne primes are valid.  For
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
    * example, if the user has typed
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
    * <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
    * <code>
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
    * &#064;MersennePrime(1
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
    * </code>
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
    * </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
    * the value of {@code userText} will be {@code "1"}; and only
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
    * two of the primes are possible completions:
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
    * <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
    * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
    * return Arrays.asList(of(&quot;127&quot;,        &quot;M7&quot;),
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
    *                      of(&quot;131071&quot;,     &quot;M17&quot;));
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
    * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
    * </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
    * Sometimes no valid completion is possible.  For example, there
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
    * is no in-range Mersenne prime starting with 9:
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
    * <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
    * <code>
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
    * &#064;MersennePrime(9
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
    * </code>
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
    * </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
    * An appropriate response in this case is to either return an
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
    * empty list of completions,
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
    * <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
    * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
    * return Collections.emptyList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
    * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
    * </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
    * or a single empty completion with a helpful message
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
    * <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
    * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
    * return Arrays.asList(of(&quot;&quot;, &quot;No in-range Mersenne primes start with 9&quot;));
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
    * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
    * </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
    * @param element the element being annotated
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
    * @param annotation the (perhaps partial) annotation being
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    *                   applied to the element
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
    * @param member the annotation member to return possible completions for
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    * @param userText source code text to be completed
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
    *
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
    * @return suggested completions to the annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
    */
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
    Iterable<? extends Completion> getCompletions(Element element,
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
                                                  AnnotationMirror annotation,
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
                                                  ExecutableElement member,
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
                                                  String userText);
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
}