[JSR308] Receiver on field initializers

Artemus Harper subanark at gmail.com
Sun May 11 11:56:51 EDT 2008


After doing some more investigation I have found that simply querying the
method in the visitVariable will not cause the crash, but this happened
since I skipped the handler and called this directly from the visitClass
method, where the info is not yet set. I think I didn't realize that the
default visitor sets state as it visits and uses that for processing. So all
that is probably needed is a warning of where it is valid to call the
getReceiver method.

On a side note, would it be possible to have a way to enable type
compatibility when constructors are called, currently it seems that the
constructor is always skipped.

As for the problem with the field annotations, I currently have a temporary
'hack' that collects the constructor annotations, and sees if the one I'm
interested in is in one of those. I also considered simply adding a call to
visitAssignment for all the fields for each constructor in the beginning,
and a new method visitField for the field decelerations. The logic would be
cleaner, but would cause additional processing (and may confuse some
processor such as a duplicate code analyzer).

On Sat, May 10, 2008 at 4:35 PM, Mahmood Ali <mahmood at mit.edu> wrote:

> Greetings,
>
> Thank you very much for your email and observation!
>
>  What exactly is the annotations on the receiver of a field initializer?
> >
>
> Currently, the receiver is the annotated type of the enclosing class.  We
> realize that this may be problematic for some checkers.
>
> It has been proposed that we should have the least restricted type
> (actually least upper bound) of all the constructors, including the
> synthetic constructors.  We have not gotten to it yet, but hopefully it will
> make it into the following stable release.
>
>  Also, when I tried to ask the API for the receiver I got an exception (In
> > my
> > case I'm doing escape analysis):
> >
> > public class EscapeVisitor extends BaseTypeVisitor<Void, Void> {
> >    @Override
> >    public Void visitVariable(VariableTree node, Void p) {
> >        AnnotatedTypeMirror type =
> > factory.getReceiver(node.getInitializer()); //throws exception
> >    }
> >
>
> Thanks for this bug report.  The bug can be fixed simply by returning null
> if enclosingMethod is null in
> AnnotatedTypeFactory.getCurrentMethodReceiver().
>
> However, this particular bug should not occur if your visitor is extending
> BaseTypeVisitor<Void Void>.  Can you please send us (me) a copy of your
> checker to be able to replicate your findings?
>
> Regards,
> Mahmood
>



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


More information about the JSR308 mailing list