Bug 84528 - Not visiting line comments in compilation unit?
Summary: Not visiting line comments in compilation unit?
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-06 12:36 EST by DJ Houghton CLA
Modified: 2005-02-16 13:08 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description DJ Houghton CLA 2005-02-06 12:36:14 EST
build i0202

This is just as likely to be a user error since I am a beginner as AST traversal
but here goes....


I have created an ASTVisitor on a compilation unit. I have implemented the
#visit(MethodInvocation) and it works great. I want to also visit line comments
(specifically //$NON-NLS comments) so I implemented #visit(LineComment).
Unfortuanatly my code never gets run. 

When clicking on the compilation unit in the variables view in the debugger, I
see that my comments are not there. I'm not sure what I'm doing wrong. 

I would expect the LineComment nodes to be in the AST for the compilation unit
but that's not what I'm seeing.

Here is compilation unit.toString() from Variables view. In the original source
code, there is a //$NON-NLS comment on each line with a string literal on it.

---------------

package aaa.actions;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.jface.dialogs.MessageDialog;
public class SampleAction implements IWorkbenchWindowActionDelegate {
  private IWorkbenchWindow window;
  String myVar=Messages.getString("SampleAction.0");
  public SampleAction(){
  }
  public void foo(){
    String text=myVar;
    text=Messages.getString("SampleAction.1");
    text=Messages.getString("SampleAction.2") + new Object();
    text=Messages.getString("SampleAction.3") + new
Object()+Messages.getString("SampleAction.4");
    text=new Object().toString();
  }
  public void run(  IAction action){
   
MessageDialog.openInformation(window.getShell(),Messages.getString("SampleAction.5"),Messages.getString("SampleAction.6")
+ new Object());
  }
  public void selectionChanged(  IAction action,  ISelection selection){
  }
  public void dispose(){
  }
  public void init(  IWorkbenchWindow window){
    this.window=window;
  }
}
Comment 1 Olivier Thomann CLA 2005-02-07 16:23:33 EST
Comments are not visited.
The only comments that are visited are the javadoc comment attached to a
declaration.
Closing as INVALID.
Comment 2 DJ Houghton CLA 2005-02-07 16:35:28 EST
Should the javadoc be updated for ASTVisitor.visit(LineComment) saying that it
won't be called?
Comment 3 Olivier Thomann CLA 2005-02-07 16:37:21 EST
Reopen to update javadoc.
Comment 4 Olivier Thomann CLA 2005-02-08 10:48:40 EST
Would this clarify the specs?
<p>Note that {@link #visit(LineComment) ASTVisitor.visit(LineComment)} and
 * {@link #visit(BlockComment) ASTVisitor.visit(BlockComment)} are never traversed. 
 * The user needs to use the {@link
org.eclipse.jdt.core.dom.CompilationUnit#getCommentList()
CompilationUnit.getCommentList()}
 * to traverse all the comments in the compilation unit.
 * </p>
Comment 5 DJ Houghton CLA 2005-02-08 11:33:17 EST
That would be good on the class comment. And it would be useful to have on the
methods themselves:

Note: this method is old API and is never called

or something to that effect. That way it would show up in the hover when client
do code assist, etc.
Comment 6 Olivier Thomann CLA 2005-02-08 11:39:59 EST
Ok, done.
Spec has been clarified.
Fixed and released in HEAD.
Comment 7 Jim des Rivieres CLA 2005-02-08 18:48:53 EST
Hey. This is *not* old API. And the methods certainly can be called (although 
just not part of a normal AST traversal).

I've change the spec's to clarify that situation. And the corresponding 
methods on ASTMatcher as well.
Comment 8 David Audel CLA 2005-02-16 13:08:02 EST
Verified in I20050215-2300