Skip to content

1. Intermediate Model

Timur Sağlam edited this page Mar 2, 2017 · 40 revisions

Intermediate Model

The intermediate model is a 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 meta-metamodel.

When an intermediate model gets created by the project extractor, all extracted information is added to the intermediate model, no matter if that information can be represented in an Ecore metamodel or not. For example, an intermediate model contains enumerations with methods and attributes, which cannot be represented in an Ecore metamodel, because EEnums cannot have methods and attributes. That means an intermediate model contains equally as much or more information than an 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. It also contains a list of external datatypes that are referenced by elements of the intermediate model. The intermediate model can be divided into two different hierarchies. The element hierarchy in the package eme.modeland the datatype hierarchy in the package eme.model.datatypes.

The element hierarchy

element hierarchy class diagram The model representations of Java 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, which are instances of the class ExtractedEnumeral. An ExtractedMethod contains an AccessLevelModifier and a MethodType as well as 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

data type hierarchy class diagram The classes for data types, parameters, and attributes 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 generic arguments are modeled as 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 data type also has a wildcard status, which is represented through the enumeration WildcardStatus. This status determines whether the data type is a wildcard type and if so, whether it has an upper or a lower bound. The WildcardStatus NO_WILDCARD means that a data type is not a wildcard type.

An ExtractedVariable is an 'ExtractedDataType' with a variable name, also called identifier.

A parameter, modeled through the class ExtractedParameter represents a method parameter. The class inherits from the class 'ExtractedVariable'. It has no additional functionality.

An attribute, modeled through the class ExtractedAttribute, represents an attribute of a type. The class inherits from the class ExtractedVariable. One difference between an attribute and a variable 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 an ExtractedAttribute can be static or final, which is modeled through two booleans.

A generic type parameter is modeled through the class ExtractedTypeParameter. This class does not inherit from ExtractedDataType. Like a parameter, it has an identifier or name. The type parameter also has any number of type parameter bounds. The bounds are represented by a list of data types.

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, an IllegalArgumentException gets thrown. The external data types of an intermediate model can be accessed one by one with the method getExternalType() or all at once with the method getExternalTypes().

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. Deselecting extracted types that are used as method, parameter or attribute type will lead to the generation of an EDataType

Creating Intermediate Models

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

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 be assigned to its super package 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).
  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. Keep in mind that there is no automatic adding of methods and attributes to their extracted types.
  6. If you want to provide additional information for external datatypes (e.g. external type parameters) you can add external data types as ExtractedType directly to the IntermediateModel.