Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32285
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Steven Simpson <ss@domain.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | 'Unrecognized' annotation processor options |
| Date | Sat, 08 Aug 2015 18:48:48 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 114 |
| Message-ID | <01sh9c-h3f.ln1@s.simpson148.btinternet.com> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Info | mx02.eternal-september.org; posting-host="b3b3ac612f0d10056e7085ac7bc4e2a6"; logging-data="8121"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18erVD8zGNccHfe8NYON5wqU5STnlkyzX0=" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 |
| Cancel-Lock | sha1:dD+HK9KuNa32RaVq2OZDn/FNc/M= |
| Xref | csiph.com comp.lang.java.programmer:32285 |
Show key headers only | View raw
Greetings!
I have an annotation processor which recognizes one annotation and one
-A option. If the recognized annotation is never encountered, I get a
warning:
> warning: The following options were not recognized by any processor:
> '[proc]'
SSCCE:
/* Example.java */
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface Example { }
/* Proc.java */
import java.util.Collections;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
public class Proc extends AbstractProcessor {
private static final String OPTION_NAME = "proc";
private ProcessingEnvironment env;
@Override
public Set<String> getSupportedOptions() {
System.err.println("Returning options");
return Collections.singleton(OPTION_NAME);
}
@Override
public Set<String> getSupportedAnnotationTypes() {
return Collections.singleton(Example.class.getName());
}
@Override
public SourceVersion getSupportedSourceVersion() {
return env.getSourceVersion();
}
@Override
public void init(ProcessingEnvironment processingEnv) {
System.err.println("Initializing");
env = processingEnv;
env.getOptions().get(OPTION_NAME);
}
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
System.err.println("Round");
if (roundEnv.processingOver()) {
env.getOptions().get(OPTION_NAME);
}
return false;
}
}
/* Test1.java */
public class Test1 { }
/* Test2.java */
@Example
public class Test2 { }
$ mkdir -p apt classes
$ javac -d apt Proc.java
$ javac -d classes/ -cp apt/ -Aproc=foo -processor Proc Test1.java
Initializing
Returning options
warning: The following options were not recognized by any processor: '[proc]'
$ javac -d classes/ -cp apt/ -Aproc=foo -processor Proc Test2.java
Initializing
Returning options
Round
Round
$ javac -version
javac 1.8.0_45
It seems that if process(..) is not invoked, the processor's options
will be deemed unrecognized, even though the compiler always finds out
what's recognized regardless.
What's the utility of this definition of 'unrecognized'? If you wanted
to report that a processor was unused, you could detect it more
directly. If you wanted to report misspelled option names, or options
directed at absent processors, this isn't the correct logic. Perhaps
I'm missing the intent of getSupportedOptions, and/or misusing it...?
Cheers!
--
ss at comp dot lancs dot ac dot uk
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
'Unrecognized' annotation processor options Steven Simpson <ss@domain.invalid> - 2015-08-08 18:48 +0100 Re: 'Unrecognized' annotation processor options Steven Simpson <ss@my.domain.invalid> - 2015-08-31 12:34 +0100
csiph-web