Skip to content
Timur Sağlam edited this page May 23, 2018 · 60 revisions

The Ecore metamodel extraction was originally developed as a part of a bachelor's thesis. The thesis is accessible at KITopen. This wiki contains three kinds of information: How to use the project, how to work with the source code of the project and general information about the architecture and the internal processes. The Ecore metamodel extraction is used in the project JavaCodeEcorification.

Basic Use

The project can be used in two different ways. One can use the project as an Eclipse Plugin through the MainHandler class or address the main class 'EcoreMetamodelExtraction' directly.

  1. When using it as a plugin, projects can be selected for the extraction via the package explorer context menu or the EME button at the toolbar. The extraction is executed with the constraints of the user properties file. To use the project this way, run the project as Eclipse Application. The extracted Ecore metamodel is saved according to the selected saving strategy.

  2. When working with the class EcoreMetamodelExtraction directly, it offers two simple methods to work with. The method getProperties() grants access to the instance of the class ExtractionProperties, which allows configuring the extraction process programmatically (see Properties). This can also be done by editing the properties file before running the program. With the method extract() the metamodel extraction is started for a given IProject.

For demo purposes, the repository EME-TestProject can be used. It is a simple Java project containing code that allows testing the extraction of the different supported features. See the project README for installation hints.

The Extraction

This project is a reverse engineering tool for Ecore metamodels. It allows extracting Ecore metamodels from any arbitrary Java code. At the core of the approach is a mapping from elements of the implicit Java metamodel, which the Java Language Specification defines, to elements of the Ecore meta-metamodel. Both models are very similar in many ways, but they are not identical. That means the Ecore meta-metamodel cannot be used to represent Java code perfectly. As a result, some features of the Java language can only be extracted under certain conditions, while other features cannot be extracted at all. For a more detailed description of the differences see the page Model Differences.

This program extracts packages with their hierarchy, interfaces, classes, enumerations with their enumerals, inheritance and realization relations, attributes, methods with their parameters, return types and throws declarations, generic types with their type parameters, generic arguments, and wildcard types.

To further understand how the project extracts Ecore metamodels from Java code, you have to look at the extraction table. It depicts the mapping between different elements of the language Java and their relating Ecore elements. The left column contains the Java elements. The right column contains the Ecore elements which are generated from the extracted features. The middle column shows another set of elements. These are the relating elements of the intermediate model. The intermediate model is an internal model which is used for the extraction. That means we internally map from Java elements to intermediate model elements and intermediate model elements to Ecore elements.

Extraction Table:

Java Model (implicit) Intermediate Model Ecore Meta-Metamodel
Package ExtractedPackage EPackage
Type ExtractedType EClassifier
Class ExtractedClass EClass
Interface ExtractedInterface EClass
Enum ExtractedEnumeration EEnum
Enumeral ExtractedEnumeral EEnumLiteral
Field ExtractedField EStructuralFeature (EAttribute / EReference)
Method ExtractedMethod EOperation
Method Parameter ExtractedParameter EParameter
Method Return Type ExtractedDataType EClassifier / EGenericType
Method Throws Declaration ExtractedDataType EClassifier / EGenericType
Generic Type Parameter ExtractedTypeParameter ETypeParameter
Generic Type Argument ExtractedDataType EGenericType
Generic Type Bound ExtractedDataType EGenericType
Super Type Reference ExtractedDataType EClass & EGenericType

General Architecture

Even though the project consists out of ten packages, the general architecture can be broken down into three parts: The project extractor, the intermediate model, and the metamodel generator. The extractor analyzes a Java project using the JDT API and extracts all the information the implicit model of the Java code contains. With this information, the extractor then builds an intermediate model. The generator then uses the intermediate model to build an Ecore metamodel. The Ecore metamodel is built like a tree structure out of EObjects, with a root package as a container of all the elements of the metamodel. The generator also can save the generated Ecore metamodel as an Ecore file. For this process, there are several different saving strategies available.

The whole extraction process is depicted in the following diagram: EME process flow

Package structure

The projects main package eme contains five subpackages: eme.extractor, eme.model, eme.generator, eme.properties and eme.handlers. The packages eme.extractor, eme.model and eme.generator contain the three key components which were explained before. The eme.properties package contains the classes for the management of the properties file. The package eme.handler contains the main handler, which allows using the project as a plugin for the Eclipse IDE and offers a simple dialog for choosing an input project.

To understand the different parts of the project, see the following pages:

  1. Intermediate Model

  2. Java Project Extractor

  3. Ecore Metamodel Generator

  4. Saving Strategies

  5. Extraction Properties

  6. Multiplicities

  7. Scope Selection

Clone this wiki locally