Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32285 > unrolled thread
| Started by | Steven Simpson <ss@domain.invalid> |
|---|---|
| First post | 2015-08-08 18:48 +0100 |
| Last post | 2015-08-31 12:34 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
'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
| From | Steven Simpson <ss@domain.invalid> |
|---|---|
| Date | 2015-08-08 18:48 +0100 |
| Subject | 'Unrecognized' annotation processor options |
| Message-ID | <01sh9c-h3f.ln1@s.simpson148.btinternet.com> |
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
[toc] | [next] | [standalone]
| From | Steven Simpson <ss@my.domain.invalid> |
|---|---|
| Date | 2015-08-31 12:34 +0100 |
| Message-ID | <tnqdbc-9ho.ln1@s.simpson148.btinternet.com> |
| In reply to | #32285 |
On 08/08/15 18:48, Steven Simpson wrote: > 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]' No comments on why it should be this way? I will take it as a bug, then. -- ss at comp dot lancs dot ac dot uk
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web