Bug 75702

Summary: [dom] Need a way to get back from an AST to the originating ICompilationUnit
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: jerome_lanneluc
Version: 3.0   
Target Milestone: 3.1 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Markus Keller CLA 2004-10-06 07:08:07 EDT
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;
...).
Comment 1 Markus Keller CLA 2004-11-01 04:58:29 EST
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.
Comment 2 Philipe Mulet CLA 2004-11-09 12:33:41 EST
This is already work in progress.
Comment 3 Jerome Lanneluc CLA 2004-11-24 07:46:32 EST
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 ?
Comment 4 Markus Keller CLA 2004-11-24 08:33:29 EST
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()).
Comment 5 Jerome Lanneluc CLA 2005-02-24 12:11:22 EST
Added CompilationUnit#getJavaElement().
Added test ASTConvertTest2#test0573()
Comment 6 David Audel CLA 2005-03-31 04:34:48 EST
Verified in I20050330-0500