|Mailing List • Forums|
|Browse Source • Project Set File|
Java Composition Metamodel
This JavaApplication metamodel aims at weaving a MoDisco Java Model with a MoDisco KDM Inventory Model. It relies on the core metamodel described in the kdm.source extension framework.
Such a metamodel allows linking java nodes to their physical position in the source files (JavaNodeSourceRegion metaclass owning startLine, endLine properties).
As proposed in the kdm.source extension framework, the reference JavaASTNodeSourceRegion.javaNode derives from ASTNodeSourceRegion.node. So does Java2File.javaUnit from CodeUnit2File.unit.
Note : the references java2DirectoryChildren and java2FileChildren are expected to be containment references. For some technical reasons (memory usage tuning via lazy loading), they are not containments to make sure that the Java2Directory, Java2File and JavaNodeSourceRegion instances are managed in their own graph compared with JavaApplication instances (see benchmark).
Java Composition Discoverer
MoDisco provides a discoverer associated to the metamodel definition described here.
The discovery takes a workspace Java project as input.
- The first step of the discovery creates one Java model, using the associated discoverer.
- The second step of the discovery creates one Kdm inventory model, using the associated discoverer.
- The third step creates a model with JavaApplication metamodel instances with references to the two leaf models.
The plug-in provides the user with a contextual menu to easily create models.
By right-clicking on a Java Project in the Eclipse Package Explorer view and choosing Discovery > Discoverers > Discover Java and Inventory model from Java project you can quickly create the Java Application model of your application:
A discovery parameters dialog opens to let you specify the parameters of the discovery:
See the documentation of the Java discoverer for an explanation of the parameters.
Once launched, a progress dialog will appear as soon as the operation begins. Depending on the size of your application, the reverse engineering process might take some time to complete:
At the end of the process, the newly created model files are added to the root of your project if you set SERIALIZE_TARGET to true:
And the model is opened in the default model browser if you selected Open model in editor after discovery:
A xmi file suffixed by _java2kdm.xmi contains the root element of the model, which refers to the _java.xmi Java model file and the _kdm.xmi Inventory model file.
Some referenced xmi fragment files are serialized into a java2kdmFragments directory (see Resources distribution in the benchmark).
Once the main file _java2kdm.xmi has been opened in the MoDisco model Browser, you may navigate through the JavaApplication metamodel instances to the Java and kdm.source metamodel instances.
Some facets called javaToKdmShortcuts and KdmToJavaShortcuts are available for allowing navigation shortcuts from some Java/Kdm.source model elements. (enabling the "Show Derived Links" option is necessary to view the shorcut links)
To take advantage of memory usage tuning (see the benchmark), for huge Java legacy code, the MoDisco global preferences should have the "resources loading depth" set to 1 (0 works but is less interesting for browsing). This setting allows the lazy loading of xmi fragment files, through the model navigation, for less memory usage than with an initial complete loading of resources.
Using the Group by package setting will ease the selection in the types panel considering the metamodels (EPackages instances) involved.
Each MoDisco discoverer implements a normalized interface and can be called programmatically (see org.eclipse.modisco.infra.discovery.core.IDiscoverer<T>).
First, add the following plug-in dependencies to your project (Require-Bundle in your Manifest.MF):
You can easily discover a Java application model programmatically. For example:
DiscoverKDMSourceAndJavaModelFromJavaProject discoverer = new DiscoverKDMSourceAndJavaModelFromJavaProject(); discoverer.discoverElement(javaProject, monitor); Resource javaApplicationModel = discoverer.getTargetModel();
To have a monitor to pass to the
discoverElement method, you can either call the discoverer in an Eclipse Job, or pass a new NullProgressMonitor if you don't need progress reporting.
As an example, you may checkout the code from the org.eclipse.modisco.java.composition.discoverer.tests project:
Java source code synchronization
A new step in Java model browsing is to link model elements directly with their source code. This synchronization is possible thanks to the MoDisco Source Code Synchronization Framework. Basically, this new feature allows the MoDisco Model Browser to behave like the Eclipse outline.
How does it work
Prerequisite is to create a Composition model
Once your composition model is opened, all you have to do to navigate from your java model to its source code is to activate the source code synchronization (this will prevent the Eclipse Properties view from opening on double-click):
And then double click on an element to directly open its file and get this element selected : on the following figure we double-clicked on the method "setMyInteger"
If you prefer to keep the action "Open the Properties view" on the double click action, you can use the contextual menu to perform a single synchronization : the result will be exactly the same
To use the plug-ins you need:
- JDK 1.5 or above
- a version of Eclipse 3.6 or above with the following set of plug-ins installed
- EMF 2.5.0 or higher
All of the source code is stored in the Eclipse public source repository:
- metamodel : https://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.modisco/plugins/trunk/org.eclipse.modisco.java.composition/
- discoverer : https://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.modisco/plugins/trunk/org.eclipse.modisco.java.composition.discoverer/
- Java source code synchronization : https://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.modisco/plugins/trunk/org.eclipse.modisco.java.composition.ui/
|Components|| Infrastructure: KDM · SMM · GASTM · Model Browser · Discovery Manager · MoDisco Workflow · Query Manager · Facet Manager · Metrics Visualization Builder · KDM Source Extension|
Technologies: Java · JEE · EjbJar · WebApp · XML
Use Cases: Simple Transformation Chain · Model Filter
|Help||Installation · SVN|
|Project||API Policy · Retention Policy · Project Plan · metrics · Accessibility Guidelines · Capabilities Disablement|