[Checkers] InternalUtils.constructor
Artemus Harper
subanark at gmail.com
Tue Sep 9 01:08:10 EDT 2008
I am unsure why this method does not return the generated constructor for
anonymous classes (and instead returns the constructor of the superclass).
As the result is different from simply the declared type.
E.g.
new Object()
{
public void method() { }
}.method();
is valid code.
For my work this is causing problems since I'm annotating the new part to
refer to the annotations on the super type of the anonymous class rather
than the annotations on the result of invoking the constructor, which do
affect the result of new.
For now I have hacked around the issue by having constructorFromUse() return
the anoymous constructor, but to do this I had to reference JCTree class
directly.
Example from my work:
@Role("T")
public class MyList
{
...
@Unique("{T->E}") public Iterator<T> iterator()
{
return new @Role("{T->E}") Iterator<T>()
{
...
};
}
This anonymous inner class is equivalent to:
@Role("T") public class MyListIterator<T> implements @Role("T->E")
Iterator<T>
{
...
}
'The T->E means to map Iterator's type param E to T.
@Role is similar to generics, except that it allows universally assignable
types (e.g. List<null> is assignable to any List<? extends T> for any T and
contains only null values; Collections.emptyList() would be this), and it
can be used independent of generics. For my purposes Object will have roles
that determine if toString(), equals(), and hashCode() do not leak their
reference. If I have time I will have annotations on type parameters be
aliases to annoting on the type.
I know this might be an abuse of the annotations on new, but the
doumentation was vague to the possible use of having an annotation in that
location. I don't really see the purpose of annotating new for the result of
the value, since this can be inferred in all cases I can think of, except
for anoymous inner classes whoes method's operations depend on the
annotation, which would mostly be the same as if the annotation were on the
class decleration.
--
Artemus Harper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.csail.mit.edu/mailman/private/checkers/attachments/20080908/f7fedb4f/attachment.htm
More information about the checkers
mailing list