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.
Right-click on the MoDisco project and select the "New > Other ..." button.

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

Choose a name for your model role set (My.roleSet in the example) and press "Next".

Select "RoleSet" in the "Model Object" list and press "Finish"


Open the "My.roleSet" file and open the "Properties View"

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.

Load the resources containing the meta-model extended by the role set. To load a meta-model resource the user must use the "Load meta-model resource" action.

In this example, we choose to use the Java meta-model.

Fill the "Extended package" field with the ePackages containing the virtually extended meta-model.

Right click on the RoleSet element and choose the "New Child > Role" action to create a role.

Set the role name and the class that the role will extend.

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.

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





The role set is now ready to be used.
If a role set model is valid, it is registered in the role set catalog. To consult the role set catalog, we can use the "Role Set" view.
To get this view select "Windows > Show view > Other ..." in the menu bar and chose "Role Set" in the list.


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

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 {
RoleSet roleSet = RoleSetCatalog.getSingleton().getRoleSet("My");
RoleContext context = new RoleContext();
context.addRoleSet(roleSet);
Role role = roleSet.getRole("AbstractClassDeclaration");
if (context.isInstance(eObject, role)) {
Object object = context.get(eObject, role
.getEStructuralFeature("nbAbstractMethod"));
if (object instanceof Integer) {
Integer nbAbstractMethod = (Integer) object;
return nbAbstractMethod;
}
}
return null;
}
}
All rights reserved. This document is made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
Contributors: