Visual OCL

TU-Berlin | Faculty IV | Institute ISTI | Research group TFS

User Guide for the Eclipse VOCL-Plugin
group 2

small logo
section: < previous | next >
| |
chapter: << previous | next >>

2.1 Creating a Constraint


A VOCL-Constraint consists of a header and a body which contains the actual VOCL expression. The header contains information about the context, the Constraint's kind, the Constraint's name and an optional variable declaration. The context itself can be a classifier (for invariant or a definition) or a method (for pre -and post conditions).
The Constraint is the top-level element of a VOCL-Expression, that means that it includes all other elements such as navigation, bool, let-in and it-then-else expressions. For creating such a figure you have to execute the following steps:
  1. Click on the entry Constraint in the palette.
  2. Move the mouse cursor on the drawing area at this position the figure should appear.
  3. Click on the left button (the mouse position is left corner of the figure) and a dialog is opened (see Fig 2.1.1).

In the next two subsections the creation of a Constraint with a Classifier as the context on the one hand and with a method declaration on the other hand.

2.1.1 Creating an invariant


After you have followed the steps from above you see the dialog in Fig 2.1.1. In this dialog you enter the values below:

  1. in the name textfield you can enter a optional name for the constraint (here: Company-Constraint)
  2. in the combobox you can choose between three different kinds for the Constraint (here: inv)
  3. then you have to specify the context of the Constraint, i.e. the class which the Constraint is associated with
    1. you have to specify at least the type of the context (here: Company)
    2. after that you can add a name for the context (here: c)

Fig. 2.1.1 - Constraint dialog


Then you can click on Okay and the figure will be drawn. Moreover the inputs are checked and if some inputs are not there an inforamtion dialog is opened and you must fill the missing entries.
In Fig. 2.1.2 you can see the Constraint of the settings from above. The Constraint is a rounded rectangle with a header, in which the settings of the dialog appear, and the body which contains the VOCL expression.


Fig. 2.1.2 - resulting Constraint with a Classifiier as the context

2.1.2 Creating a Constraint with a method as the context


In the previous subsection you have learnt how to create a Constraint with a Classifier as the context. Now we present the other case, namely a Constraint with a method as the context. To do this follow the next steps (see Fig. 2.1.3):
  1. Follow the steps from the introduction of this section.
  2. Enter a name for the Constraint (here: Company-Constraint-2)
  3. Select a kind for the Constraint (here: pre)
  4. Enter the method name, parameters and return type in the textfield context:type such as follow:
    1. Enter the name of the Classifier the Constraint is associated with (here: Company)  followed by "::"
    2. Enter the name of the method (here: getProfitPerYear)
    3. Enter the parameters (name and type divided by a ":") of the method in brackets (here: (year:Integer))
    4. At last enter the return type of the method
The resulting string should look like this  Company::getProfitPerYear( year: Integer) : Integer
         


Fig. 2.1.3 - constraint dialog with method

In Fig 2.1.4 the resulting Constraint can be seen. The method string of the dialog is not be checked yet. This will follow in a next version of the editor.


Fig. 2.1.4 - resulting Constraint
©2005 TFS