Jump to: navigation, search


MoDisco Role

The MoDisco role component introduced the "role" concept. A role is a kind of virtual class extension. Those "virtual classes" will never have instances. An object can be conform to a role but can not be an instance of a role.


The goal of role concept introduction is to be able to highlight some model elements having a specific role.


How to create a model role set

The first step is to create a MoDisco project.

The second step is to create a query set. This query set will store boolean queries indicating if an object is conform to a role.


MoDisco Role newRoleSet 001.gif

Select "Role Model" and press the "Next" button

MoDisco Role newRoleSet 002.gif


MoDisco Role newRoleSet 003.gif


MoDisco Role newRoleSet 004.gif

MoDisco Role newRoleSet 005.gif


MoDisco Role newRoleSet 006.gif

Set the name of the role set and take care that the role set name is the same than the containing file name ("My" in the example). The nsURI and prefix must also be filled.

MoDisco Role newRoleSet 007.gif


MoDisco Role newRoleSet 008.gif


MoDisco Role newRoleSet 009.gif


MoDisco Role newRoleSet 010.gif


MoDisco Role newRoleSet 011.gif


MoDisco Role newRoleSet 012.gif

To specify how to know if an object is conform to a role, we have to provide a boolean query. To provide this query we have to load the model containing its description.

MoDisco Role newRoleSet 013.gif

The query has to referred using the MoDisco protocol: "modisco:/query/<querySetName>". In the example, we use the "My" query set.

MoDisco Role newRoleSet 014.gif

Until the query set resource is referred, we have just to select the query describing the role. In the example this query is named "isAbstract".

MoDisco Role newRoleSet 015.gif

At this step, if we save the model, the "red cross" should disappear from the file icon. This mean that the role set model is valid.

MoDisco Role newRoleSet 016.gif

If the role has specific attributes or references which can be calculated, we can declare them. In this example, we will declare an attribute indicating the number of abstract method contained in the abstract class. To create a new role attribute right-click on the role element and select the "New > New Child > RoleAttribute" button.

MoDisco Role newRoleSet 017.gif

The attribute's type and name must be set. The "Value Query" field must be field with a reference to a query which is able to calculate the attribute's value. This query must have the same type than the attribute and be applicable to the virtually extended class.

MoDisco Role newRoleSet 018.gif

The role set is now ready to be used.

How to consult the MoDisco role set catalog trough the UI


To get this view select "Windows > Show view > Other ..." in the menu bar and chose "Role Set" in the list.

MoDisco Role newRoleSet 019.gif File:MoDisco Role newRoleSet 020.gif

The "Role set" view presents the available role sets and them roles. For each role set the description model location is point out.

MoDisco Role newRoleSet 021.gif

How to programmatically use the MoDisco role set catalog.

Here a MoDisco role API example is provided. To have more informations please refer to the JavaDoc.

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmt.modisco.infra.query.core.exception.ModelQueryException;
import org.eclipse.gmt.modisco.infra.role.Role;
import org.eclipse.gmt.modisco.infra.role.RoleSet;
import org.eclipse.gmt.modisco.infra.role.core.RoleContext;
import org.eclipse.gmt.modisco.infra.role.core.RoleSetCatalog;
import org.eclipse.gmt.modisco.infra.role.core.exception.ModiscoRoleException;

public class Example {

	public Integer getNbAbstractMethod(EObject eObject)
			throws ModelQueryException, ModiscoRoleException {
		RoleContext context = new RoleContext();
		Role role = roleSet.getRole("AbstractClassDeclaration");
		if (context.isInstance(eObject, role)) {
			Object object = context.get(eObject, role
			if (object instanceof Integer) {
				Integer nbAbstractMethod = (Integer) object;
				return nbAbstractMethod;
		return null;

Role Meta-model Description

MoDisco Role metamodel.png

The role meta-model extends the ecore meta-model and use the query meta-model.

A roleSet is a kind of ePackage. A roleSet contains roles through the eClassifier reference. A role is a kind of eClass.


The role class has one specific reference: conditionQuery. The conditionQuery reference points the ModelQuery class. The model queries pointed by the conditionQuery reference must return a Boolean. Those queries are used to specify how to decide if an instance is conform to a role. If the conditionQuery is empty all the instances of the class referred by role instance trough the eSuperType reference, are conform to the role.

A role contains roleAttributes and roleReferences through the eStructuralFeature reference. The RoleAttribute and RoleReference classes have a common super class: RoleStructuralFeature. The RoleStructuralFeature has one reference named valueQuery and pointing to the ModelQuery class. The valueQuery is used to compute the role structural feature value. The roleAttribute and roleReference must have the same type than the query they refer.