## DLTK Model

### Structure

Model is a key thing in DLTK you should know about. In fact, as you probably know, DLTK model had been cloned from JDT model. So, if you are familiar with JDT model, you will understand everything here quickly. As JDT, DLTK uses an in-memory object model to represent the workspace structure from projects level to source file internals. This structure is derived from the project's build path. The model is hierarchical. 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 of IScriptProject)
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)
IMethod | IMethod | Represents a method or constructor inside a type. (Child of IType)

You can use DLTKCore.create(...) methods to access model. These methods allow to create appropriate model element from file, resource or project.

### Model building

DLTK Model elements from workspace level down to source modules level are built automatically. All things, that you should do for that:

- Contribute IDLTKLanguageToolkit interface implementation via org.eclipse.dltk.core.language extension point.
- Set correct nature as in extension point attribute, so in getNatureId() method.
- Methods validateSourceModule() and validateSourcePackage() should return OK if source module/package is a real source module, or anything else if it's a regular file/folder.

After that, projects, that have given nature will be considered as script project and model for them will be built accordingly to internal structure, validate...() methods and build paths.

For building source module's internal model there is another mechanism called source element parsers. They are contributed via org.eclipse.dltk.core.sourceElementParsers ext. point and should implement ISourceElementParser.

Main task of source element parser is to parse source file and report internal model elements info to given ISourceElementRequestor.