Community
Participate
Working Groups
We need a way to get back from an AST/ASTNode to the originating ICompilationUnit (if the AST was created for a particular ICompilationUnit). Currently, we just set a property on the CompilationUnit when we parse something with RefactoringASTParser. But this is no longer possible when the AST has been created by ASTParser#createASTs(ASTRequestor, IProgressMonitor) from bug 73675. I don't really care whether the query is added to AST, CompilationUnit, or ASTNode in general. On ASTNode, it could even be IJavaElement getJavaElement() and return the corresponding IJavaElement iff available (CompilationUnit -> ICompilationUnit/IClassFile; MethodDeclaration -> IMethod; ForStatement -> null; ...).
The current API makes the ICompilationUnit available in ASTRequestor#acceptAST(CompilationUnit ast, ICompilationUnit source). I would still favor a query on AST or ASTNode to get back to IJavaElements from an AST. Changing severity to enhancement, since the way back is available now.
This is already work in progress.
Actually no work has started on this API. Markus can you confirm that CompilationUnit#getJavaElement() (that would return an ICompilationUnit) is the only thing that you really need ? And that you currently have a workaround that is to set a property on the CompilationUnit ?
Exactly. As a workaround, we currently parse everything with our RefactoringASTParser, which stores the originating ICompilationUnit in a property of the CompilationUnit node. The getJavaElement() on any ASTNode was just an idea for convenience and is currently not required (however, that functionality should in fact already be available when bindings are resolved: aNode.resolveBinding().getJavaElement()).
Added CompilationUnit#getJavaElement(). Added test ASTConvertTest2#test0573()
Verified in I20050330-0500