Skip to content

1. Intermediate Model

Timur Sağlam edited this page Jan 5, 2017 · 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. This is the base class of an intermediate model. It contains all the elements of the model and offers methods for searching through the content 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 possibility to be selected or not for the Ecore metamodel generation.

An ExtractedPackage contains any number of instances of ExtractedPackage to represent subpackages. It also contains any number of instances of ExtractedTypes to represent the interfaces, classes and enumerations of the package. An ExtractedType (which can be an ExtractedInterface, an ExtractedClass or an ExtractedEnumeration) has instances of the classes ExtractedMethod and ExtractedAttribute. These are the methods and attributes of the type. An ExtractedEnumeration additionally has enumerals, but they are stored internally. An ExtractedMethod contains an AccessLevelModifier and instances of the classes ExtractedParameter and ExtractedDataType Parameters are modeled through ExtractedParameter instances. The method return type and the exception declarations are modeled through ExtractedDataType instances.

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 (like a method return type or a throws declaration). It has a simple type name (like String), a full type name (like java.lang.String), array dimensions and generic arguments. The array dimensions specify 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. That means a generic data type is a small tree structure itself, because every generic argument can have generic arguments itself.

A parameter, modeled through the class ExtractedParameter represents a method parameter. The class inherits 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 inherits 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 through two 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() from IntermediateModel. 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 actively selected or deselected 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. Selected elements will not be generated if the properties (see Properties) do not allow the extraction of those elements.

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