Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "MDT-OCLTools"

(Features supported)
(Features supported)
Line 112: Line 112:
 
==== Syntax highlighting ====  
 
==== Syntax highlighting ====  
  
<ul>
+
==== AutoEdit 1 ====
  <li>Syntax highlighting</li>
+
  <li>AutoEdit 1: Auto-completion of closing brace</li>
+
  <li>AutoEdit 2: Upon typing a colon <code>:</code> and pressing Enter. A new indented line will be added, letting the
+
  
cursor ready for typing the body of the OCL expression.</li>
+
Auto-completion of closing brace
  <li>Bracket matching</li>
+
 
  <li>Content Assist<br/>[Image content_assist.png]
+
==== AutoEdit 2 ====
</li>
+
 
  <li>Current line highlighting and Show range indicator</li>
+
Upon typing a colon <code>:</code> and pressing Enter. A new indented line will be added, letting the
  <li>Text Folding</li>
+
cursor ready for typing the body of the OCL expression.
  <li>Templates, customizable through Preference pages
+
 
 +
==== Bracket matching ====
 +
 
 +
==== Content Assist ====
 +
 
 +
[Image content_assist.png]
 +
 
 +
==== Current line highlighting and Show range indicator ====
 +
 
 +
==== Text Folding ====
 +
 
 +
==== Templates, customizable through Preference pages ====
  
 
[[Image:OCLTools_editor_preference_page.png]]
 
[[Image:OCLTools_editor_preference_page.png]]
</li>
+
 
<li>Problem and Warning markers, "red squigglies"<br/>
+
 
 +
==== Problem and Warning markers, "red squigglies" ====
 +
 
 
[[Image:OCLTools_problem_markers.png]]
 
[[Image:OCLTools_problem_markers.png]]
</li>
 
<li>Outline view</li>
 
<li>OCL AST View <br/>
 
[[Image:OCLTools_oclASTView.png]]
 
</li>
 
  
</ul>
+
 
 +
==== Outline view ====
 +
 
 +
==== OCL AST View ====
 +
 
 +
[[Image:OCLTools_oclASTView.png]]

Revision as of 10:40, 2 November 2007

What's inside

OCL Tools is a recently added component to the Model Development Tools (MDT) Project aiming at providing first-class support to modelers working with specifications containing expressions written in OCL, the Object Constraint Language. Such support includes editing, refactoring, code generation, execution, and interactive debugging of the OCL constraints given for some underlying (Ecore or UML2) class model. The functionality of OCL Tools builds upon the MDT OCL component, and has been seeded with two initial contributions:

  • an OCL -> Java compiler, that as of now takes as input an .ecore and a textual file containing OCL constraints (handling UML2 is in the ToDo list). This compiler extends EMF code generation, producing Java 5 source code with side-effects-free methods for the given OCL invariants, pre- and postconditions, and derived attributes and operations.
  • an OCL text editor, supporting usability features such as AutoCompletion, navigation by means of hyperlinks, structured views (for the outline of a document and for the Abstract Syntax Tree of an OCL constraint), among others. Although MDT OCL itself is completely fluent in both Ecore and UML2, only the Ecore binding is supported by the OCL text editor at this time.

A longer intro to OCL Tools can be found in the draft article being reviewed for publication at: https://bugs.eclipse.org/bugs/show_bug.cgi?id=204701


OCL Compiler

What it does

In a nutshell, the compiler translates expressions like that in Listing 1 into what is shown in Listing 2:

context LoyaltyAccount
	inv invariant_points :
		self . points > 0
		implies self.transactions->exists ( t | t.points > 0 )
Listing 1 An OCL Invariant
public boolean invariant_points () {
	Boolean implies1 = ( this . getPoints () > 0);
	if (!( implies1 )) {
		implies1 = Boolean . TRUE ;
	} else {
		Boolean exists2 = false ;
		for ( RandL . Transaction t :
		org.eclipse.ocl.util.CollectionUtil.asSet ( this . getTransactions ())) {
				if (!exists2 ) {
					exists2 = (t.getPoints () > 0);
				}
		}
		implies1 = exists2 ;
	}
	return implies1 ;
}
Listing 2 LoyaltyAccount's invariant_points translated into Java



How to use it

Step 1: Prepare an .ocl file

Figure 1(a) Start situation


Step 2: Invoke the compiler

Figure 1(b) Invoking the compiler by right-clicking on the .ecore file

The compiler works ...

Figure 1(c) The compiler works ...

Step 3: Java code is ready

Figure 1(d) End result

OCL Text Editor

The big picture of the editor is:

OCLTools oclEditor screenshots.png

Features supported

Among others, it supports the following:

Syntax highlighting

AutoEdit 1

Auto-completion of closing brace

AutoEdit 2

Upon typing a colon : and pressing Enter. A new indented line will be added, letting the cursor ready for typing the body of the OCL expression.

Bracket matching

Content Assist

[Image content_assist.png]

Current line highlighting and Show range indicator

Text Folding

Templates, customizable through Preference pages

File:OCLTools editor preference page.png


Problem and Warning markers, "red squigglies"

OCLTools problem markers.png


Outline view

OCL AST View

OCLTools oclASTView.png

Back to the top