Since Papyrus 3.0 (Eclipse Oxygen), Papyrus provides the Expressions Framework.
This framework provides one basis interface IExpression<CONTEXT_TYPE, RETURN_TYPE>
. This interface provides the method evaluate(CONTEXT_TYPE):RETURN_TYPE
.
This framework has been developed to be hightly extensible, in order to be able to evaluate all object kinds and returning all possible values. This extensibility requires for the developer to extends the basic IExpression in its framework.
The expressions can be grouped in an ExpressionCatalog
, in order to provide predefined expressions to the user.
Each expression must have a name and can have a description.
The Expressions have initially been developed for Papyrus Matrices Table. Developing the matrices, we need to provide a way to easily filter the rows and the columns to show. That's the reason for which the first expressions available in Papyrus are the boolean expressions to evaluate EObject.
true
true
false
(to avoid to have one icon by feature)
true
(we no idea about the real need of this feature)
true
, to get creation menu coming from the other models extending expressions
true
false
, excepted for the Expressions EPackage itself
false
, excepted for the Expressions EPackage itself
After this configuration, we generate the java code for the model, in order to get the EMF edit plugins for each expression model, and the editor. This last one is mandatory only for the basis of the expression framework. The extension, like UML Expressions, doesn't require it.
We completed the generated code declaring a custom factory for the package to implement the evaluate
methods for each expression. In the future, we probably look for including the body of the method in the UML model, using the OCL language.
We declare our own ResourceFactory and Resource, in order to control the format options for all editors able to manage an EMF resource. By this way, we ensure that the format of the files never changes regardless the used EMF editor. Our new files are: org.eclipse.papyrus.infra.emf.expressions.util.custom.ExpressionsResourceFactory and org.eclipse.papyrus.infra.emf.expressions.util.custom.ExpressionsResource.
The options currenlty set for the format are:
Map<Object, Object> options = super.getDefaultSaveOptions();
// idem in Papyrus ModelSet
options.put(XMLResource.OPTION_URI_HANDLER, new URIHandlerImpl.PlatformSchemeAware());
// idem in MultiDiagramUtil
options.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
options.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
// formating option about the size of the line in the file
// options.put(XMLResource.OPTION_LINE_WIDTH, 10);
options.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED);
We registered the
ExpressionsResourceFactory throw the extension point org.eclipse.emf.ecore.extension_parser
.
We commented a part of the generated code to avoid to get an NPE at runtime. In the method org.eclipse.papyrus.infra.emf.expressions.booleanexpressionspackage.impl.EObjectBooleanExpressionsPackageImpl.createUMLAnnotations
, the second call to addAnnotation
is trying to add an annotation on the null
.
The plugins available in Papyrus for the user:
In addition, we have a toolsmiths plugin:
IsStereotypedWithExpression
required to manipulate a given profile.Your expression catalog file should have the expression extension. You must register it using the extension point called org.eclipse.papyrus.infra.emf.expressions.expressionCatalog.
Installaing the Papyrus Toolsmiths feature, you get an Expressions Generator. This one is able to generate all expressions IsStereotypedWithExpression to test application of your stereotypes defined in your profile.
You must call the method org.eclipse.papyrus.infra.emf.expressions.catalog.ExpressionCatalogRegistry.getAllRegisteredCatalog()
.