Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "DLTK Core Architecture"
(Improve wording (no addition to content)) |
|||
Line 2: | Line 2: | ||
== Build paths == | == Build paths == | ||
− | Similar to | + | Similar to Java's class paths, DLTK has the concept of build paths. |
− | + | A build path is the set of source folders, library containers and references to other projects. The build path is used for model building and launching. | |
− | + | The build path is stored in the file .buildpath relative to the project's root folder. DLTK automatically reads it when required. You can get the current project's build path as an array of <code lang="java">IBuildpathEntry</code>s via the <code lang="java">IScriptProject.getRawBuildpath()</code> method. To change the build path for a project use the <code lang="java">setRawBuildpath()</code> method. New elements of <code lang="java">IBuildpathEntry</code> may be created with the <code lang="java">DLTKCore.new*Entry(...)</code> methods. | |
== Model == | == Model == | ||
− | + | The DLTK model is central to understanding DLTK. The DLTK model is based on the JDT model, so if you are familiar with that then you will understand everything here quickly. | |
− | + | ||
− | The following table summarizes the different kinds of model elements. All elements classes support the IModelElement interface. | + | Like JDT, DLTK uses an in-memory, hierarchical object model to represent the workspace structure from the project level down to source file internals. This structure is derived from the project's build path. |
+ | |||
+ | The following table summarizes the different kinds of model elements. All elements classes support the <code lang="java">IModelElement</code> interface. | ||
<table border=1> | <table border=1> | ||
Line 21: | Line 23: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td>IScriptModel</td> | + | <td><code lang="java">IScriptModel</code></td> |
− | <td>IJavaModel</td> | + | <td><code lang="java">IJavaModel</code></td> |
<td>Represents the root model element, corresponding to the | <td>Represents the root model element, corresponding to the | ||
workspace. The parent of all projects with the script natures. It also | workspace. The parent of all projects with the script natures. It also | ||
Line 28: | Line 30: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td>IScriptProject</td> | + | <td><code lang="java">IScriptProject</code></td> |
− | <td>IJavaProject</td> | + | <td><code lang="java">IJavaProject</code></td> |
<td>Represents a script project in the workspace. (Child of | <td>Represents a script project in the workspace. (Child of | ||
− | IScriptModel)</td> | + | <code lang="java">IScriptModel</code>)</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td>IProjectFragment</td> | + | <td><code lang="java">IProjectFragment</code></td> |
− | <td>IPackageFragmentRoot</td> | + | <td><code lang="java">IPackageFragmentRoot</code></td> |
<td>Represents a project fragment, and maps the contents to an | <td>Represents a project fragment, and maps the contents to an | ||
underlying resource which is either a folder, JAR, or ZIP file. (Child | underlying resource which is either a folder, JAR, or ZIP file. (Child | ||
− | of IScriptProject)</td> | + | of <code lang="java">IScriptProject</code>)</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td>IScriptFolder</td> | + | <td><code lang="java">IScriptFolder</code></td> |
− | <td>IPackageFragment</td> | + | <td><code lang="java">IPackageFragment</code></td> |
<td>Represents a folder containing script files inside. (Child of | <td>Represents a folder containing script files inside. (Child of | ||
− | IProjectFragment )</td> | + | <code lang="java">IProjectFragment</code>)</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td>ISourceModule</td> | + | <td><code lang="java">ISourceModule</code></td> |
− | <td>ICompilationUnit</td> | + | <td><code lang="java">ICompilationUnit</code></td> |
− | <td>Represents a source file. (Child of IScriptFolder)</td> | + | <td>Represents a source file. (Child of <code lang="java">IScriptFolder</code>)</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td>IPackageDeclaration</td> | + | <td><code lang="java">IPackageDeclaration</code></td> |
− | <td>IPackageDeclaration</td> | + | <td><code lang="java">IPackageDeclaration</code></td> |
<td>Represents a package declaration in a source module. (Child | <td>Represents a package declaration in a source module. (Child | ||
− | of ISourceModule )</td> | + | of <code lang="java">ISourceModule</code>)</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td>IType</td> | + | <td><code lang="java">IType</code></td> |
− | <td>IType</td> | + | <td><code lang="java">IType</code></td> |
<td>Represents either a class/module/namespace inside a source | <td>Represents either a class/module/namespace inside a source | ||
file.</td> | file.</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td>IField</td> | + | <td><code lang="java">IField</code></td> |
− | <td>IField</td> | + | <td><code lang="java">IField</code></td> |
− | <td>Represents a field inside a type. (Child of IType)</td> | + | <td>Represents a field inside a type. (Child of IType</code>)</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td>IMethod</td> | + | <td><code lang="java">IMethod</code></td> |
− | <td>IMethod</td> | + | <td><code lang="java">IMethod</code></td> |
<td>Represents a method or constructor inside a type. (Child of | <td>Represents a method or constructor inside a type. (Child of | ||
− | IType)</td> | + | IType</code>)</td> |
</tr> | </tr> | ||
</table> | </table> | ||
− | You | + | You should use the <code lang="java">DLTKCore.create(...)</code> methods to build out a model. These methods make it easy for the DLTK user to create the appropriate model element from a file, resource or project. |
== Model building == | == Model building == | ||
− | DLTK | + | DLTK automatically provides model elements from the workspace level down to the source modules level. To extend the model, the DLTK user should: |
− | * | + | * contribute a <code lang="java">IDLTKLanguageToolkit</code> interface implementation via the <code>org.eclipse.dltk.core.language</code> extension point, |
− | * | + | * contribute the language-specific nature as an extension point attribute, and return that from the <code lang="java">getNatureId()</code> method, |
− | * | + | * implement methods <code lang="java">validateSourceModule()</code> and <code lang="java">validateSourcePackage()</code> to return OK only for source modules or packages that are real source modules. |
− | + | User projects that have the right nature will then be considered as a script project and the DLTK model for them will be built accordingly to internal structure, results from <code lang="java">validate...()</code> methods and from build paths. | |
− | For building source module's internal model there is another mechanism called source element parsers. | + | For building a source module's internal model elements, there is another mechanism called source element parsers. These are contributed via the <code>org.eclipse.dltk.core.sourceElementParsers</code> extension point and should implement <code lang="java">ISourceElementParser</code>. |
− | + | The main task of the source element parser is to parse source files and report internal model element information to the given <code lang="java">ISourceElementRequestor</code>. | |
== Search engine == | == Search engine == | ||
Line 95: | Line 97: | ||
===Indexes=== | ===Indexes=== | ||
− | + | The platform's search engine uses indexes. An index is a set of documents and the keys associated with them. There are possible several different indexes (for type names, methods, ...). | |
− | DLTK automatically index all source files in a separate thread. | + | DLTK automatically builds an index for all script source files in a separate thread. The DLTK provides a standard source element parser with a requester set to it's own <code lang="java">SourceIndexerRequestor</code> object. The source element parser doesn't know anything about search and just reports model elements info. The task of the <code lang="java">SourceIndexerRequestor</code> is to find and report appropriate index keys to the platform's <code lang="java">SourceIndexer</code>. The DLTK user may extend the DLTK's <code lang="java">SourceIndexerRequestor</code> as required. |
===Search=== | ===Search=== | ||
− | Before using the search engine user should prepare | + | Before using the search engine, the user should prepare DLTK <code lang="java">SearchPattern</code> objects. These may be a <code lang="java">TypeDeclarationPattern</code> or a <code lang="java">MethodPattern</a>. These can be created using the static method <code lang="java">SearchPattern.createPattern()</code>. |
− | After that user should specify a search scope(project, workspace,...). | + | |
− | + | After that, the user should specify a search scope(project, workspace,...). The scope may be created with the <code lang="java">SearchEngine.createSearchScope()</code> method. | |
− | + | ||
− | < | + | The final item required is a <code lang="java">SearchRequestor</code> object that will receive all successful search matches. |
− | + | When that is ready, DLTK's <code lang="java">SearchEngine.search()</code> may be called. Here is an example: | |
+ | <source lang="java"> | ||
+ | SearchRequestor requestor = new SearchRequestor() { | ||
+ | public void acceptSearchMatch(SearchMatch match) | ||
+ | throws CoreException { | ||
+ | // process match | ||
+ | } | ||
+ | }; | ||
− | + | SearchPattern pattern = SearchPattern.createPattern(namePattern, | |
− | + | IDLTKSearchConstants.METHOD, IDLTKSearchConstants.DECLARATIONS, | |
− | + | SearchPattern.R_PATTERN_MATCH | SearchPattern.R_EXACT_MATCH); | |
− | + | IDLTKSearchScope scope = SearchEngine.createWorkspaceScope(RubyLanguageToolkit | |
+ | .getDefault()); | ||
− | + | try { | |
− | + | SearchEngine engine = new SearchEngine(); | |
− | + | engine.search(pattern, new SearchParticipant[] { SearchEngine | |
− | + | .getDefaultSearchParticipant() }, scope, requestor, null); | |
− | + | } catch (CoreException e) { | |
− | + | if (DLTKCore.DEBUG) | |
− | + | e.printStackTrace(); | |
− | + | } | |
− | + | </source> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ===How search works=== | |
− | + | Extending the search engine requires understanding of how the search engine works. When <code lang="java">SearchEngine.search()</code> is called, a special <code lang="java">PatternSearchJob</code> is created containing all the indexes being enumerated. As result the list of documents containing matching keys will be found. Next, each document is reparsed with a <code lang="java">MatchLocator</code> and appropriate <code lang="java">SearchMatch</code> objects are reported. | |
− | + | The DLTK user should provide an implementation of <code lang="java">MatchLocatorParser</code> to use for reparsing. This object will receive a <code lang="java">MatchLocator</code> and a <code lang="java">PossibleMatch</code> (indicating a candidate source file) and while parsing should invoke the <code lang="java">match(...)</code> method on the <code lang="java">MatchLocator</code> with the matches it determines. | |
==Runtime model ("mixin" model)== | ==Runtime model ("mixin" model)== |
Revision as of 18:19, 13 September 2010
Contents
Build paths
Similar to Java's class paths, DLTK has the concept of build paths.
A build path is the set of source folders, library containers and references to other projects. The build path is used for model building and launching.
The build path is stored in the file .buildpath relative to the project's root folder. DLTK automatically reads it when required. You can get the current project's build path as an array of IBuildpathEntry
s via the IScriptProject.getRawBuildpath()
method. To change the build path for a project use the setRawBuildpath()
method. New elements of IBuildpathEntry
may be created with the DLTKCore.new*Entry(...)
methods.
Model
The DLTK model is central to understanding DLTK. The DLTK model is based on the JDT model, so if you are familiar with that then you will understand everything here quickly.
Like JDT, DLTK uses an in-memory, hierarchical object model to represent the workspace structure from the project level down to source file internals. This structure is derived from the project's build path.
The following table summarizes the different kinds of model elements. All elements classes support the IModelElement
interface.
Element | JDT-analog | Description |
IScriptModel |
IJavaModel |
Represents the root model element, corresponding to the
workspace. The parent of all projects with the script natures. It also gives you access to the projects without the script nature. |
IScriptProject |
IJavaProject |
Represents a script project in the workspace. (Child of
IScriptModel ) |
IProjectFragment |
IPackageFragmentRoot |
Represents a project fragment, and maps the contents to an
underlying resource which is either a folder, JAR, or ZIP file. (Child ofIScriptProject ) |
IScriptFolder |
IPackageFragment |
Represents a folder containing script files inside. (Child of
IProjectFragment ) |
ISourceModule |
ICompilationUnit |
Represents a source file. (Child of IScriptFolder ) |
IPackageDeclaration |
IPackageDeclaration |
Represents a package declaration in a source module. (Child
of ISourceModule ) |
IType |
IType |
Represents either a class/module/namespace inside a source file. |
IField |
IField |
Represents a field inside a type. (Child of IType</code>) |
ASTNote | Superclass of all the ast nodes. |
ASTListNode | Represents list of nodes. |
ModuleDeclaration | Top-level node for a source file. |
TypeDeclaration | Declaration of class/module/namespace. |
MethodDeclaration | Declaration of procedure or method. |
Other classes you can find in org.eclipse.dltk.ast.* packages. Usage of DLTK AST is not mandatory, but some DLTK features like folding may rely on it and greatly simplify implementation.
Copyright © Eclipse Foundation, Inc. All Rights Reserved.