Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Mapping SearchEngine results into jdt.core.dom nodes?
Mapping SearchEngine results into jdt.core.dom nodes? [message #1738189] Sun, 17 July 2016 22:24 Go to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 599
Registered: January 2010
Location: Birmingham, UK
Senior Member

Hello all,

In the Epsilon [1] project, we want to expose regular Java projects as models. To do so, we wrote some code [2] that takes IJavaProject instances and uses an ASTVisitor instance to collect information from jdt.core.dom AST nodes. For instance, with TypeDeclaration.all" you can list all the TypeDeclarations in a project.

Later on, we found out about the SearchEngine class in jdt.core.search and thought it'd be nice to use that to be able to quickly look up classes by name. We have a first version of the integration, but we've run into a slight issue: the search engine serves up SourceTypes and BinaryTypes, not the TypeDeclarations that we want.

We first tried adapting some code from the JDT autocomplete code, but that produced jdt.internal.compiler.ast TypeDeclarations, which a) are internal and b) are not the jdt.core.dom TypeDeclarations that we want. Eventually what we did [3] is get the ICompilationUnit from the search result, reparse and find the jdt.core.dom TypeDeclaration whose name matches that of the SourceType, but having to reparse the file feels inefficient.

Is there a better way to map the results of the SearchEngine to JDT DOM nodes? Should we use a different approach?

Thanks in advance!
Antonio

[1]: http://www.eclipse.org/epsilon/
[2]: https://github.com/epsilonlabs/emc-jdt
[3]: https://github.com/epsilonlabs/emc-jdt/blob/master/org.eclipse.epsilon.emc.jdt/src/org/eclipse/epsilon/emc/jdt/SearchableTypeCollection.java#L73
Re: Mapping SearchEngine results into jdt.core.dom nodes? [message #1738534 is a reply to message #1738189] Wed, 20 July 2016 15:28 Go to previous messageGo to next message
Raffi Khatchadourian is currently offline Raffi KhatchadourianFriend
Messages: 8
Registered: July 2015
Junior Member

You can have a look at
org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil.getAstNode(SearchMatch, CompilationUnit)
, but it's an internal API. There is also a set of overloaded getExactASTNode() methods here. You'll see one there that takes only a SearchMatch and a ProgressMonitor.
Re: Mapping SearchEngine results into jdt.core.dom nodes? [message #1738606 is a reply to message #1738534] Thu, 21 July 2016 10:59 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 599
Registered: January 2010
Location: Birmingham, UK
Senior Member

Thanks, that seems to do most of the work. The CompilationUnit is still a DOM one, not an internal one, so I understand we still need to reparse the internal.core ICompilationUnit into a DOM CompilationUnit using the ASTParser.
Re: Mapping SearchEngine results into jdt.core.dom nodes? [message #1738767 is a reply to message #1738606] Sat, 23 July 2016 15:26 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Antonio Garcia-Dominguez wrote on Thu, 21 July 2016 12:59
Thanks, that seems to do most of the work. The CompilationUnit is still a DOM one, not an internal one, so I understand we still need to reparse the internal.core ICompilationUnit into a DOM CompilationUnit using the ASTParser.


Small correction: org.eclipse.jdt.core.ICompilationUnit is not internal, it's just part of a different representation (the "Java model"). Since an ICompilationUnit doesn't have the details that an AST has, parsing is indeed needed to get the AST representation (aka "DOM"), if you need those details ...
Re: Mapping SearchEngine results into jdt.core.dom nodes? [message #1738769 is a reply to message #1738767] Sat, 23 July 2016 16:04 Go to previous message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 599
Registered: January 2010
Location: Birmingham, UK
Senior Member

Thank you for the clarification Smile.
Previous Topic:EMF refactor
Next Topic:MARS.1 -> MARS.2 upgrade kills installation
Goto Forum:
  


Current Time: Sat Oct 05 03:41:43 GMT 2024

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

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

Back to the top