Community
Participate
Working Groups
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; } }
Comments are not visited. The only comments that are visited are the javadoc comment attached to a declaration. Closing as INVALID.
Should the javadoc be updated for ASTVisitor.visit(LineComment) saying that it won't be called?
Reopen to update javadoc.
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>
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.
Ok, done. Spec has been clarified. Fixed and released in HEAD.
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.
Verified in I20050215-2300