Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How to use EType "Sequence"
How to use EType "Sequence" [message #633955] Tue, 19 October 2010 23:37 Go to next message
hutzu  is currently offline hutzu
Messages: 15
Registered: September 2010
Junior Member
I design a stack.ecore and stack.ocl.
stack.ocl showing~
context Stack:: Stack():
post: stack = Sequence{}

context Stack::push(element: Integer):
post: stack = stack@pre->prepend(element)

context Stack::pop():
pre: stack@pre->size() > 0
post: stack = stack@pre->
subSequence(2, stack@pre->size())

context Stack::peek(): Integer
pre: stack@pre->size() > 0
post: result = stack@pre->first()

context Stack::size(): Integer
post: result = stack@pre->size()

and then i want to finish stack.ecore
i suddenly found ecore has no EType "Sequence"
i look for Package org.eclipse.ocl.ecore
it reallys had "SequenceType"
or how to extend it. thanks a lot
hutzu
Re: How to use EType "Sequence" [message #634002 is a reply to message #633955] Wed, 20 October 2010 04:40 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi Hutzu

Your mail client seems to have inserted a 'mailto:' on all the '@pre'.

You haven't provided the stack.ecore, ansd your stack.ocl seems to be
only a subexample.

The following give me no trouble.

stack.ecore
----------------

package hutzu : stk = 'stk'
{
class Stack
{
attribute stack : Integer[*] { !unique };
operation Stack() : Stack;
operation peek() : Integer;
operation pop() : Integer;
operation push(element : Integer) :;
operation size() : Integer;
}
}

stack.ocl
--------------

import 'stack.ecore'

package hutzu

context Stack:: Stack():
post: stack = Sequence{}

context Stack::push(element: Integer):
post: stack = stack@pre->prepend(element)

context Stack::pop():
pre: stack@pre->size() > 0
post: stack = stack@pre->
subSequence(2, stack@pre->size())

context Stack::peek(): Integer
pre: stack@pre->size() > 0
post: result = stack@pre->first()

context Stack::size(): Integer
post: result = stack@pre->size()

endpackage

------

I can only guess that you didn't declare stack as a Sequence in your ecore.

SequeceType is the EClass of Sequwence. Sequence is a built-in library
class used
for ordered, !unique, upperBound > 1 multiplicities.

You might find ->notEmpty() more readable thatn ->size() > 0.

(Remove the "import 'stack.ecore'" when using the parser via the Java API.)

Regards

Ed Willink


On 20/10/2010 04:37, hutzu wrote:
> I design a stack.ecore and stack.ocl.
> stack.ocl showing~
> context Stack:: Stack():
> post: stack = Sequence{}
>
> context Stack::push(element: Integer):
> post: stack = mailto:stack@pre->prepend(element)
>
> context Stack::pop():
> pre: mailto:stack@pre->size() > 0
> post: stack = mailto:stack@pre->
> subSequence(2, mailto:stack@pre->size())
>
> context Stack::peek(): Integer
> pre: mailto:stack@pre->size() > 0
> post: result = mailto:stack@pre->first()
>
> context Stack::size(): Integer
> post: result = mailto:stack@pre->size()
>
> and then i want to finish stack.ecore
> i suddenly found ecore has no EType "Sequence"
> i look for Package org.eclipse.ocl.ecore it reallys had
> "SequenceType"
> or how to extend it. thanks a lot
> hutzu
Previous Topic:[OCL-ECORE-JAVA] OCL Queries on Ecore model from Java code.
Next Topic:OCL XOR link constraint
Goto Forum:
  


Current Time: Fri Jul 25 10:01:34 EDT 2014

Powered by FUDForum. Page generated in 0.02563 seconds