Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Retrieve literals from enum
Retrieve literals from enum [message #666451] Wed, 20 April 2011 13:44 Go to next message
Joern is currently offline JoernFriend
Messages: 22
Registered: March 2010
Junior Member
Hi,

How do I retrieve all literals from an enum?

Until Indigo it has been possible to use something like MyEnum.allInstances(). This does not evaluate in Indigo (Interactive Xtext OCL Console).

Thanks in advance & best regards

Joern
Re: Retrieve literals from enum [message #666454 is a reply to message #666451] Wed, 20 April 2011 13:52 Go to previous messageGo to next message
Axel Uhl is currently offline Axel UhlFriend
Messages: 41
Registered: July 2009
Member
Joern,

I tried an allInstances() on an enum in the standard console, using OCLEcore.ecore as my test model:

Evaluating:
ocl::expressions::CollectionKind.allInstances()
Results:
OrderedSet = 1
Collection = 4
Set = 0
Bag = 2
Sequence = 3

I suppose the problem is somewhere within the new Pivot evaluator used by the new Xtext console.
Re: Retrieve literals from enum [message #666462 is a reply to message #666454] Wed, 20 April 2011 14:08 Go to previous messageGo to next message
Joern is currently offline JoernFriend
Messages: 22
Registered: March 2010
Junior Member
Axel,

Thanks for your quick reply.

Unfortunately the model validation shows the same behaviour so the models do not validate any more. Are there any alternatives?

Best regards,

Joern
Re: Retrieve literals from enum [message #666466 is a reply to message #666451] Wed, 20 April 2011 13:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Joern

I thought I'd fixed this just after M6, but the JUnit still has the
Enumeration test commented out with a FIXME.

I'm just about to commit some major fixes for the editor
resynchronization after errors have been fixed, then I'll have a look.

Regards

Ed Willink

On 20/04/2011 14:44, Joern wrote:
> Hi,
>
> How do I retrieve all literals from an enum?
> Until Indigo it has been possible to use something like
> MyEnum.allInstances(). This does not evaluate in Indigo (Interactive
> Xtext OCL Console).
>
> Thanks in advance & best regards
>
> Joern
Re: Retrieve literals from enum [message #666475 is a reply to message #666462] Wed, 20 April 2011 14:35 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Joern

I guess that the true reflection might work. Try

AN_ENUM_LITERAL.oclType().ownedLiteral

or perhaps

AN_ENUM_LITERAL.oclType().oclAsType(Enumeration).ownedLitera l

no promises. I'll add the above to my test cases.

The underlying problem is that the specification has never defined type
expressions clearly; '4.oclAsType(Real)' is not syntactically valid!
Implementations have always been pragmatic. The new evaluator is too,
and the pragmatism falls over on a couple of FIXMEs. allInstances() is
unusual in that it is a dynamic static operation; static in that it
applies to a class, dynamic in that it varies for derived classes.
Modeling this as the pivot model does requires extra clarity that may
eventually make it into the specification.

Should be fixed in M7.

Regards

Ed Willink

On 20/04/2011 15:08, Joern wrote:
> Axel,
>
> Thanks for your quick reply.
> Unfortunately the model validation shows the same behaviour so the
> models do not validate any more. Are there any alternatives?
>
> Best regards,
>
> Joern
Re: Retrieve literals from enum [message #666496 is a reply to message #666475] Wed, 20 April 2011 15:20 Go to previous messageGo to next message
Joern is currently offline JoernFriend
Messages: 22
Registered: March 2010
Junior Member
Hi Ed,

Thanks for the answer.

I tried your proposals - but the operation oclType() seems not to exist. Neither Enum::Literal.oclType() nor Enum.oclType() does evaluate.

In the spec I only found a refernce to "OclType" as "the singleton instance of TypeType" ...

But another workaround would be welcome Smile

Best regards,

Joern
Re: Retrieve literals from enum [message #666989 is a reply to message #666496] Mon, 25 April 2011 11:38 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I've no idea why oclType() does not exist. You'll have to provide
detailed information on versions and files. AFAIK oclType() exists in
all Eclipse OCL versions but with rather suspect utility in most.

I've just committed changes that resolve a pleasing number of FIXMEs in
regard to TypeValues by introducing a templated Classifier<T> so that
the known type is propagated as e.g. Classifier<CollectionKind>. This
gets rid of most of the pragmatic code; both oclType() and
allInstances() are now model rather than manually-defined.

As a result both of

CollectionKind.allInstances()
CollectionKind.ownedLiteral

now return

Set{CollectionKind::Bag,CollectionKind::Collection,Collectio nKind::OrderedSet,CollectionKind::Sequence,CollectionKind::S et}

An N-build for this is available from
https://hudson.eclipse.org/hudson/job/buckminster-mdt-ocl-co re-3.1-nightly/lastSuccessfulBuild/artifact/MDT-OCL.download s/
(It needs a moderately recent Xtext N-build too.)

Regards

Ed Willink



On 20/04/2011 16:20, Joern wrote:
> Hi Ed,
>
> Thanks for the answer.
>
> I tried your proposals - but the operation oclType() seems not to
> exist. Neither Enum::Literal.oclType() nor Enum.oclType() does evaluate.
>
> In the spec I only found a refernce to "OclType" as "the singleton
> instance of TypeType" ...
>
> But another workaround would be welcome :)
>
> Best regards,
>
> Joern
Previous Topic:Parsing expressions without context
Next Topic:Activating container() support in OCL*Delegates and OCLConsole
Goto Forum:
  


Current Time: Fri Apr 26 17:34:51 GMT 2024

Powered by FUDForum. Page generated in 0.03437 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top