Create a new facet set

How to create a model facet set

How to create a MoDisco project

The first step is to create a MoDisco project.

How to create a MoDisco query set

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

How to create a MoDisco facet set

Right-click on the MoDisco project and select the "New > Other ..." button.

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

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

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

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

Set the name of the facet set and take care that the facet 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 facet 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 FacetSet element and choose the "New Child > Facet" action to create a facet.

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

To specify how to know if an object is conform to a facet, 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.

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

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

If the facet 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 facet attribute right-click on the facet element and select the "New > New Child > FacetAttribute" button.

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.

The facet set is now ready to be used.

How to consult the MoDisco facet set catalog trough the UI

If a facet set model is valid, it is registered in the facet set catalog. To consult the facet set catalog, we can use the "Facet Set" view.

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

The "Facet set" view presents the available facet sets and them facets. For each facet set the description model location is point out.

How to programmatically use the MoDisco facet set catalog.

Here a MoDisco facet 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.facet.Facet;
import org.eclipse.gmt.modisco.infra.facet.FacetSet;
import org.eclipse.gmt.modisco.infra.facet.core.FacetContext;
import org.eclipse.gmt.modisco.infra.facet.core.FacetSetCatalog;
import org.eclipse.gmt.modisco.infra.facet.core.exception.ModiscoFacetException;

public class Example {

	public Integer getNbAbstractMethod(EObject eObject)
			throws ModelQueryException, ModiscoFacetException {
		FacetSet facetSet = FacetSetCatalog.getSingleton().getFacetSet("My");
		FacetContext context = new FacetContext();
		context.addFacetSet(facetSet);
		Facet facet = facetSet.getFacet("AbstractClassDeclaration");
		if (context.isInstance(eObject, facet)) {
			Object object = context.get(eObject, facet
					.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: