Skip to content

1. Intermediate Model

Timur Sağlam edited this page Dec 31, 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:

IntermediateModel class diagram

The element hierarchy

The model representations of packages, classes, interfaces, enumerations and methods are all extracted elements. While ExtractedPackage and ExtractedMethod inherit from ExtractedElement directly, the classes ExtractedClass, ExtractedInterface and ExtractedEnumeration are extracted types, inheriting from the class ExtractedType, which inherits from ExtractedElement directly.

The functionality that is inherited from the class ExtractedElement is that every element has a name (e.g MyClass), the name of its parent (e.g. main.model), a full name which consists out of the parents name and the own name (e.g. main.model.MyClass) and the posibility to be selected or not for the Ecore metamodel generation.

The data type hierarchy

The classes for data types, parameters and attributes in the intermediate model are strongly connected through inheritance. A data type, modeled through the class 'ExtractedDataType' represents a single data type. It has a simple type name (like String), a full type name (like java.lang.String), array dimensions and generic arguments. The array dimensions specifiy whether this data type is an array, and how many array dimensions it has. An 'ExtractedDataType' only has generic arguments if the data type is generic. The arguments are a list of other data types.

A parameter, modeled through the class ExtractedParameter represents a method parameter. The class inehrits from the class 'ExtractedDataType'. The difference between a parameter and a data type is that the data type has a variable name, also called identifier.

An attribute, modeled through the class ExtractedAttribute, represents an attribute of a type. The class inehrits from the class 'ExtractedParameter'. One difference between an attribute and a parameter is that the attribute has an access level modifier, represented through the enumeration AccessLevelModifier, which can be PUBLIC, PROTECTED or PRIVATE. Another difference is that a ExtractedAttribute can be static or final, which is modeled thorughtwo booleans.

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.

Selecting and deselecting Elements

Every element of the intermediate can be activly deselected or reselected for the Ecore metamodel generation. An element of the intermediate model is defined as an instance of a class that inherits from the class ExtractedElement. To set whether an element is selected or not, call the method ExtractedElement.setSelected(boolean value). The default value for every ExtractedElement is true, which means it will get extracted if possible.

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