[JSR308] Annotations carried over to supertypes.
Niko Matsakis
niko at alum.mit.edu
Thu Sep 25 07:37:27 EDT 2008
Hello,
I am working on building a bridge between JSR-308 to an existing type
checker I have written in O'Caml. Right now it doesn't utilize very
much of the checkers framework. Instead, it serializes the AST into
an internal format and passes it to the existing executable. This is
partly because the tool already existed and partly because my own uses
for annotations are slightly different than what the checkers
framework expects. In any case, I've run into an obstacle.
I need to print out the interface to classes that are referenced by
the class being compiled. This basically takes the form of an
abstract class definition, so it contains the super type (for example)
and names of any methods along with their parameter types etc.
I am attempting to print out this information based on the Element
interface, since I have instances of that interface for all the
classes that are referenced, but not necessarily instances of the Tree
interface (it seems). Unfortunately, some of the assumptions of the
checkers framework aren't quite what I had in mind.
I have a class definition which looks like:
> @P @Q class Foo extends @P Object {}
If I have a TypeElement for class Foo and I ask for its direct super
types:
> atypeFactory.fromElement(typeElement).directSuperTypes()
I get back "@P @Q Object". What I wanted was "@P Object": in other
words, what the user explicitly wrote. Instead, the atypeFactory
copies over all annotations from the original type.
Now, I recognize that the current system makes sense for most
annotations, but it doesn't in mine, where annotations act more like
generic parameters. In other words, it's as if:
> class Foo<X,Y> extends Object<X>
yielded Object<X,Y> as the supertype of Foo<X,Y>.
I also see that there is a hook in the AnnotatedTypeFactory that would
allow me to customize the result which is returned
(postDirectSuperTypes()). I would happily implement it, except that I
can't figure out a way -- using only the Element interface and not the
Tree interface -- to get access to that original declaration of "@P
Object". Presumably the annotations present on that type reference
are preserved somewhere, but I'm not sure where.
Any help on how to get access to the annotations on the original
supertype declaration would be mightily appreciated!
Also, I want to add my congratulations to the checkers team: the
framework seems to be well-designed: extensible, but while still
preserving the ability to write readable code. I hope to be able to
provide more substantive feedback when I've gained more experience
with it.
Niko
More information about the JSR308
mailing list