Difference between revisions of "JDT Core Programmer Guide"

From Eclipsepedia

Jump to: navigation, search
(AST)
m (draft header)
Line 1: Line 1:
 +
{{:DocumentationGuidelines/DraftHeader}}
 +
 
= Overview =
 
= Overview =
 
The purpose of this document is give insight into JDT Core internals.  
 
The purpose of this document is give insight into JDT Core internals.  

Revision as of 05:07, 26 June 2012

Warning2.png
Draft Content
This page is currently under construction. Community members are encouraged to maintain the page, and make sure the information is accurate.


Contents

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.

Concepts

Java Model

Java model is a lightweight model for views.

Search Engine

Indexes of declarations, references and type hierarchy relationships.

Searching steps:

  1. Indexing phase, see SearchDocument#addIndexEntry(...)
  2. Get the file names from indexes
  3. Parse the file and find out matching nodes
  4. Resolve types (see CompilationUnitDeclaration#resolve()) and narrow down matches reported from index
  5. 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.

Tests

Unit tests

To run unit tests follow the instructions under JDT_Core_Committer_FAQ#Unit_Testing.

New Java Search tests should be added to JavaSearchBugsTests2.

Performance tests

To run performance tests you need to have the following projects in your workspace:

  • org.eclipse.jdt.core.tests.performance
  • org.eclipse.jdt.core.tests.binaries
  • org.eclipse.test.performance
  • org.eclipse.test.performance.win32 (if you're on Windows)

More info about obtaining the JDT/Core source code can be found here: JDT_Core_Committer_FAQ#Where_is_the_JDT.2FCore_code.3F.

Useful VM arguments:

  • -Dmeasures=1 to reduce number of measurements to 1, default is 10
  • -Dprint=true to print more test details on the console
  • -Ddebug=true to print debug info on the console