[JSR308] AnnotatedTypeFactory.getSelfType

Artemus Harper subanark at gmail.com
Sat Aug 9 16:35:41 EDT 2008


If I understand this correctly there will be a hook to annotate the "self
type" of enclosing classes?

E.g.
public class Foo
{
   public void method()
   {
      Object o = new Object() {
           public void method2()
           {
              method3(); //line A
              method4(); //line B
              Foo.this.method4(); //line C
           }
           public void method3() { }
       };
   }
   public void method4() { }
}

Will I be able to annotate the receiver on line A differently from the
receiver on line B or line C?

Or will there just be a way to annotate the invisible outer class instance
that each non-static inner class has?

Here is a piece of my test code that I am property trying to check:

    //Returns an Iterable that can be used in a foreach loop, as each
element is given
    //in the loop it is removed from the array (in reverse order). The
receiver for this
    //is not NoEscape since the return value indirectly references this
instance.
    @InnerUnique({"T->T"})
    public Iterable<T> drainToItr()
    {
        return new @InnerUnique({"T->T"}) Iterable<T>()
        {
            @InnerUnique({"T->E"})
            public Iterator<T> iterator() @InnerUnique({"?T"})
            {
                return new @InnerUnique({"T<-E"}) Iterator<T>()
                {
                    @Override
                    @Unique({"T"})
                    public T next()
                    {
                        return removeLast();
                    }

                    @Override
                    public boolean hasNext()
                    {
                        return size() > 0;
                    }

                    @Override
                    public void remove()
                    {
                        //Each element is removed even when remove() is not
called.
                    }
                };
            }
        };
    }

In this case the removeLast() method refers to a method 2 levels up.
On Sat, Aug 9, 2008 at 1:04 PM, Mahmood Ali <mahmood at mit.edu> wrote:

> Hi Artemus,
>
> Thank you for reporting the bug.  The framework doesn't anything clever
> with enclosed types yet, but should.
>
> I think that the proper solution would be to have getReceiver use another
> method that handles trees like EnclosingClass.this.foo.
>
> I will add it to my TODO list and it should be fixed hopefully soon.
>
> Regards,
> Mahmood
>
>
> On Aug 7, 2008, at 9:54 PM, Artemus Harper wrote:
>
>  Is this method (when it gets fixed) going to be responsible for
>> determining which self type an expression refers to in the case of inner
>> classes referring to outer class methods or fields?
>>
>> getReceiver depends on this method and its not giving me the correct
>> results for inner classes, and I am planning to hack getSelfType to
>> determine the correct receiver to return. I want to know if this will cause
>> incompadibilities with future code.
>> --
>> Artemus Harper
>> _______________________________________________
>> JSR308 mailing list
>> JSR308 at lists.csail.mit.edu
>> https://lists.csail.mit.edu/mailman/listinfo/jsr308
>>
>
>


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


More information about the JSR308 mailing list