[JSR308] Creating new annotated types.

Niko Matsakis niko at alum.mit.edu
Wed Nov 12 05:19:06 EST 2008


Hello,

I am having some trouble finding the best way to introduce a  
particular feature into my checker.  I would like to have a special  
static method that is recognized by my type checker (essentially  
emulating a keyword).  This method is called "free()" and is declared  
as a static method.  When this method is invoked, the  
AnnotatedTypeFactory needs to make special changes to the type.

Unfortunately, I find it very hard to manipulate  
AnnotatedTypeMirrors.  It's relatively easy to add or remove  
annotations, but to make other sorts of changes seems to be next to  
impossible.  Most of the required methods are either only available  
within the package or simply not available.  In my case, the method is  
declared as:

	public static <X> X free(X ptr) { return ptr; }

What I want to do is to change the annotations on the return type.   
Because the return type and the argument type are linked, however, any  
changes I make there are also reflected on the parameter type, which  
is no good.  Ideally, what I'd like to do is simply to create a brand  
new executable type with the required values, but I can't do that  
without modifying the framework.  The constructor, after all, is  
package protected, as is setReturnType().

I like the idea of immutable AnnotatedTypeMirrors, so rather than make  
the mutators public, I am currently adding a deep cloning visitor to  
the framework that should solve my problem.  It does a deep clone of a  
type with appropriate overloadable methods at each point.  However, I  
thought I'd fire off an e-mail in case I'm missing some obvious way of  
doing things.


Niko



More information about the JSR308 mailing list