Skip to content
Timur Sağlam edited this page Jul 17, 2017 · 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 directly the main class EcoreMetamodelExtraction.

  1. When using it as a plugin, a simple dialog allows choosing a Java project which is then used to extract a metamodel. 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 menu EME in the menu bar allows choosing two options: Plain extraction of a metamodel without saving (only logger output) and extraction of a metamodel followed by saving it into a file according to the selected saving strategy.

  2. When working with the class EcoreMetamodelExtraction directly, it offers three 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 methods extractFrom() and extractAndSaveFrom() 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

The theoretical approach to the extraction is to find a mapping between the elements of the implicit model of the language Java and the 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 can only be extracted under certain conditions, while other features cannot be extracted from the language Java 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 the project maps from Java elements to intermediate model elements and from 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
Attribute ExtractedAttribute 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 as a tree structure out of EObjects, with a root package as a container of all the elements of the metamodel. The generator also has the ability to 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

Clone this wiki locally