Gustaf
Gustaf

Reputation: 147

OCL at0 operator syntax error

Working on a timereport project in MDriven and I have created an instance where an employee has worked ten hours. The Employee class's "attribute.type" is of "timespan" for "HoursWorked".

action:
Employee.create
Employee.allinstances->at0(0) .HoursWorked:= 10:00:00

This code gives me a syntax error. Is the at0 not functioning with "timespan"? If so, which expression should be used in this case to create a certain timespan?

Also, if anyone knows a good, informative wiki with all the OCL expressions and how to correctly write syntax that would be much aprreciated.

Upvotes: 3

Views: 78

Answers (2)

Hans Karlsen
Hans Karlsen

Reputation: 2435

The issue is that the MDriven action language (based on OCL but with side effects allowed) requires you to separate statements with ;

Try:

action:
Employee.create;  -- notice that semicolon
Employee.allinstances->at0(0).HoursWorked:= TimeSpan.Create(10,00,00)  --NO ; on end statement

Upvotes: 2

Ed Willink
Ed Willink

Reputation: 1498

This question is titled OCL and so the following answer applies:

There is no allinstances in OCL; it is allInstances().

There is no at0() in OCL; it is at() and since OCL is a specification language indexes are 1-based, so a 0 index is invalid.

The OCL expressions and library operations are available in the OMG specification or the online Eclipse help: http://help.eclipse.org/oxygen/topic/org.eclipse.ocl.doc/help/StandardLibrary.html?cp=74_2

However it is clear that you are actually using a non-standard OCL embedded presumably in MDriven, so answers applicable to OCL may not be relevant.

Upvotes: 1

Related Questions