[JSR308] Custom annotations?

Richard Gomes rgomes1997 at yahoo.co.uk
Sun Feb 10 16:40:08 EST 2008

Hi Mike,

Thank you for your directions.

It should be very convenient to detect that ...

@Rate double rate = 1.0;
@Volatility double vol = rate;

.... cannot compile because the variables are semantically different, 
nevertheless both are represented internally as floating point numbers.

I was thinking to create an annotation intended to mark another annotations as 

public @interface Typecast {
	// Marks other annotations as 'typecasts'

It implies to say that the second annotation is simply a tagging interface. 
For instance:

@Target({ ElementType.FIELD,
                 ElementType.PARAMETER })
public @interface Rate {
	// No methods - Tagging annotation

Once @Rate, @Volatility, etc are defined as @Typecast, an annotation processor 
would include all these annotations in its processing task, in a similar way 
that there's an annotation processor which recognizes the specific annotation 
@NonNull, for instance.

Do you know if there's something similar already being done by someone else?
(In fact, I have only the idea... no single line of code on it.)

What do you think about this idea? 

Thank you again and kind Regards,

Richard Gomes

On Thursday 07 February 2008 13:14:17 Michael Ernst wrote:
> Richard-
> > I was able to get JSR-308 annotation checkers working fine.
> Great!  I'm glad to hear that.
> > My question is: how can I turn on type checkings relative to the
> > annotations @Rate and @Volatility I've defined?
> Please see Section 8, titled "How to write a checker plugin", of the "JSR
> 308 Type-checkers and Framework" document, which is linked from the JSR 308
> webpage (http://groups.csail.mit.edu/pag/jsr308/).
> Here are direct links (but they're subject to change, so if at some point
> they do not work, just follow the links from the main JSR 308 page).
> The "JSR 308 Type-checkers and Framework" document is
>   http://groups.csail.mit.edu/pag/jsr308/dist/manual.pdf
>   http://groups.csail.mit.edu/pag/jsr308/dist/manual.html
> Here's a direct link to Section 8, "How to write a checker plugin":
>   http://groups.csail.mit.edu/pag/jsr308/dist/manual.html#writing-a-checker
> You'll also find the distributed checkers helpful as examples (especially
> the simple ones like Interned).
> If you still have questions after examining these, please ask again, and
> we'll do our best to help.
> >     public static void main(String[] args) {
> >         Main test = new Main();
> >         test.allTests(); // Why I've got (defer.invalid) here??? <<<<
> > ===== }
> The checker outputs "deref.invalid", not "defer.invalid".
> "deref.invalid" is short for "dereference.invalid", meaning that this
> dereference (namely, invoking a method on the "test" variable) might throw
> an exception at run time.
> The reason for this is that the type of the "test" variable is "@Nullable
> Main", meaning that it might be null.  You can change the declaration to
> "@NonNull Main" to eliminate the checker warning.
> You don't always have to write "@NonNull" for local variables that are
> never null.  The checker deduces some such facts for you, and it should do
> so in your example.  I've added it to our test suite so it will be
> corrected in a future release.
>                     -Mike

More information about the JSR308 mailing list