|
Préférences
Moteurs de recherche
|
||||||||||||||
| JavaTM 2 Platform Std. Ed. v1.6.0
javax.annotation.processing
|
|||||||||||||||
| Method Summary | |
|---|---|
Iterable<? extends Completion> |
getCompletions(Element element,
AnnotationMirror annotation,
ExecutableElement member,
String userText)
Returns to the tool infrastructure an iterable of suggested completions to an annotation. |
Set<String> |
getSupportedAnnotationTypes()
Returns the names of the annotation types supported by this processor. |
Set<String> |
getSupportedOptions()
Returns the options recognized by this processor. |
SourceVersion |
getSupportedSourceVersion()
Returns the latest source version supported by this annotation processor. |
void |
init(ProcessingEnvironment processingEnv)
Initializes the processor with the processing environment. |
boolean |
process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv)
Processes a set of annotation types on type elements originating from the prior round and returns whether or not these annotations are claimed by this processor. |
| Method Detail |
|---|
Set<String> getSupportedOptions()
getOptions.
Each string returned in the set must be a period separated sequence of identifiers:
- SupportedOptionString:
- Identifiers
- Identifiers:
- Identifier
- Identifier
.Identifiers
- Identifier:
- Syntactic identifier, including keywords and literals
A tool might use this information to determine if any options provided by a user are unrecognized by any processor, in which case it may wish to report a warning.
SupportedOptionsSet<String> getSupportedAnnotationTypes()
"*" by itself represents the set of all annotation types,
including the empty set. Note that a processor should not
claim "*" unless it is actually processing all files;
claiming unnecessary annotations may cause a performance
slowdown in some environments.
Each string returned in the set must be accepted by the following grammar:
where TypeName is as defined in the Java Language Specification.
- SupportedAnnotationTypeString:
- TypeName DotStaropt
- *
- DotStar:
- . *
SupportedAnnotationTypesSourceVersion getSupportedSourceVersion()
SupportedSourceVersion,
ProcessingEnvironment.getSourceVersion()void init(ProcessingEnvironment processingEnv)
processingEnv - environment for facilities the tool framework
provides to the processorboolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
true is returned, the annotations are claimed and subsequent
processors will not be asked to process them; if false
is returned, the annotations are unclaimed and subsequent
processors may be asked to process them. A processor may
always return the same boolean value or may vary the result
based on chosen criteria.
The input set will be empty if the processor supports "*" and the root elements have no annotations. A Processor must gracefully handle an empty set of annotations.
annotations - the annotation types requested to be processedroundEnv - environment for information about the current and prior round
Iterable<? extends Completion> getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText)
int member whose value should lie between 1
and 10 or a string member that should be recognized by a known
grammar, such as a regular expression or a URL.
Since incomplete programs are being modeled, some of the
parameters may only have partial information or may be null. At least one of element and userText
must be non-null. If element is non-null, annotation and member may be null. Processors may not throw a NullPointerException
if some parameters are null; if a processor has no
completions to offer based on the provided information, an
empty iterable can be returned. The processor may also return
a single completion with an empty value string and a message
describing why there are no completions.
Completions are informative and may reflect additional validity checks performed by annotation processors. For example, consider the simple annotation:
@MersennePrime {
int value();
}
(A Mersenne prime is prime number of the form
2n - 1.) Given an AnnotationMirror
for this annotation type, a list of all such primes in the
int range could be returned without examining any other
arguments to getCompletions:
A more informative set of completions would include the number of each prime:import static javax.annotation.processing.Completions.*; ... return Arrays.asList(of("3"), of("7"), of("31"), of("127"), of("8191"), of("131071"), of("524287"), of("2147483647"));
However, if thereturn Arrays.asList(of("3", "M2"), of("7", "M3"), of("31", "M5"), of("127", "M7"), of("8191", "M13"), of("131071", "M17"), of("524287", "M19"), of("2147483647", "M31"));
userText is available, it can be checked
to see if only a subset of the Mersenne primes are valid. For
example, if the user has typed
@MersennePrime(1
the value of userText will be "1"; and only
two of the primes are possible completions:
return Arrays.asList(of("127", "M7"),
of("131071", "M17"));
Sometimes no valid completion is possible. For example, there
is no in-range Mersenne prime starting with 9:
@MersennePrime(9
An appropriate response in this case is to either return an
empty list of completions,
or a single empty completion with a helpful messagereturn Collections.emptyList();
return Arrays.asList(of("", "No in-range Mersenne primes start with 9"));
element - the element being annotatedannotation - the (perhaps partial) annotation being
applied to the elementmember - the annotation member to return possible completions foruserText - source code text to be completed