I've created an Annotation
/**
* Highlights this method is declared in XML
*/
public @interface FromXML {
}
I'm using this on methods that look like this:
@FromXML
public void onSomethingClick(View v){
}
The v
variable is needed by the Android reflection system to call this method.
However the input var v
is unused, so my IDE warns me of this. I like this warning and want it on for the rest of my code.
To hide the warning I could do
@SuppressWarnings("unused")
@FromXML
public void onSomethingClick(View v){
}
or I could add a param tag
But I would rather that the IDE (eclipse) reads my @FromXML
annotation and doesn't give me the warning.
I know you can't extend an Annotation, but thats basically what I want to do.
Is there a way I can add my annotation to be recognised as a 'suppress warnings' annotation.
or
Is there a way to code my annotation to 'act like' suppress warnings?
Ok I can't do this in any easy way or form.
Looking at the annotation package http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/annotation/package-summary.html
I can't extend an annotation: Why is not possible to extend annotations in Java?
I can't implement another annotation java.lang.Override
I can't mimic / mock / pretend to be @Override
If I add @Override
to my @FromXML
it is NOT inherited down the chain.
The only way would be to create an Eclipse plugin that recognises my annotation and stops the warning. Shame because I can't find an easy way to do this.
I also went down the route of creating an interface for my @FromXML
entry points, this was very nice and communicated my Activity
was of a type and therefore I didn't need the annotation anymore, perhaps this design change is the answer.