Bug 25297 - AST: DCR: Allow subclasses of ASTNode
Summary: AST: DCR: Allow subclasses of ASTNode
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 2.1 M3   Edit
Assignee: Jim des Rivieres CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-24 04:06 EDT by Martin Aeschlimann CLA
Modified: 2002-10-25 05:23 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.