Home » Language IDEs » Java Development Tools (JDT) » Does Eclipse hold ASTs for each compilation unit in the workspace?
Does Eclipse hold ASTs for each compilation unit in the workspace? [message #226073] |
Mon, 20 March 2006 02:10 |
Eclipse User |
|
|
|
Originally posted by: rorycosgrove.gmail.com
Hi all,
I asked this question before but I am afraid I was a bit vague and may
have been in the wrong thread, so here goes....
Can anybody tell me, does Eclipse hold an abstract syntax tree for each
compilation unit in the workspace? If so, is it possible to access
Eclipse's AST collection?
I had been looking at the Eclipse AST generation classes and can create
an AST with the following:
ASTParser lParser = ASTParser.newParser(AST.JLS2);
lParser.setSource( pCU );
lParser.setResolveBindings(true);
CompilationUnit lResult = (CompilationUnit) lParser.createAST(null);
The Problem
~~~~~~~~~~~~~
When looping through a project, generating these ASTs can take some time.
Wish List
~~~~~~~~~~~~~
If Eclipse has already generated ASTs to support refactoring etc, I
would ideally like to use those.
Failing that my question is, is there any way to persist lResult above
without manually visiting every node on the tree?
Thanks in advance !
Rory
|
|
|
Re: Does Eclipse hold ASTs for each compilation unit in the workspace? [message #226081 is a reply to message #226073] |
Mon, 20 March 2006 02:27 |
Eclipse User |
|
|
|
Originally posted by: paulo.silveira.caelum.com.br
Rory
I have a similar problem. Where are you looking for jdt.core package
tutorials, javadoc and resources?
thanks
roryc wrote:
> Hi all,
> I asked this question before but I am afraid I was a bit vague and may
> have been in the wrong thread, so here goes....
> Can anybody tell me, does Eclipse hold an abstract syntax tree for each
> compilation unit in the workspace? If so, is it possible to access
> Eclipse's AST collection?
> I had been looking at the Eclipse AST generation classes and can create
> an AST with the following:
> ASTParser lParser = ASTParser.newParser(AST.JLS2);
> lParser.setSource( pCU );
> lParser.setResolveBindings(true);
> CompilationUnit lResult = (CompilationUnit) lParser.createAST(null);
> The Problem
> ~~~~~~~~~~~~~
> When looping through a project, generating these ASTs can take some time.
> Wish List
> ~~~~~~~~~~~~~
> If Eclipse has already generated ASTs to support refactoring etc, I
> would ideally like to use those.
> Failing that my question is, is there any way to persist lResult above
> without manually visiting every node on the tree?
> Thanks in advance !
> Rory
|
|
|
Re: Does Eclipse hold ASTs for each compilation unit in the workspace? [message #226098 is a reply to message #226073] |
Mon, 20 March 2006 14:06 |
Eclipse User |
|
|
|
Originally posted by: benno_baumgartner.ch.ibm.com
"roryc" <rorycosgrove@gmail.com> wrote in message
news:dvl2vj$q1q$1@utils.eclipse.org...
> Hi all,
>
> I asked this question before but I am afraid I was a bit vague and may
> have been in the wrong thread, so here goes....
>
> Can anybody tell me, does Eclipse hold an abstract syntax tree for each
> compilation unit in the workspace? If so, is it possible to access
> Eclipse's AST collection?
>
> I had been looking at the Eclipse AST generation classes and can create an
> AST with the following:
>
> ASTParser lParser = ASTParser.newParser(AST.JLS2);
> lParser.setSource( pCU );
> lParser.setResolveBindings(true);
> CompilationUnit lResult = (CompilationUnit) lParser.createAST(null);
>
> The Problem
> ~~~~~~~~~~~~~
> When looping through a project, generating these ASTs can take some time.
>
> Wish List
> ~~~~~~~~~~~~~
> If Eclipse has already generated ASTs to support refactoring etc, I would
> ideally like to use those.
>
> Failing that my question is, is there any way to persist lResult above
> without manually visiting every node on the tree?
>
> Thanks in advance !
>
> Rory
Hi Rory
Maybe ASTParser#createASTs(ICompilationUnit[], String[], ASTRequestor,
IProgressMonitor) is what you are looking for? This is much faster for a
larg number of cus than creating an ast with #createAST in a loop. But be
carefull, if you pass to many cus to createASTs you may run into a out of
memory Exception (https://bugs.eclipse.org/bugs/show_bug.cgi?id=132121).
Hope that helps
Benno
|
|
| | |
Re: Does Eclipse hold ASTs for each compilation unit in the workspace? [message #226141 is a reply to message #226098] |
Mon, 20 March 2006 17:01 |
Eclipse User |
|
|
|
Originally posted by: rorycosgrove.gmail.com
Benno Baumgartner wrote:
> Hi Rory
>
> Maybe ASTParser#createASTs(ICompilationUnit[], String[], ASTRequestor,
> IProgressMonitor) is what you are looking for? This is much faster for a
> larg number of cus than creating an ast with #createAST in a loop. But be
> carefull, if you pass to many cus to createASTs you may run into a out of
> memory Exception (https://bugs.eclipse.org/bugs/show_bug.cgi?id=132121).
>
> Hope that helps
> Benno
>
>
Thats great, thanks! How did I miss that?
Could you tell me is there any way to persist this result? I would
obviously like to move these to disk to avoid re-creating them where
possible.
The only way I can think of so far is manually visiting each node which
is no fun ;)
Thanks again for your help.
Rory
|
|
|
Re: Does Eclipse hold ASTs for each compilation unit in the workspace? [message #226148 is a reply to message #226114] |
Mon, 20 March 2006 17:13 |
Eclipse User |
|
|
|
Originally posted by: rorycosgrove.gmail.com
Adam Kiezun wrote:
> roryc wrote:
>> Hi all,
>>
>> I asked this question before but I am afraid I was a bit vague and may
>> have been in the wrong thread, so here goes....
>>
>> Can anybody tell me, does Eclipse hold an abstract syntax tree for
>> each compilation unit in the workspace? If so, is it possible to
>> access Eclipse's AST collection?
>
> it does not. it would be way to expensive.
>
> /adam
Hi Adam,
Thanks for your reply!
This has been puzzling me slightly though, I had got the impression from
the following paper, that there was a 'Program Database' behind the
refactoring support. In fact - you probably know this one better than me ;)
Integrating Refactoring Support into a Java Development Tool
http://people.csail.mit.edu/akiezun/companion.pdf
Or are these ASTs generated on the fly, only when needed?
Thanks again for your help.
Rory
|
|
| |
Re: Does Eclipse hold ASTs for each compilation unit in the workspace? [message #226167 is a reply to message #226155] |
Mon, 20 March 2006 18:11 |
Eclipse User |
|
|
|
Originally posted by: rorycosgrove.gmail.com
Adam Kiezun wrote:
>>
>> Hi Adam,
>>
>> Thanks for your reply!
>>
>> This has been puzzling me slightly though, I had got the impression
>> from the following paper, that there was a 'Program Database' behind
>> the refactoring support. In fact - you probably know this one better
>> than me ;)
>>
>> Integrating Refactoring Support into a Java Development Tool
>> http://people.csail.mit.edu/akiezun/companion.pdf
>>
>> Or are these ASTs generated on the fly, only when needed?
>>
>> Thanks again for your help.
>> Rory
>
> Yes, ASTs are created on the fly, as a refactoring is executed.
>
> The database the paper is referring to is the SearchEngine.
> It lets you quickly find references and declarations of elements.
> Then, you can create ASTs for only the files that contain the elements
> you want.
> The 'database' is updated in a background thread and it's always
> up-to-date.
>
> AFAIK, the editor keeps an AST files that are currently open.
> But all other files and not parsed all the time.
>
> /adam
Thanks Adam! That clears everything up :)
|
|
|
Goto Forum:
Current Time: Fri Apr 19 15:11:31 GMT 2024
Powered by FUDForum. Page generated in 0.02039 seconds
|