Using code templates (Professional Edition only)

In this section you will use content assist to fill in a template for a common code structure. Open testlib.oclx file in the OCL editor if you do not already have it open.

  1. With the cursor at the end of the testlib.oclx file (but before the endlibrary token) in the OCL editor, press press Ctrl+Space to enable content assist. You will see a list of OCL Library elements. When you single-click a template, or select it with the Up or Down arrow keys, you'll see the code for the template in its help message.

    Content assist for OCL Library elements

  2. Choose the Tests - Template entry and press Enter to confirm the template. The template will be inserted in your source code.

    Inserted OCL Tests template

  3. Next we change the visibility kind of the tests from public to protected. To do so simply choose the proteced entry and press Enter. Observe that the visibility kind of the tests is replaced and the cursor is moved to the next variable of the code template. This is the name of the tests test_name.

    Altered OCL Tests template

  4. Since we don't want to change the name (it was guessed right by the template) we press the tab key, which moves the cursor to the next variable of the code template. This is the type of the result variable type.

    Altered OCL Tests template

  5. Change the type of the result variable from type to Integer and press the tab key to move the cursor to the next variable of the code template.

    Altered OCL Tests template

  6. Complete the test as follows:

    protected tests
    model models.new_file.uml
      test test_name:
        let result:Integer = getClassByName('C2').numberOfAttributes()
        expected result = 1
    endtests

  7. Save the file.

Related concepts

OCL editor
Templates

Related reference

Templates Preferences
OCL Editor Preferences