Bug 75702 - [dom] Need a way to get back from an AST to the originating ICompilationUnit
Summary: [dom] Need a way to get back from an AST to the originating ICompilationUnit
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-06 07:08 EDT by Markus Keller CLA
Modified: 2005-03-31 04:34 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 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