Skip to content

5. Ecore Code Adaption

Timur Sağlam edited this page Sep 17, 2018 · 1 revision

Adapting the Ecore code

The Ecore code originally uses its Ecore interfaces as parameters and return types for its methods. We change that to make sure that all the classes of the Ecore code use the original types of the origin code. Without that change, the original method calls will result in errors after the removal of the fields and their access methods.

This can be achieved by changing the import declarations of classes in the Ecore code that have a counterpart in the origin code (and therefore also in the Ecore metamodel). The main class for adapting the Ecore code is the class EcoreImportManipulator. It offers the method manipulate() which takes an IProject and does the following steps for every implementation class of the Ecore code:

  • Finding the correlating Ecore interface of the implementation class
  • Checking all import declarations in the implementation class on whether they reference a type from the Ecore package which has a counterpart in the Ecore metamodel and the original code (This excludes imports of Ecore package types, Ecore factory types, and other API types).
  • Changing all matching import declarations in the implementation class, so they reference their origin code counterparts.
  • Removing the original import declaration from the correlating Ecore interface if it exists there.
  • Adding the changed import declarations to the correlating Ecore interface.
  • Retaining the original super interface declarations of both types be replacing the type names through their fully qualified type name.

The super interface declarations have to retained because the manipulated import declarations might originally have referenced the type which is used in the super interface declaration. This is done using the InterfaceRetentionVisitor class. Finding the correlating Ecore interface and checking whether a compilation unit is an Ecore Implementation class are done with the help of an additional class: The TypeNameResolver which resolves the fully qualified name of the package member type of a compilation unit.

Clone this wiki locally