[Checkers] changes to AnnotatedTypeFactory/Mirror

Matt Papi mpapi at csail.mit.edu
Mon Mar 3 16:42:49 EST 2008

I just checked in some rather large changes to AnnotatedTypeFactory and 
AnnotatedTypeMirror. I apologize for the size of the commit, but I 
didn't want to risk having a broken build for what might have been a 
couple of days.

These changes should be entirely compatible with existing code, with a 
couple exceptions noted below. They have hopefully made things and 
easier to use, understand, and maintain (and less buggy!).

The changes to AnnotatedTypeMirror implement lazy initialization for 
annotated types. Previously, AnnotatedTypeFactory was responsible for 
completing initialization of AnnotatedTypeMirrors (and it sometimes 
didn't do so correctly, causing at least a few debugging headaches).
AnnotatedTypeMirror now has enough information to initialize its 
component type fields (albeit without annotations) on a getter call, so 
that AnnotatedTypeFactory only has to worry about adding annotations to 
types, and not about constructing types. This simplifies 
AnnotatedTypeFactory and (to a lesser extent) other code that uses 
AnnotatedTypeMirror, and should prevent future partial-initialization 
errors from occurring.

The changes to AnnotatedTypeFactory split the functionality of 
getAnnotatedType(Tree) into a few methods -- fromTypeTree, fromClass, 
fromMember, fromExpression. getAnnotatedType(Tree) was doing all of its 
work in one large visitor that was becoming rather unwieldy to maintain, 
and suffered from other problems as well. (For example, an identifier 
can appear in a type or as part an expression, but the visitor only 
handled the latter case. Now, there's a visitIdentifier associated with 
fromTypeTree() and another one associated with fromExpression().)

One thing that definitely requires changing in the checkers is that the 
code in overridden getAnnotatedType({Tree,Element}) methods should be 
refactored into annotateImplicit({Tree,Element}, AnnotatedTypeMirror) 
methods (which are called by all of the from* methods). I have done this 
for the Interned checker, will do it for NonNull shortly, and can do it 
for the other two if you'd like.

Another thing that might be a problem: the implementation of class 
annotation inheritance seems to have caused a couple of problems here 
and there. The Interned checker looks fine, but I know (and I've 
mentioned to Mahmood already) that it causes 2 test failures in the IGJ 

Please let me know if you find any problems with these changes. I've 
tested using test suites, FreePastry, and Daikon to make sure that 
nothing is severely broken. I'll be working on a problem set for the 
next few hours, but aside from that I'll try to fix things as soon as I can.

- Matt

More information about the checkers mailing list