How to access operation parameters in OCL [message #49139] |
Sun, 20 January 2008 10:52 |
Eclipse User |
|
|
|
Originally posted by: maiera.de.ibm.com
Suppose I have a class C1 that owns a property DesiredSpeed and an
operation SetSpeed() which has one parameter NewSpeed.
I would like to write a (model level) OCL postcondition which expresses
that the value of the DesiredSpeed property shall be the value of the
NewSpeed parameter.
I did not find anything in the OCL spec that specifies how to access the
NewSpeed parameter from within the context of the constraint (which is
the context of the instance of class C1 the method is invoked on).
My rough guess for the OCL is as follows:
post: self.DesiredSpeed = self.SetSpeed.NewSpeed
but Eclipse OCL does not seem to support that.
1. What is the correct OCL to access operation parameters ?
2. Where in the OCL spec is that described ?
Andy
|
|
|
Re: How to access operation parameters in OCL [message #49309 is a reply to message #49139] |
Mon, 21 January 2008 14:24 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Andy,
Parameters of the operation are manifest as variables in the context of OCL
pre/post conditions.
1. The names of the parameters are accessible directly as variables in the
context of your OCL constraint. Try this:
context C1::SetSpeed(NewSpeed : Speed)
post: self.DesiredSpeed = NewSpeed
Note that, using the concrete syntax for context declarations, you can
actually alias the parameters (use different names than what are specified
in the model) because the operation is matched by its signature of
parameter types. I'm not entirely sure that this is in keeping with the
spec. In any case, when embedding your constraint in a model using the
Operation::postCondition property, the parameter names defined by the model
are available in your OCL constraint.
2. See Section 7.3.4 for a discussion of pre- and post-conditions, and
Section 12.2.1 describing the ExpressionInOcl metaclass's ownership of the
variables corresponding to operation parameters.
Cheers,
Christian
Andreas Maier wrote:
> Suppose I have a class C1 that owns a property DesiredSpeed and an
> operation SetSpeed() which has one parameter NewSpeed.
>
> I would like to write a (model level) OCL postcondition which expresses
> that the value of the DesiredSpeed property shall be the value of the
> NewSpeed parameter.
>
> I did not find anything in the OCL spec that specifies how to access the
> NewSpeed parameter from within the context of the constraint (which is
> the context of the instance of class C1 the method is invoked on).
>
> My rough guess for the OCL is as follows:
>
> post: self.DesiredSpeed = self.SetSpeed.NewSpeed
>
> but Eclipse OCL does not seem to support that.
>
> 1. What is the correct OCL to access operation parameters ?
>
> 2. Where in the OCL spec is that described ?
>
> Andy
|
|
|
Powered by
FUDForum. Page generated in 0.02625 seconds