No subject


Tue Jun 24 21:06:34 EDT 2008


annotation, then adding and getting elements are done as if they were not
unique, while if the caller declared the elements as being Unique, then
elements it gets or puts are unconditionally unique (@Unique()).

This transformation cannot be done with the current API, as there is no
implicit annotation on the method. I normally add or remove these
annotations in the methodFromUse method in the AnnotatedTypeFactory.

The reason I choose not to directly annotate the type parameters (and
instead use InnerUnique) is that this would unnecessarly require that some
classes have a generic parameter for items that did not need to have type
parameters for. I want to allow micro properties in a container to be
annotateable. E.g. a JList has a model, a cell editor, a selection model, a
ui, which are all simple properties which can be annotated, but it would be
unwieldly to use generics to add them all in, while with simple inner
properties a user can obmit any of them for their default annotation values.

Some of the requirements I would like to keep for this project:
1. Reusability of code that will work for both annotated and unannotated
code.
2. User does not need to be aware of the annotations except in situations
that demand it.
 -- For API utility classes, the classes can support uniqueness, but all the
methods are freely useable for non-unqiue instances.

On Mon, Aug 4, 2008 at 8:06 PM, Mahmood Ali <mahmood at mit.edu> wrote:

> Hi Artemus,
>
>  As it currently stands the code [...] determine[s] if the generic type
>> parameter of the iterable matches the element. This may be fine in some
>> cases, but it assumes that annotations are copied from the parameter type to
>> the returned value.
>>
>> 2. Instead of using the type of the Iterable type parameter, use the
>> return type of iterator().next() to emulate what is actually happening in
>> the loop.
>>
>
> Can you please provide a use case for this proposal?
>
> Personally, I think that it's essential that the return type of
> Iterator.next() is the same as the type variable of Iterator.  I think that
> this is important to maintain the subtype relations with Iterator<E>.
>
> Thanks,
>
> Mahmood
>
>


-- 
Artemus Harper

------=_Part_45778_32701882.1217907852043
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

<div dir="ltr">Short description:<br>1. My annotations are morphed based on use<br>2. I don&#39;t annotate the type parameters directly.<br><br>Long description:<br>In my case, annotations may look differently from the caller than how they are declared and used by the callee.<br>
<br>In my test case I have:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Create a list of unique elements<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @InnerUnique({&quot;T&quot;}) UniqueList&lt;String&gt; list = new UniqueList&lt;String&gt;();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Unique String s1 = new String(&quot;s1&quot;); //cannot get references to string literals<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add( (@Unique String) s1); //give up control of the reference to the list<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(new String(&quot;s2&quot;)); //no cast needed here<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @InnerUnique({&quot;T&quot;}) UniqueList&lt;String&gt; list2 = new UniqueList&lt;String&gt;();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @InnerUnique({&quot;T&quot;}) Iterable&lt;String&gt; iterator = list.drainToItr();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(@Unique String s : iterator) //get an iterator that removes elements from the list<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list2.add((@Unique String) s); //add the unique reference to another list<br>
<br><br>The UniqueList.add method looks like (where items is an <font class="FrameItemFont">AtomicReferenceArray)</font><br>public void add(@Unique({&quot;T&quot;}) T item) @NoEscape <br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ensureCapasity(size + 1);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //We need to cast here to give ownership to the array. After this statement<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //item is no longer referencable in the normal manner.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; items.set(size++, (@Unique({&quot;T&quot;}) T) item);<br>}<br>
<br>What @Unique({&quot;T&quot;}) means is that item is unique if this UniqueList instance is declared as InnerUnique({&quot;T&quot;}). The callee doesn&#39;t know if its elements are unique, only the caller knows.<br><br>


More information about the JSR308 mailing list