Bug 27134 - Add a ASTNode for non-Javadoc comments
Summary: Add a ASTNode for non-Javadoc comments
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.0 M7   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 23152
Blocks:
  Show dependency tree
 
Reported: 2002-11-25 19:49 EST by roman CLA
Modified: 2004-02-11 09:40 EST (History)
5 users (show)

See Also:


Attachments
First rough implementation for ASTNode comments (227.34 KB, patch)
2003-12-01 07:46 EST, Frederic Fusier CLA
no flags Details | Diff
First implementation for ASTNode comments (233.54 KB, patch)
2003-12-01 14:04 EST, Frederic Fusier CLA
no flags Details | Diff
New version after Jim feedback (220.17 KB, patch)
2003-12-05 09:14 EST, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description roman CLA 2002-11-25 19:49:43 EST
It would be quite helpful to have an ASTNode that represents non-Javadoc
comments (i.e. "/* ... */" and "// ...."

In that way one would be able to parse a .java file into a AST tree, modify
the tree and reconstruct a .java file from that modified AST tree.

If one tries to do that now, one looses the original non-Javadoc comments.
Comment 1 David Vydra CLA 2003-01-26 01:24:39 EST
We have the same need. Can this be fixed in the 2.1 timeframe?
Comment 2 Philipe Mulet CLA 2003-01-29 09:20:51 EST
Unfortunately, there is no consensus yet on what comments should be surfaced as 
(especially what node would they get associated with).

Currently, you have to resort to using our scanning API to rescan portions of 
the source.

Will reconsider post 2.1
Comment 3 Philipe Mulet CLA 2003-10-30 04:40:44 EST
Will consider providing a list of detected comments instead. Then provide a 
heuristic to perform associations with nodes. Javadoc comments would be more 
detailed so as to surface tags.
Comment 4 Alex Kanevsky CLA 2003-10-30 21:54:20 EST
Here is how I suggest to implement Comment ASTNodes.
There are two distinct scenarios under which comments occur,

1. Comment does not unambiguously belong to a particular ASTNode.
Any ASTNode that implements method like
List statements(); is a good candidate.
E.g., in case of comments inside of the Block statement.
In such case, Block.statements(); method shall return CommentStatement object
in the proper place of List.
E.g.,
// java file scope comment
void foo () {
    // method block scope comment
    if (true) {
        // if statement block scope comment
    } else {
        /* else statement block scope comment */
    }
}

2. Comment is clearly associated with a particular node.
E.g., Expression objects of, say, 
List MethodInvocation.arguments(),
or 
List IfStatement.getExpression ()
In such case, Expression's methods
Comment getPreceedingComment();
Comment getTrailingComment();
shall return Comment object, or null if no comment is present.
Generally speaking, if there is an expression element that JLS allows to put a
comment next to,
it should implement two of the above methods.
E.g.,
if (/* Preceding comment */ true /* Trailing comment */) {}
A.foo(/* pre-comment */ 5 /* post comment */, 7, 11 /*post comment*/ );
int a = 5 /* post comment*/;
will fall into this category

Comment object shall be wrapped in an object appropriate for an ASTNode it is
located within whenever
it is necessary.
E.g., as stated above, in case of block statement it shall be wrapped in
CommentStatement;
if a list of expressions is expected by the method returning a comment, it
should be wrapped in CommentExpression, etc.

toString () methods of the nodes shall reflect this change appropriately.
Comment 5 Frederic Fusier CLA 2003-12-01 07:46:03 EST
Created attachment 7016 [details]
First rough implementation for ASTNode comments
Comment 6 Frederic Fusier CLA 2003-12-01 07:49:05 EST
If validated, this implementation could be put in M6...
Comment 7 Frederic Fusier CLA 2003-12-01 14:04:16 EST
Created attachment 7020 [details]
First implementation for ASTNode comments

This version pass all JDTCore tests, but unfortunately does not implements last
design agreed with Martin (removal of JavadocEmbeddedTag)...
This will be done hopefully tomorrow.
Comment 8 Frederic Fusier CLA 2003-12-05 09:14:02 EST
Created attachment 7076 [details]
New version after Jim feedback

Pass all JDT-Core and JDT-UI refactoring tests.
Last design implemented (remove of JavadocEmbeddedTag).
Comment 9 Frederic Fusier CLA 2004-01-13 08:11:37 EST
Implementation will start as soon as Jim will provide final feedbacks on DOM 
AST comments spec which should synthesize our (ie. Jim, Martin, Philippe and I) 
last exchanges...
Comment 10 Frederic Fusier CLA 2004-01-27 08:16:32 EST
Fixed.

Specific class jdt.core.tests.dom.ASTConverterJavadocTest has been created to 
test this new functionality. Currently it only has 2 tests and will be 
completed by the end of the week..

Jim, I've only added a reference to this bug in buildnotes_jdt-core.html file. 
May you add more information either in buildnotes or in this bug you think user 
should have about this new functionality? Thanks
Comment 11 Jim des Rivieres CLA 2004-01-27 13:42:32 EST
The original problem has been partially addressed by recent changes detailed 
in bug 50683 and bug 50697. 

However, API for serializing an AST, including comments, is still an open 
issue. See bug 23152.
Comment 12 David Audel CLA 2004-02-11 09:40:12 EST
Verified for 3.0M7