|
|
(32 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | {{MoDiscoKDMSourceExtensionTabs}}
| + | #REDIRECT [[MoDisco/Moved To Help Center]] |
− | | + | |
− | == KDM.Source extension : a core metamodel for weaving Code models and KDM Inventory models ==
| + | |
− | | + | |
− | The component proposes a small framework for building weaving information between code models (Java, C++, ...) and physical resources (disk files and directories).
| + | |
− | | + | |
− | This framework reuses the [http://wiki.eclipse.org/MoDisco/Components/KDM KDM] "Source" subpackage, which proposes a model for physical resources, known as "Inventory Model" (see figure [http://wiki.eclipse.org/MoDisco/Components/KDM/Documentation/0.9#Details here])
| + | |
− | | + | |
− | KDM inventory model also proposes ''SourceRegion''/''SourceRef'' concepts for weaving other kdm models (kdm code models, ...) with physical representation. Some references exist from other KDM subpackages to the ''SourceRef'' concept.
| + | |
− | | + | |
− | [[Image:Kdmsourceregion.JPG|frame|center|KDM Source Metamodel subpart (from the KDM Specification v 1.1)]] | + | |
− | | + | |
− | MoDisco proposes to compose KDM inventory models with non-KDM models. For generic reuse reasons, a new metamodel extending KDM Source has been created. | + | |
− | | + | |
− | A subpart of KDM Source model is extended for linking the ''SourceRegion'' concept with non-KDM elements, via the ''ASTNodeSourceRegion'' metaclass.
| + | |
− | | + | |
− | Moreover a recurrent pattern, in such a model composition, is to link KDM ''SourceFile'' with a code model element. Such a link is represented with ''CodeUnit2File'' metaclass.
| + | |
− | | + | |
− | [[Image:Kdmsourceextension.JPG|frame|center|MoDisco KDM Source extension Metamodel]]
| + | |
− | | + | |
− | This is a core metamodel that the developer should extend for describing a composition between a specific code metamodel and kdm.source.
| + | |
− | | + | |
− | == How to create a composition metamodel between Code models and KDM Inventory models ==
| + | |
− | | + | |
− | Given a particular code metamodel (Such as the Java one), MoDisco proposes to extend KDMSourceExtension to define a metamodel composition between inventory models and code models.
| + | |
− | | + | |
− | The ''ASTNodeSourceRegion'' should be subclassed, and a reference to one concrete code metaclass should "specialize" the ''ASTNodeSourceRegion->node:EObject'' reference (one simple way is to set the new reference as derivated from the generic one).
| + | |
− | | + | |
− | '''''(TODO : an opposite reference should be described for allowing navigation from code elements to the ''SourceRegion'' instances --> waiting for facet shortcut evolution)'''''
| + | |
− | | + | |
− | In most cases the ''CodeUnit2File'' will be subclassed.
| + | |
− | | + | |
− | A reference example of such a composition metamodel is the [http://wiki.eclipse.org/MoDisco/Components/Java/Composition/Documentation/0.9#Java_Composition_Metamodel Java Application example].
| + | |
− | | + | |
− | [[Image:Javakdmsourceregion.JPG|frame|center|Java and kdm composition metamodel (extract)]]
| + | |
− | | + | |
− | == How to develop a discoverer for the composition between code and KDM inventory models==
| + | |
− | | + | |
− | === Overview ===
| + | |
− | | + | |
− | After describing a composition metamodel, the contributor/adopter has to write an associated [http://wiki.eclipse.org/MoDisco/Components/DiscoverersManager discoverer].
| + | |
− | Such a discoverer will instantiate elements for the ''composition metamodel'' described before (''JavaSourceRegions''...)
| + | |
− | Such a discoverer will have to manipulate the both kdm.source and code models.
| + | |
− | | + | |
− | A kdm.source model can be discovered using the [[http://wiki.eclipse.org/MoDisco/Components/KDM/Documentation/0.9#KDM_Source_Discoverer KDM Source discoverer]]. Note that such a discoverer only provides a representation of files/directories. It does not instantiate ''SourceRegions'' subclasses.
| + | |
− | | + | |
− | A discoverer for the related code model is a prerequisite. The [[http://wiki.eclipse.org/MoDisco/Components/Java/Documentation/0.9#Java_Discoverer Java Discoverer]] is an example. Such a discoverer is not supposed to instantiate ''SourceRegions'' subclasses. To avoid ambiguity, we will talk about it as a "leaf code discoverer".
| + | |
− | | + | |
− | The composite discoverer should, in most cases, invoke the leaf discoverers (kdm.source and code). Another way is to provide the leaf models as parameters values to the composite discoverer.
| + | |
− | | + | |
− | A reference example of such a composition dicoverer is the [http://wiki.eclipse.org/MoDisco/Components/Java/Composition/Documentation/0.9#Java_Composition_Discoverer Java Application discoverer example] (Java class DiscoverKDMSourceAndJavaModel).
| + | |
− | | + | |
− | [[Image:Codekdmdiscovery.JPG|frame|center|Composition discovery overview]]
| + | |
− | | + | |
− | === Instrumenting the leaf code discoverers for retrieving visited source regions ===
| + | |
− | | + | |
− | In most cases, code discoverers have access to physical localization for each portion of code that is modeled.
| + | |
− | | + | |
− | There are two ways for a composite discoverer to catch such an information when invoking the leaf discoverer :
| + | |
− | * subclass some leaf discoverer implementation classes.
| + | |
− | * add a listener to the leaf discoverer to listen for source regions visit events.
| + | |
− | | + | |
− | The second way implies that the leaf discoverer extends the ''org.eclipse.modisco.kdm.source.extension.discovery.AbstractRegionDiscoverer'' class to support the registering of ''org.eclipse.modisco.kdm.source.extension.discovery.SourceRegionVisitListener''.
| + | |
− | | + | |
− | ''AbstractRegionDiscoverer.notifyRegionSourceVisit'' must be called when appropriate from inside the leaf discoverer.
| + | |
− | | + | |
− | The [[http://wiki.eclipse.org/MoDisco/Components/Java/Documentation/0.8#Java_Discoverer Java discoverer]] implementation class illustrates such a pattern application.
| + | |
− | | + | |
− | The following figure illustrates the architecture for leaf and composite discoverers related to a CSharp metamodel.
| + | |
− | | + | |
− | [[Image:Csharpkdmdiscovery2.JPG|frame|center|Applicative Architecture for CSharp leaf and composite discoverers example]]
| + | |
− | | + | |
− | === Instantiate source region nodes ===
| + | |
− | | + | |
− | Once the composite discoverer has the capability to retrieve information about sources regions visited and associated code model elements, it will instantiate the ''SourceRegion''.
| + | |
− | | + | |
− | === Resources Distribution and memory usage ===
| + | |
− | | + | |
− | Creating one ''SourceRegion'' instance for each code model element may induce some memory usage issues. Considering a given code metamodel, it may be interesting to have a strategy for dispatching model elements (from the composition model) into more than one XMI resource file.
| + | |
− | | + | |
− | Thus, EMF lazy resource loading mechanism enables opening and working with some subpart of the model.
| + | |
− | | + | |
− | A reference implementation for this strategy is in the
| + | |
− | [[http://wiki.eclipse.org/MoDisco/Components/Java/Composition/Architecture#Benchmark Java Application discovery]].
| + | |
− | | + | |
− | '''''(TODO : indicate gain with MinimalEObject)'''''
| + | |
− | | + | |
− | == Requirements ==
| + | |
− | | + | |
− | To use the plug-in you need:
| + | |
− | | + | |
− | *JDK 1.5 or above
| + | |
− | *a version of Eclipse 3.6 or above with the following set of plug-ins installed
| + | |
− | | + | |
− | :*[[EMF|EMF]] 2.5.0 or higher
| + | |
− | | + | |
− | == Source Repository ==
| + | |
− | | + | |
− | All of the source code is stored in a public source repository, which you can access at:
| + | |
− | | + | |
− | [https://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.modisco/plugins/trunk/org.eclipse.modisco.kdm.source.extension/ https://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.modisco/plugins/trunk/org.eclipse.modisco.kdm.source.extension/]
| + | |