Bug 25297

Summary: AST: DCR: Allow subclasses of ASTNode
Product: [Eclipse Project] JDT Reporter: Martin Aeschlimann <martinae>
Component: CoreAssignee: Jim des Rivieres <jeem>
Status: RESOLVED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: dirk_baeumer, Olivier_Thomann
Version: 2.1   
Target Milestone: 2.1 M3   
Hardware: All   
OS: All   
Whiteboard:

Description Martin Aeschlimann CLA 2002-10-24 04:06:53 EDT
20021022

It is currently not possible to subclass ASTNode as several abstract methods 
are declared package private.
Are there strong reasons to prevent subclassing? We would like to add 
artificial elements to the AST tree.
Comment 1 Olivier Thomann CLA 2002-10-24 07:43:07 EDT
Jim - any comment?
Comment 2 Jim des Rivieres CLA 2002-10-24 09:15:56 EDT
The AST API was intentionally designed around a closed set of AST node types
that represent programs written in the Java language.

Please say more about what you are trying to achieve by adding "artificial 
elements to the AST tree".

Comment 3 Martin Aeschlimann CLA 2002-10-24 09:45:19 EDT
This is one idea:
I would like to have a node that can stand for a arbitrary string of code. In 
the context of rewriting, I would extend our visitors (flattener, rewriter) to 
also handle the new node.

MyNewNode.accept(visitor):
if (visitor instanceof MyExtendedVisitor) {
 ((MyExtendedVisitor)visitor).accept(this)
}

Another idea is that I could introduce a artifical container node that groups a 
sequence of statements. 
Comment 4 Jim des Rivieres CLA 2002-10-24 10:01:32 EDT
For an artificial container that groups a sequence of statements, you could 
use a Block node and mark it as special using get/setProperty. Similarly, an 
arbitrary string of code could be carried in a property on any type of ASTNode.
More generally, you can use a property to carry other ASTNodes.



Comment 5 Olivier Thomann CLA 2002-10-24 14:21:30 EDT
Is this good enough?
Ok to close?
Comment 6 Philipe Mulet CLA 2002-10-24 18:15:17 EDT
Why would you need to attach these directly as nodes ? AST nodes are 
representing all known legal Java constructs.

Your specific ones rather seem related to outputting source. You could remember 
your specific objects through a map keyed by ASTs, and do whatever you want 
with them.

Comment 7 Martin Aeschlimann CLA 2002-10-25 03:44:35 EDT
It's not that I can't solve the given examples (its all working in ASTRewrite 
with properties and maps, as you suggested), but I feel that being able to 
define your own AST nodes would make the infrastucture even more powerful.

To make changes in place looks more convenient to me, especially in combination 
with an extended visitor. 
I wrote the bug report to find out if the closed world assumtion is essential 
in the AST code, or if it was just a design decision that that could be 
loosened. If it could be, I would vote to give the freedom to the AST-client.

ok to close.
Comment 8 Philipe Mulet CLA 2002-10-25 05:23:22 EDT
I believe the DOM should not be extensible, so that other clients can 
manipulate it as well in a predictable way.

Think of AST evaluation for instance, would they recognize your specific 
nodes ? 

Closing.