Tutorial - Your first steps
Note that the OCLEditor is currently in Alpha status - so not all features are 100% properly working and also more features will be added in coming releases.
Step 1: Create a new Java project
  1. Start your own Eclipse.
  2. Start the "New project" wizard (File -> New -> Project...).
  3. Select "Java project" and press "Next".
  4. Specify the project name (e.g. "testOcl").
  5. You can use the standard settings by pressing "Finish".
Step 2: Create the Java model
  1. Start the "New class" wizard by right-clicking your created project and then select "New" -> "Class" in the context menu.
  2. Enter "Person" in the field "Name" and "org.test" in the field "Package".

  3. Note: You have to specify a package name. Otherwise the Alpha version of the OCL editor will not work correctly.
  4. Create some fields (e.g. "private int age;" and "private String name;").
  5. Create Getter/Setter methods. For this right-click in the editor and select "Source" -> "Generate Getters and Setters...".


  6. dddddd
Step 3: Specify your first OCL constraint
  1. Right click the method "setAge(int)" in the Content Outline View on the right side of the screen and select "OCL Pre-/Post-Condition" in the appearing context menu.
    As you can see, a new file with the same name as the Java file and the extension ".ocl" was created and also some code in the OCL file was generated automatically.
  2. Now you can specify your first OCL contract, e.g. for the method "setAge" by replacing "true" with "age > 0 and age < 99".


Step 4: Test the OCL parser
  1. First you have to enable the OCL parser by opening the "Settings" dialog for your project. There select the page "OCL Editor" and enable "Perform parsing of OCL files".
  2. Start the OCL parser. E.g. "Project" -> "Rebuild All".
    If your OCL file contains errors then they will be shown with problem markers.


Forward pointers
  • Quick navigation between Java code and OCL constraints is possible with the context menu in the Content Outline view. Also the other way.
  • Various operations are possible with the context in the Content Outline View of the OCL Editor.
  • Also a wizard for creating OCL files exists (File -> New -> Other.. -> Java -> OCL File).