Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » In an AST Visitor, how can I know which node's property I am visiting?(Is it possible to differentiate?)
In an AST Visitor, how can I know which node's property I am visiting? [message #644465] Sat, 11 December 2010 18:01 Go to next message
Joan Robert is currently offline Joan RobertFriend
Messages: 16
Registered: December 2010
Junior Member
Hi, I'm programming an AST Visitor.

An EnumDeclaration node contains the following structural properties:

JAVADOC, MODIFIERS, NAME, SUPER_INTERFACE_TYPES, ENUM_CONSTANTS and BODY_DECLARATIONS.

When I visit a child node of EnumDeclaration (a SimpleName node, for instance), is it possible to know which of the lists of nodes I'm visiting? Is it possible to differentiate?

I'd like to process a node differently, depending on whether I found it in ENUM_CONSTANTS or BODY_DECLARATIONS.

Thanks for the help.

[Updated on: Sun, 12 December 2010 10:36]

Report message to a moderator

Re: In an AST Visitor, how can I know which node's property I am visiting? [message #644498 is a reply to message #644465] Sun, 12 December 2010 10:35 Go to previous messageGo to next message
Joan Robert is currently offline Joan RobertFriend
Messages: 16
Registered: December 2010
Junior Member
Using the accept method it is possible to do this.

List<Node> as = node.<getPropertyX>();
for( Node a: as)
    a.accept( this);
Re: In an AST Visitor, how can I know which node's property I am visiting? [message #644568 is a reply to message #644465] Mon, 13 December 2010 10:10 Go to previous messageGo to next message
Markus KellerFriend
Messages: 294
Registered: July 2009
Senior Member
On 2010-12-11 19:01, Joan Robert wrote:
> When I visit a child node of EnumDeclaration (a SimpleName node, for
> instance), is it possible to know which of the lists of nodes I'm
> visiting? Is it possible to differenciate?

Use "node.getLocationInParent() == EnumDeclaration.NAME_PROPERTY" or
other *_PROPERTY constants.

Markus
Re: In an AST Visitor, how can I know which node's property I am visiting? [message #644571 is a reply to message #644568] Mon, 13 December 2010 10:25 Go to previous message
Arlindo is currently offline ArlindoFriend
Messages: 33
Registered: August 2009
Member
That's a good alternative way, Markus.

[Updated on: Wed, 15 December 2010 15:56]

Report message to a moderator

Previous Topic:Java extension and java.g file grammar
Next Topic:My "Import existing project" disappeared
Goto Forum:
  


Current Time: Fri Apr 26 18:39:28 GMT 2024

Powered by FUDForum. Page generated in 0.03068 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top