Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Adding New function on Collection type(Adding New function on Collection type)
Adding New function on Collection type [message #662845] Fri, 01 April 2011 08:27 Go to next message
Manu  is currently offline Manu Friend
Messages: 7
Registered: November 2009
Junior Member
I am trying to add a new function on collection type.I have defined the function in my environment and passed it to
addHelperOperation(). I have also added
annotation.getDetails().put("keywords", "iterator");
so that it will be treated as an iterator function. But the parser is not able to recognize this as a iterator function and considering this as a normal operation.
Hence the expression "self.books->forMax( copies > 3)" is parsed to "self.books->null(OclInvalid.>(3))". for the "org.eclipse.emf.examples.extlibrary.EXTLibraryPackage" example.
Can some one tell me other than defining the operation on getOCLStandardLibrary().getCollection() and adding iterator as key word on the annotation what else I need to do to so that parser will parse this correctly.
Re: Adding New function on Collection type [message #662871 is a reply to message #662845] Fri, 01 April 2011 09:33 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4154
Registered: July 2009
Senior Member
Hi Manu

It's really hard with the old code. I think there are about 9 places
that you need to modify, including the grammar since iterators were
reserved words and so very built-in.

If you really want to do it, search *.java, *.ecore, *.g, *.gi for
'forAll' and 'FORALL' to find all the locations to change, then load the
org.eclipse.mdt/org.eclipse.ocl/releng/psfs/parser-tools.psf so that you
have the 'LPG2 selected-file' external launch available to rebuild the
grammar.

The new code in the Indigo M6 Examples has a modelled library so that
you can use your own extended library. The declaration for forAll in
OCL2-4.oclstdlib is/may be:

type Collection<T> : CollectionType conformsTo OclAny {
....
iteration forAll(i : T | body : Lambda T() : Boolean) : Boolean =>
'org.eclipse.ocl.examples.library.iterator.ForAllIteration';
iteration forAll(i : T, j : T | body : Lambda T() : Boolean) :
Boolean => 'org.eclipse.ocl.examples.library.iterator.ForAllIteration';
....
}

which provides all the definitions required during parsing, analysis and
evaluation dispatch in one modeled modifiable place.

'Lambda T() : Boolean' is a lambda type that declares the iterator body
as a parameterless operation on T returning a Boolean.

'org.eclipse.ocl.examples.library.iterator.ForAllIteration' is the name
of a Java class implementing CallableImplementation.evaluate(...).

In principle you could just:

---
import 'OCL2-4.oclstdlib';
library ocl : ocl = 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib'
{
type Collection<T> {
iteration forMax(...) : ... => '...';
}
---
and use TypeManager.setDefaultStandardLibraryURI(String
defaultStandardLibraryURI)
to use your custom 'standard' library.

Library import and 'merge' is one of my active debugging activities, so
I can't promise that it works today, hopefully M7.
Today you would need to clone OCL2-4.oclstdlib.

Regards

Ed Willink


On 01/04/2011 09:27, Manu wrote:
> I am trying to add a new function on collection type.I have defined
> the function in my environment and passed it to addHelperOperation().
> I have also added annotation.getDetails().put("keywords", "iterator");
> so that it will be treated as an iterator function. But the parser is
> not able to recognize this as a iterator function and considering this
> as a normal operation.
> Hence the expression "self.books->forMax( copies > 3)" is parsed to
> "self.books->null(OclInvalid.>(3))". for the
> "org.eclipse.emf.examples.extlibrary.EXTLibraryPackage" example.
> Can some one tell me other than defining the operation on
> getOCLStandardLibrary().getCollection() and adding iterator as key
> word on the annotation what else I need to do to so that parser will
> parse this correctly.
Previous Topic:Helios OCL Console / CompleteOCL Editor against workspace metamodels
Next Topic:Annotated OCL in Ecore model not working in Helios
Goto Forum:
  


Current Time: Fri Nov 28 06:10:15 GMT 2014

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

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