Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Question about access to AST model in JDT
Question about access to AST model in JDT [message #902830] Mon, 20 August 2012 12:18 Go to next message
Raymond Mising name is currently offline Raymond Mising name
Messages: 59
Registered: July 2009
Member
Hey guys, I have a question about access to AST models in JDT. Does JDT hold the AST model instance of a java file in memory after it is closed from editor? or whenever I want to access the AST model of an un-opened java file, I need to parse it using ASTParser? Thanks.

[Updated on: Mon, 20 August 2012 13:08]

Report message to a moderator

Re: Question about access to AST model in JDT [message #902864 is a reply to message #902830] Mon, 20 August 2012 14:46 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 1002
Registered: July 2009
Senior Member
Raymond Mising name wrote on Mon, 20 August 2012 18:18
Hey guys, I have a question about access to AST models in JDT. Does JDT hold the AST model instance of a java file in memory after it is closed from editor? or whenever I want to access the AST model of an un-opened java file, I need to parse it using ASTParser? Thanks.


The AST as provided in package org.eclipse.jdt.core.dom has to be created on-demand, it is never cached, because it is quite a heavy thing (even heavier when created with bindings). So if you as a plug-in developer need access to the AST you have to create it first - and make sure you're not holding on to it longer than necessary.

Help on how to create an AST can be found here: http://help.eclipse.org/topic/org.eclipse.jdt.doc.isv/guide/jdt_api_manip.htm&cp=3_0_0_1 (scroll down to "Code modification using the DOM/AST API").

As you also say "model", let me mention that the Java model provided in package org.eclipse.jdt.core is actually cached in memory, but that's a different animal.

Stephan
Re: Question about access to AST model in JDT [message #903264 is a reply to message #902864] Wed, 22 August 2012 14:28 Go to previous messageGo to next message
Raymond Mising name is currently offline Raymond Mising name
Messages: 59
Registered: July 2009
Member
Thanks Stephan for the replay. I know JDT caches the IDocument of java files in the CompilationUnitDocumentProvider. What about the Java model (semantic model)? Is that also cached somewhere?
Re: Question about access to AST model in JDT [message #903745 is a reply to message #903264] Sat, 25 August 2012 07:56 Go to previous message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 1002
Registered: July 2009
Senior Member
The Java model is cached, but that happens transparently. Client plug-ins typically request fresh handles from JavaCore ("create" methods). Only when structure from an IJavaElement is requested, the cache is consulted to see if this structure is already known. -> Don't worry about creating lots of handles, the cache will work behind the scenes to minimize re-computing structure. But keep in mind: these handles (IJavaElement) should always be compared using equals() never using ==.

HTH,
Stephan
Previous Topic:java.lang.nullpointerexception
Next Topic:Importing Java Web EE Netbeans Project to Eclipse
Goto Forum:
  


Current Time: Tue Sep 02 13:05:55 EDT 2014

Powered by FUDForum. Page generated in 0.01608 seconds