Bug 73669 - [dom] Bridging the Gap between JavaModel and AST
Summary: [dom] Bridging the Gap between JavaModel and AST
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 M7   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-10 10:50 EDT by Dirk Baeumer CLA
Modified: 2005-05-11 10:07 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2004-09-10 10:50:35 EDT
As discussed we need methods to bridge between the Java Model and ASTs.

IJavaElement[] JavaCore#create(IBinding[])

IBinding[] AST.create(IJavaElement[])
ASTNode AST.create(IJavaElement[])
Comment 1 Jerome Lanneluc CLA 2004-09-13 09:41:28 EDT
Dirk, can you please make sure that all assumptions are correct, and answer 
the questions below ?

1. IJavaElement[] JavaCore#create(Binding[])
- all Bindings come from the same compilation unit
- they were built using an ICompilationUnit element (i.e. 
ASTParser#setCompilationUnit(...) was used)

2. IBinding[] AST#create(IJavaElement[])
- all Java elements come from the same compilation unit
- their project's options are used
- the default working copy owner is used
- the API level cannot be specified here. Could we put this API on ASTParser 
instead ? 
- this API should take an IProgressMonitor as well

3. ASTNode[] AST#create(IJavaElement[])
- you meant returning an array of ASTNodes, right ?
- all Java elements come from the same compilation unit
- no resolution is needed
- same as above: this API would make more sense on ASTParser. Do you agree ?
Comment 2 Dirk Baeumer CLA 2004-09-14 05:41:43 EDT
1. IJavaElement[] JavaCore#create(Binding[])

- we have bindings from arbitrary compilation units we want to convert to
  Java elements (an example is the ripple method finder were we have to convert
  the leaf types into bindings).
- currently I think 99% of the ASTs were built from an ICompilationUnit. What
  will happen if the call this method for a binding created from a char array
  given that a corresponding Java element exists.

2. IBinding[] AST#create(IJavaElement[])
- we have Java elements from arbitrary compilation units we want to convert 
  into bindings.
- if we move the API to ASTParser can't we get more control of 
  compiler options and working copy owners ?
- agree on the IProgressMonitor

3. ASTNode[] AST#create(IJavaElement[])
- you meant returning an array of ASTNodes, right ? YES
- I think this can be limited to one compilation unit since creating to many
  ASTs via this method might be a big memory problem.
- what do you mean with no resolution is needed ?
Comment 3 Jerome Lanneluc CLA 2004-09-14 06:24:19 EDT
1. IJavaElement[] JavaCore#create(Binding[])
> we have bindings from arbitrary compilation units we want to convert to
> Java elements (an example is the ripple method finder were we have to convert
> the leaf types into bindings).
OK. I'll make sure that the code doesn't assume that all bindings come from 
the same CU.

> currently I think 99% of the ASTs were built from an ICompilationUnit. What
> will happen if the call this method for a binding created from a char array
> given that a corresponding Java element exists.
If an AST was built using ASTParser.setSource(char[]), we cannot know where 
this source come from, and we cannot create an IJavaElement (we would not know 
the parent IPackageFragmentRoot of this IJavaElement)
So in this case null would be returned.

2. IBinding[] AST#create(IJavaElement[])
> we have Java elements from arbitrary compilation units we want to convert
> into bindings.
OK. I'll make sure that the code doesn't assume that all Java elements come 
from the same CU.

> if we move the API to ASTParser can't we get more control of
> compiler options and working copy owners ?
Yes, you could use ASTParser#setCompilerOptions(...) and setWorkingCopyOwner
(...)

3. ASTNode[] AST#create(IJavaElement[])
> I think this can be limited to one compilation unit since creating to many
> ASTs via this method might be a big memory problem.
OK. I'll keep the assumption that all Java elements come from the same CU.

> what do you mean with no resolution is needed ?
I meant that you're not going to ask for the bindings of the created ASTNodes, 
right ?
Comment 4 Dirk Baeumer CLA 2004-09-14 11:56:33 EDT
>If an AST was built using ASTParser.setSource(char[]), we cannot know where 
>this source come from, and we cannot create an IJavaElement (we would not 
>know the parent IPackageFragmentRoot of this IJavaElement)
>So in this case null would be returned.
Returning null in this case is fine with me. We should spec in the API that if 
the binding was created from a compilation unit the value will not be null.

>> what do you mean with no resolution is needed ?
>I meant that you're not going to ask for the bindings of the created 
>ASTNodes, right ?

We would like to ask for bindings. Can't this be controlled via the flag 
resolve bindings we pass to ASTParser
Comment 5 Jerome Lanneluc CLA 2004-09-15 05:16:22 EDT
> We would like to ask for bindings. Can't this be controlled via the flag 
> resolve bindings we pass to ASTParser
OK, I'll make sure to honnor this flag.
Comment 6 Jerome Lanneluc CLA 2004-09-17 09:06:52 EDT
Dirk, for the first bridge (creating Java elements from bindings), do you mind 
if we move the functionality to IBinding ? It would be something like 
IBinding#getJavaElement() and it would return null if no Java element can be 
created.
Comment 7 Dirk Baeumer CLA 2004-09-17 10:04:26 EDT
Does this have a performance impact if I convert more than one binding into a 
JavaElement? If not then I am fine with only having this method on IBinding.
Comment 8 Jerome Lanneluc CLA 2004-09-17 10:08:15 EDT
No this won't have any performance impact.
Comment 9 Jerome Lanneluc CLA 2004-09-29 10:08:28 EDT
Added IBinding#getJavaElement()
Comment 10 Jerome Lanneluc CLA 2004-09-29 10:09:02 EDT
Tests in ASTModelBridgeTests
Comment 11 Dirk Baeumer CLA 2004-11-18 13:06:42 EST
Dicussed with Philippe and we agree on that for consistency JDT/Core should
offer a method that converts IJavaElements to Bindings. However, JDT/Cores
implementation will be based on the compiler pipeline. To decouple work, JDT/UI
will implement its own helper method using the compiler pipeline which down the
road can be replace with the JDT/Core method.
Comment 12 Dirk Baeumer CLA 2004-12-13 05:59:21 EST
Regarding my last comment: this isn't true since using the AST parser requires
that we have source. However there can be Java model elements for which we need
binding even if we don't have the source for them.

Creating a fake CU which references the element is a workaround but becomes
complicated with methods, generics, ...

Can we consider an API that converts IJavaElements into bindings for M5 ?

Comment 13 Jerome Lanneluc CLA 2005-01-10 12:28:49 EST
Added API ASTParser#createBindings(IJavaElement[],IProgressMonitor) to create
the DOM bindings for the given Java elements.
Corresponding tests are in ASTModelBridgeTests#testCreateBindings*
Comment 14 Jerome Lanneluc CLA 2005-03-08 07:14:32 EST
Dirk, do you still need to create ASTNodes from IJavaElements ?
Comment 15 Dirk Baeumer CLA 2005-03-08 09:49:37 EST
We are using the API on ASTParser know. For me this API is sufficient. What does
the rest of the JDT/UI team think ?
Comment 16 Tobias Widmer CLA 2005-03-08 09:55:49 EST
It seems sufficient for me as well. Ast nodes are only required for ast 
rewrite in which case the API on AstParser can be used.
Comment 17 Martin Aeschlimann CLA 2005-03-08 10:10:24 EST
The step ISourceReference -> AST node is still a bit cumbersome.
We have a class NodeFinder that finds a node by range, but it is internal.
Clients have to copy this class.

I think it would be a good idea to make the NodeFinder API.
Comment 18 Jerome Lanneluc CLA 2005-04-07 09:23:16 EDT
Nothing more planned on this front for 3.1.
Please open sepate feature requests if you need more.
Comment 19 Frederic Fusier CLA 2005-05-11 10:07:20 EDT
Verified for 3.1 M7 using build I20050509-2010 + jdt.core HEAD.