[JSR308] Implicit annotations with values

Mahmood Ali mahmood at MIT.EDU
Sat Jul 5 01:35:43 EDT 2008


Hi Artemus,

> 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.

If I understand you correctly, the framework tries to provide two  
mechanisms to do that:
   - Polymorphism over generics -- interaction between qualified types  
and generics
   - qualifier polymorphism -- having a polymorphic qualifier (see  
manual 2.5).

The first mechanism is enabled by default to all checkers.  A type  
argument in a parameterized type can be an annotated type.  At first  
look it seems to me that this suffices to solve the problem with  
List.add and List.get situations.
I don't know much about the subtyping relations for Unique (i.e. I  
would use three qualifiers: Unique, Aliased, PossiblyUnique - which is  
the root qualifier); so I would give examples of the Interned type  
system:
internedString and nonInternedString have the obvious declaration

> List<@Interned String> internedStrings = createNewList();
> internedStrings.add(internedString);   // valid
> String s1 = internedString.get(0);
> @Interned String s2 = internedString.get(0);
> internedStrings.add(nonInternedString); // invalid

In the other hand:

> List<@Interned String> unInternedStrings = createNewList();
> unInternedStrings.add(internedString);  // valid
> unInternedStrings.add(unInternedStrings);  // valid
> String s1 = internedString.get(0);   // valid
> @Interned String s2 = unInternedStrings.get(0);  // invalid

I assume that this is sufficient for your type system too.

The second mechanism is enabled by the user, through declaring a  
qualifier a polymorphic qualifier.  Please review section 2.5.  The  
basic idea is that you can have a PolyUnique qualifier to support  
polymorphism for non-generic methods.  So you would have a method like:

> @PolyUnique String identity(@PolyUnique String s) { return s; }  //  
> a trivial example
>
> String s1 = identity(uniqueString);  // valid
> @Unique String s2 = identity(aliasedString);  // invalid

I hope that this helpful.

> Although TreeUtils.assignmentContext(parentNode) will get most  
> cases, it won't get chained method calls.
This was partially conscious decision, following Java type inference  
for generic types.  For example:

> List<String> l1 = Collections.emptyList(); // valid
> Iterator<String> iter1 =  
> Collections.<String>emptyList().iterator(); // valid
> Iterator<String> iter2 = Collections.emptyList().iterator();   //  
> invalid

Regards,
Mahmood




More information about the JSR308 mailing list