Menu

To get at anonymous classes

Developers
widheg
2009-12-11
2012-10-08
  • widheg

    widheg - 2009-12-11

    Hi all!
    I need to ask what the correct approach is to analyze an anonymous class? In
    my Visitor (that extends SourceVisitor), I noticed that the result from
    x.getTypeDeclarationCount() (where x is of type TypeDeclaration) does not
    reflect any anomyous class whereas the result from x.getTypeDeclarationCount()
    (where x is of type New) does.

    So in visitNew() I test if x.getTypeDeclarationCount() is > 0 and if so I
    conclude that 'new' preceeds an anonymous class. In contrast, if
    x.getTypeDeclarationCount() is == 0, I conclude that 'new' preceeds a
    reference to a constructor. Is this approach correct or is there any better
    way?

    Thanks for any hints and comments!

     
  • Tobias Gutzmann

    Tobias Gutzmann - 2009-12-14

    Hej,

    this approach works. Alternatively, anonymous classes do not have names, i.e.,
    getName() returns null for ClassDeclarations that depict anonymous classes.

    Regards,
    Tobias

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.