Skip to content

1. Intermediate Model

Timur Sağlam edited this page Dec 29, 2016 · 40 revisions

Intermediate Model

The intermediate model is an tree structure that contains all extracted information about a Java project. It tries to stay close to the implicit model of the language Java and does not reflect the characteristic properties of the Ecore metametamodel.

When an intermediate model gets created by the project parser, all parsed information is added to the intermediate model, no matter if that information can be represented in an Ecore metamodel or not. As an example, an intermediate model contains enumerations with methods and attributes, which can not be represented in an Ecore metamodel, because EEnums can not have methods and attributes. That means an intermediate model contains equally as much or more information than a Ecore metamodel generated from that intermediate model.

Every intermediate model has an instance of the class IntermediateModel. It contains alle the elements of the model. The tree structure starts with an ExtractedPackage as root package, which can be accessed from the IntermediateModel instance. The class hierarchy of the intermediate model is depicted in the following diagram.

<iframe allowfullscreen frameborder="0" style="width:640px; height:480px" src="https://www.lucidchart.com/documents/embeddedchart/fb7661b4-1fb2-4ec7-a0ce-9de422a7fd4a" id="nOzksJBnX~6P"></iframe>

IntermediateModel class diagram

Accessing Intermediate Models

An intermediate model should be accessed through its instance of the class IntermediateModel. The method getRoot() grants access to the root package. Because of the tree structure of the model, all components of the model can be accessed through the root package (with the methods getClasses(), getInterfaces(), getEnumerations(), getTypes() and getSubpackages()). Another way to access the elements of the model is to use the methods getPackage() and getType(). These methods take the name of the desired package/type and return the package/type object itself. If there is no package/type with that name in the model, a IllegalArgumentException gets thrown.

Creating Intermediate Models

Intermediate models can be created with the JavaProjectParser or by hand. To allow the second option, creating them by hand, the constructors of the intermediate models classes use Strings input instead of complex Objects. To learn about using the class JavaProjectParser see the section about the parser.

To create an intermediate model by hand you need to follow these steps:

  1. Create an instance of the class IntermediateModel. The constructor takes a project name as a parameter. Normally, this is the name of the project where the model was extracted from. The project name is metadata for the metamodel generation.
  2. Create the packages of the intermediate model one by one. Use the full package names (e.g main.view.secondary).
  3. Add the packages to the class IntermediateModel. The first package will be automatically set as root. Every following package will automatically assigned to its superpackage according to its full name.
  4. Create the extracted types one by one. For every class, create its methods and attributes by hand and add them to the class. Use the full class name (e.g main.view.secondary.SomeCLass). If you want so simulate an inner class use the naming scheme package.OuterClass$InnerClass.
  5. Add the extracted types to the class IntermediateModel. When using the method add(), the classes will be added to their packages according to their full name. When using the method addTo(), you can manually add them to a specific package.
  6. Keep in mind that there is no automatic adding of methods and attributes to their extracted types.
Clone this wiki locally