Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #226114 is a reply to message #226073] Mon, 20 March 2006 16:18 Go to previous messageGo to next message
Adam Kiezun is currently offline Adam KiezunFriend
Messages: 219
Registered: July 2009
Senior Member
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
Re: Does Eclipse hold ASTs for each compilation unit in the workspace? [message #226133 is a reply to message #226081] Mon, 20 March 2006 16:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rorycosgrove.gmail.com

Paulo Silveira wrote:
> Rory
>
> I have a similar problem. Where are you looking for jdt.core package
> tutorials, javadoc and resources?
>
> thanks
>

IBM DeveloperWorks has some good stuff - basically anywhere I can get it!

Feel free to send me an email if you have a more specific question.
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #226155 is a reply to message #226148] Mon, 20 March 2006 17:56 Go to previous messageGo to next message
Adam Kiezun is currently offline Adam KiezunFriend
Messages: 219
Registered: July 2009
Senior Member
>
> 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
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 Go to previous message
Eclipse UserFriend
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 :)
Previous Topic:Using diff tool for external files
Next Topic:Lemo COBOL IDE
Goto Forum:
  


Current Time: Fri Apr 19 15:11:31 GMT 2024

Powered by FUDForum. Page generated in 0.02039 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top