[Checkers] [JSR308] Implicit annotations with values

Mahmood Ali mahmood at MIT.EDU
Mon Jul 7 10:26:36 EDT 2008


Greetings Artemus,

I feel your question should really be addressed to the Checkers  
mailing list rather than the JSR 308 mailing list, as it addresses the  
checker framework rather than the JSR 308 proposal itself.

Let me try to state your problem in a different way:

You desire to have a separate mechanism for supplying annotation  
arguments for polymorphic qualifier in orthogonal manner to type  
variables, to eliminate the need to declare artificial type parameters  
to suit qualifier parameters.  Unfortunately, I cannot think of a good  
solution to this problem.

I would try to solve the problem in a different way.  I don't know how  
extensible it is, but hopefully it will work for you.  In the case of  
StringList clients should really be using the interface rather than  
the concrete implementation; and you can supply a static factory  
method that deals with type arguments.

So I would write StringList as follows:

public class StringList<T extends @UniqueQ String> extends List<T> {
     public static <T extends @UniqueQ String> StringList<T>  
newStringList() { return new StringList<T>(); }
     private StringList() { ... }
}

Clients would be:
   List<String> l = StringList.newStringList();
   List<@Unique String> l2 = StringList.newStringList();

Both should type check.  This would work if clients should use the  
type StringList in the definition itself (i.e. in StringList l =  
newStringList() ).

> Also regarding the use of multiple copies of the same annotation,  
> could those be used as an alternative form for a single annotation?
>
> E.g.
> @A("1") @A("2")
> Is the same as:
> @A({"1","2"})
>
I don't know much about your type system to give an opinion.  When we  
were faced with a similar issue we created a new annotation (e.g. @As)  
that takes an array of the desired multiple annotations, so you could  
do:
@As({@A("1"), @A("2")})
[Review checkers/quals/DefaultQualifier and .../DefaultQualifiers]

I don't know if that works with you.

Thank,
Mahmood



More information about the checkers mailing list