[JSR308] Implicit annotations with values

Artemus Harper subanark at gmail.com
Sat Jul 5 00:43:22 EDT 2008


My plan is to use the InnerUnique annotation denote what inner elements are
unique. This seems like the best way to handle conditional uniqueness. If
you can think of a better way to describe such conditional properties that
would be helpful.

E.g. for the methods in List:
public void add(@Unique("E") E elm); //conditionally unique on E
@Unique("E") public E get(int index);

For the caller of the methods, if the list is annotated as
InnerUnique({"E"}) then the parameters are unique, otherwise they are not.
I.e.
@InnerUnique({"E"}) List<E> list = new UniqueList<E>(); //ArrayList doesn't
have the uniqueness properties I want

Then the methods in List for the list variable become:
public void add(@Unique E elm);
@Unique public E get(int index);

On the other hand if list is not annotated:
List<E> list = new UniqueList<E>();

then the methods are simply:
public void add(E elm);
public E get(int index);


So what I plan to do is modify the annotations of the Element for the method
based on the context the variable is used in. I am currently doing this in
the checkMethodInvocability method of the Visitor.

Due to the way new works I can infer what annotation new should have.
However, I don't what to have infer all the ways new can be assigned or
used, so I instead want to opt for a wild card style of "not yet determined"
annotation which is assignable in any context. Although
TreeUtils.assignmentContext(parentNode) will get most cases, it won't get
chained method calls.

On Fri, Jul 4, 2008 at 4:18 PM, Mahmood Ali <mahmood at mit.edu> wrote:

> Greetings Artemus,
>
> As of this release, the framework only constructs AnnotationMirrors with no
> values.  Hopefully, the requested feature will be added in the next release
> (next Thursday/Friday).
>
> It is worthy to note that most of the framework classes (e.g.
> GraphQualifierHierarchy, AnnotatoinUtils, AnnotatedTypeMirror), were
> designed for annotations without values.  Specifically, any container
> may hold up to one annotation of a given type regardless of its value.
> (i.e. a type cannot have both annotations @A("1") @A("2")).
>
> Regards,
> Mahmood
>
>
> On Fri, 4 Jul 2008, Artemus Harper wrote:
>
>  What would be the best way to add an implicit annotation to a type, where
>> the implicit annotation has some of its elements defined.
>>
>> My code:
>> @Override
>>   protected void annotateImplicit(Tree tree, AnnotatedTypeMirror type) {
>>   ...
>>   switch(tree.getKind()) {
>>   ...
>>   case NEW_CLASS:
>>   if(type.getAnnotation(InnerUnique.class.getName()) == null) {
>>      //I want to add @InnerUnique({"*"})
>>   ...
>>   }
>> }
>>
>> where InnerUnique is:
>> @TypeQualifier
>> @Retention(RetentionPolicy.RUNTIME)
>> public @interface InnerUnique {
>>  String[] value();
>> }
>>
>> I see that AnnotationUtils has a method to get an AnnotationMirror with no
>> values defined, but I don't see any to actually set the values.
>> My best guess is to simply implement AnnotationMirror my self and return
>> the
>> values I want. Is there a better way to do this?
>>
>> --
>> Artemus Harper
>>
>>


-- 
Artemus Harper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.csail.mit.edu/pipermail/jsr308/attachments/20080704/e9b5cfc4/attachment.htm 


More information about the JSR308 mailing list