Jump to: navigation, search

Difference between revisions of "JDT Core Programmer Guide"

(Search Engine)
m (Search Engine)
Line 13: Line 13:
 
# Get the file names from indexes
 
# Get the file names from indexes
 
# Parse the file and find out matching nodes
 
# Parse the file and find out matching nodes
# Resolve types and narrow down matches reported from index
+
# Resolve types (see [http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tree/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java#n528 CompilationUnitDeclaration#resolve()]) and narrow down matches reported from index
 
# Create the appropriate model element
 
# Create the appropriate model element
  

Revision as of 09:11, 20 June 2012

Overview

The purpose of this document is give insight into JDT Core internals.

If you're looking for information on JDT APIs you'd better start from visiting JDT Core section in Eclipse Help. You can also check How to Train the JDT Dragon presentation by Ayushman Jain and Stephan Herrmann. Instructions for the tutorial can be found here.

If the answer to your question is neither there nor here, ask the question.

Java Model

Java model is a lightweight model for views.

Search Engine

Indexes of declarations, references and type hierarchy relationships.

Searching steps:

  1. Get the file names from indexes
  2. Parse the file and find out matching nodes
  3. Resolve types (see CompilationUnitDeclaration#resolve()) and narrow down matches reported from index
  4. Create the appropriate model element

Precise and non-precise matches

If there is a search result for the given pattern, but a problem (e.g. errors in code, incomplete class path) occurred, the match is considered as inaccurate.

Inaccurate matches used to be called potential matches and as such can still be seen in the tests and tracing messages.

Using the APIs, an example

Create a search pattern:

SearchPattern pattern = SearchPattern.createPattern(
 "foo(*) int", 
 IJavaSearchConstants.METHOD, 
 IJavaSearchConstants.DECLARATIONS, 
 SearchPattern.R_PATTERN_MATCH
);

Create a search scope:

IJavaSearchScope scope = SearchEngine.createWorkspaceScope();

Collect results using SearchRequestor subclass:

SearchRequestor requestor = new SearchRequestor() {
 public void acceptSearchMatch(SearchMatch match) {
   System.out.println(match.getElement());
 }
};

Start search:

new SearchEngine().search(
 pattern, 
 new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant()}, 
 scope, 
 requestor, 
 null /*progress monitor*/
);

AST

Precise, fully resolved compiler parse tree.