[JSR308] Custom annotations?

Michael Ernst mernst at mpi-sws.mpg.de
Tue Feb 12 15:50:00 EST 2008


> 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.

Yes, this is easy.  The simple checker attached (as VolatilityChecker.java)
does this in our current framework (version 0.4).  To use it, run the
following commands:

  # First, compile the Volatility annotation and the checker.
  javac Volatility.java VolatilityChecker.java
  # The test program compiles without warnings using ordinary javac.
  javac VolatilityTest.java
  # The checker warns of a type mismatch in the annotations.
  javac -typeprocessor VolatilityChecker VolatilityTest.java

Here is a transcript of the output:

  % javac Volatility.java VolatilityChecker.java
  % javac VolatilityTest.java
  % javac -typeprocessor VolatilityChecker VolatilityTest.java
  VolatilityTest.java:5: (assignment.invalid)
          @Volatility double vol = rate;
  1 error

With just a few more lines of code you can add additional functionality:
special checking at certain operations; treating certain expressions as
automatically having the @Volatility annotation; or enabling the
framework's flow-sensitive analysis.  The manual gives some guidance, but
let us know if you get stuck.  You could write another checker for @Rate
via cut-and-paste from the one for @Volatility.  (All this will become
easier in future releases of the framework, but as you see it is pretty
easy even now.)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: VolatilityChecker.java
Type: application/octet-stream
Size: 1158 bytes
Desc: not available
Url : https://lists.csail.mit.edu/pipermail/jsr308/attachments/20080212/de59dbeb/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Volatility.java
Type: application/octet-stream
Size: 69 bytes
Desc: not available
Url : https://lists.csail.mit.edu/pipermail/jsr308/attachments/20080212/de59dbeb/attachment-0001.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VolatilityTest.java
Type: application/octet-stream
Size: 143 bytes
Desc: not available
Url : https://lists.csail.mit.edu/pipermail/jsr308/attachments/20080212/de59dbeb/attachment-0002.obj 

More information about the JSR308 mailing list