-
Notifications
You must be signed in to change notification settings - Fork 0
Constraints.md
This page describes two languages which can be used to write constraints in YAFMT. See constraints editor how to add constraints to feature model. See also how to extend YAFMT by adding new constraint language.
SamCL is a minimalistic constraint language which main purpose is to show how to use the cz.zcu.yafmt.clang extension point. It only allows 2 kinds of constraints:
-
A mute-with B
-A
andB
cannot be selected at the same time. -
A requires B
- Selection ofA
requiresB
to be also selected.
**Note: ** Feature is always referenced by its ID.
BoolCL is a constraint language based on rules of the Boolean algeabra. The following table shows list of operators and their example usage. The operators are sorted from the highest to the lowest prioryty.
Name | Example | Description |
---|---|---|
Identifier | A |
Evaluates to true when a feature which ID is A is present in the feature configuration. We shortly refer to this as: A must be selected. |
Negation | not A |
A must not be selected. |
Disjunction | A or B |
One of A or B must be selected. |
Conjunction | A and B |
Both A and B must be selected. |
Implication | A implies B |
When A is selected, B must be also selected. |
Equivalence | A equals B |
A must be selected exactly when B is selected and vice versa. |
You can use paranthenses to make more complicated expressions like this:
(A or B) and C
. There are also two kinds of contextual expressions which usage
we will show in the following example of a feature model:
We can see that the B
is cloneable so there can be more than one copy of B
in feature configuration. We want to make sure that D
is always present in
the configuration when C
is. We could simply write this as C implies D
, but such
expression is always evaluated in global scope. To limit scope of the evaluation,
we can use the following contextual expressions:
Example | Description |
---|---|
forall B: C implies D |
It is evaluated in context of each copy of B . Its result is true if evaluation for each copy of B was true . |
exists B: C implies D |
It is evaluated in context of each copy of B . Its result is true if at least one evaluation for copy of B was true . |
The next table shows results of evaluation of these expresions against the feature configurations below.
Expression | Evaluation Result for #1 | Evaluation Result for #2 | Evaluation Result for #3 |
---|---|---|---|
C implies D |
true |
true |
true |
exists B: C implies D |
false |
true |
true |
forall B: C implies D |
false |
false |
true |
New constraint language can be added by extending the cz.zcu.yafmt.clang
extension point:
<extension point="cz.zcu.yafmt.clang">
<language id="com.example.myclang"
name="My Constraint Language"
shortName="MyCL"
class="com.example.myclang.MyConstraintLanguage"/>
</extension>
Plug-ins that want to use this extension point must implement the
cz.zcu.yafmt.clang.IConstraintLanguage
interface or extend the
cz.zcu.yafmt.clang.ConstraintLanguage
abstract class. See
cz.zcu.yafmt.clang.sample
package from the cz.zcu.yafmt.clang
plug-in
(SamCL) for an example
implementation. You can also check the cz.zcu.yafmt.clang.bcl
plug-in
(BoolCL) for more
complex example.
Custom editor for an existing constrain language can be added by extending the
cz.zcu.yafmt.clang.ui
extension point:
<extension point="cz.zcu.yafmt.clang.ui">
<editingSupport languageId="com.example.myclang"
class="com.example.myclang.ui.MyConstraintLanguageEditingSupport"/>
</extension>
Plug-ins that want to use this extension point must implement the
cz.zcu.yafmt.clang.ui.IEditingSupport
interface or extend the
cz.zcu.yafmt.clang.ui.EditingSupport
abstract class. See the
cz.zcu.yafmt.clang.bcl.ui
plug-in (BoolCL
UI) for an example implementation.