Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » custom operators and functions using model information
custom operators and functions using model information [message #482954] Fri, 28 August 2009 16:40 Go to next message
Elio Damaggio is currently offline Elio DamaggioFriend
Messages: 8
Registered: July 2009
Junior Member
Hi all,

I am modifying the OCL parser/evaluator in order to (besides other things):

* include a series of time related datatypes (Date, Time, Duration,
Timestamp). These datatypes should have standard infix operators (+, -,
...) like integers and so on... I think I have to modify the
EvaluationVisitor. Is this the best course of action?

* include predefined methods that, if applied on an attribute, have access
to the model information of that attribute (i.e. which class they belong,
in addition to the actual instance).
For instance, lets assume book have an attribute called author. And the
"LOTR" book instance has "Tolkien" as its author attribute. Then the
predefined method LOTR.author.info() should be able to know that it is
invoked on the "author" attribute of a "book" class.
Do you have any idea on how to implement these methods?

Thank you all,

Elio
Re: custom operators and functions using model information [message #483005 is a reply to message #482954] Sat, 29 August 2009 05:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Elio, Ed

[Ed: you may be able to provide a simple solution for b).]

a) parser modification

The parser is intended to be extended rather than modified. Be very wary
of modifying; you will have te re-engineer each time MDT-OCL improves.
That said we are in the process of migrating from LPG 1 to LPG 2,
https://bugs.eclipse.org/bugs/show_bug.cgi?id=242153, which will require
about four trivial edit procedures to existing extensions.

b) operators

In your Ecore model of custom data types (EClass not EDataType) you can
add operations such as "+", which you can then use them naturally in
OCL. Unfortunately these give a validation error in EMF so you cannot
genModel them.

I'm not sure if the situation is any better for a UML model.

This is a spelling problem I've been considering already: For OCL it
must be "+" for Java it must be perhaps "_plus". (OMG) OCL needs to
specify an encoding scheme for awkward characters and to specify a
concrete syntax access scheme. MDT-OCL supports access via double quotes
e.g:

def: "+"(d : Date) ...

I'm afraid I don't know of any solution to making Date + Date work today.

The XSD support for EMF provides a form of renaming. I've copied this to
Ed Merks who may be able to explain how it could be exploited.

c) call path

I'm not very familiar with the EvaluationEnvironment, so nearly all of
what I'm about to suggest may already be the current MDT-OCL functionality.

You can introduce a derived LOTREnvironment which is created at each
stage of evaluation, with a reference to its outer context. At any point
these references give you the call path. You can then add custom methods
to evaluate any function of the call path that you like. Perhaps you
encapsulate these all in a richer Environment object and implement just
a single .oclEnvironment() method to access it. If you get this working
it might make for a useful contribution to MDT-OCL and a submission for
a future OCL specification.

Regards

Ed Willink

Elio Damaggio wrote:
> Hi all,
>
> I am modifying the OCL parser/evaluator in order to (besides other things):
>
> * include a series of time related datatypes (Date, Time, Duration,
> Timestamp). These datatypes should have standard infix operators (+, -,
> ..) like integers and so on... I think I have to modify the
> EvaluationVisitor. Is this the best course of action?
>
> * include predefined methods that, if applied on an attribute, have
> access to the model information of that attribute (i.e. which class they
> belong, in addition to the actual instance).
> For instance, lets assume book have an attribute called author. And the
> "LOTR" book instance has "Tolkien" as its author attribute. Then the
> predefined method LOTR.author.info() should be able to know that it is
> invoked on the "author" attribute of a "book" class.
> Do you have any idea on how to implement these methods?
>
> Thank you all,
>
> Elio
>
Re: custom operators and functions using model information [message #483018 is a reply to message #483005] Sat, 29 August 2009 11:34 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Guys,

Comments below.


Ed Willink wrote:
> Hi Elio, Ed
>
> [Ed: you may be able to provide a simple solution for b).]
>
> a) parser modification
>
> The parser is intended to be extended rather than modified. Be very
> wary of modifying; you will have te re-engineer each time MDT-OCL
> improves. That said we are in the process of migrating from LPG 1 to
> LPG 2,
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=242153, which will
> require about four trivial edit procedures to existing extensions.
>
> b) operators
>
> In your Ecore model of custom data types (EClass not EDataType) you
> can add operations such as "+", which you can then use them naturally
> in OCL. Unfortunately these give a validation error in EMF so you
> cannot genModel them.
>
> I'm not sure if the situation is any better for a UML model.
>
> This is a spelling problem I've been considering already: For OCL it
> must be "+" for Java it must be perhaps "_plus". (OMG) OCL needs to
> specify an encoding scheme for awkward characters and to specify a
> concrete syntax access scheme. MDT-OCL supports access via double
> quotes e.g:
>
> def: "+"(d : Date) ...
>
> I'm afraid I don't know of any solution to making Date + Date work today.
>
> The XSD support for EMF provides a form of renaming. I've copied this
> to Ed Merks who may be able to explain how it could be exploited.
I'm not sure most of these types make sense to support addition. I
think it makes sense to add a duration to a time or a date, but not to
add two times or two dates. I imagine the support for such things would
be done in the same way one would support BigDecimal or BigInteger. I'm
not sure how OCL supports operators on custom EDataTypes or even if it
supports all the EDataTypes in XMLTypePackage; supporting all those
would provide support for all schema-based models...
>
> c) call path
>
> I'm not very familiar with the EvaluationEnvironment, so nearly all of
> what I'm about to suggest may already be the current MDT-OCL
> functionality.
>
> You can introduce a derived LOTREnvironment which is created at each
> stage of evaluation, with a reference to its outer context. At any
> point these references give you the call path. You can then add custom
> methods to evaluate any function of the call path that you like.
> Perhaps you encapsulate these all in a richer Environment object and
> implement just a single .oclEnvironment() method to access it. If you
> get this working it might make for a useful contribution to MDT-OCL
> and a submission for a future OCL specification.
>
> Regards
>
> Ed Willink
>
> Elio Damaggio wrote:
>> Hi all,
>>
>> I am modifying the OCL parser/evaluator in order to (besides other
>> things):
>>
>> * include a series of time related datatypes (Date, Time, Duration,
>> Timestamp). These datatypes should have standard infix operators (+,
>> -, ..) like integers and so on... I think I have to modify the
>> EvaluationVisitor. Is this the best course of action?
>>
>> * include predefined methods that, if applied on an attribute, have
>> access to the model information of that attribute (i.e. which class
>> they belong, in addition to the actual instance).
>> For instance, lets assume book have an attribute called author. And
>> the "LOTR" book instance has "Tolkien" as its author attribute. Then
>> the predefined method LOTR.author.info() should be able to know that
>> it is invoked on the "author" attribute of a "book" class.
>> Do you have any idea on how to implement these methods?
>>
>> Thank you all,
>>
>> Elio
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: custom operators and functions using model information [message #483183 is a reply to message #483005] Mon, 31 August 2009 13:51 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

--=-8MhLTci7kWwSwTQDlMnA
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Ed, Elio,

Yes, OCL is trained to look for Java names "plus", "minus", "lessThan",
"greaterThan", etc. to implement these symbolic operators, but it does
expect to find the symbolic names (e.g., "+", "<") in the model's
EClass. The "<" / "lessThan" operation is particularly handy because it
allows your type to be used in "orderedBy" iterators.

One of the callOperation() or some such methods in the
EvaluationEnvironment type hierarchy has the mapping from symbolic to
Java names, in looking up the Method objects to invoke reflectively. I
should, of course, have documented it in the SDK's developer guide,
too :-(

Cheers,

Christian


On Sat, 2009-08-29 at 06:52 +0100, Ed Willink wrote:

> Hi Elio, Ed
>
> [Ed: you may be able to provide a simple solution for b).]
>
> a) parser modification
>
> The parser is intended to be extended rather than modified. Be very wary
> of modifying; you will have te re-engineer each time MDT-OCL improves.
> That said we are in the process of migrating from LPG 1 to LPG 2,
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=242153, which will require
> about four trivial edit procedures to existing extensions.
>
> b) operators
>
> In your Ecore model of custom data types (EClass not EDataType) you can
> add operations such as "+", which you can then use them naturally in
> OCL. Unfortunately these give a validation error in EMF so you cannot
> genModel them.
>
> I'm not sure if the situation is any better for a UML model.
>
> This is a spelling problem I've been considering already: For OCL it
> must be "+" for Java it must be perhaps "_plus". (OMG) OCL needs to
> specify an encoding scheme for awkward characters and to specify a
> concrete syntax access scheme. MDT-OCL supports access via double quotes
> e.g:
>
> def: "+"(d : Date) ...
>
> I'm afraid I don't know of any solution to making Date + Date work today.
>
> The XSD support for EMF provides a form of renaming. I've copied this to
> Ed Merks who may be able to explain how it could be exploited.
>
> c) call path
>
> I'm not very familiar with the EvaluationEnvironment, so nearly all of
> what I'm about to suggest may already be the current MDT-OCL functionality.
>
> You can introduce a derived LOTREnvironment which is created at each
> stage of evaluation, with a reference to its outer context. At any point
> these references give you the call path. You can then add custom methods
> to evaluate any function of the call path that you like. Perhaps you
> encapsulate these all in a richer Environment object and implement just
> a single .oclEnvironment() method to access it. If you get this working
> it might make for a useful contribution to MDT-OCL and a submission for
> a future OCL specification.
>
> Regards
>
> Ed Willink
>
> Elio Damaggio wrote:
> > Hi all,
> >
> > I am modifying the OCL parser/evaluator in order to (besides other things):
> >
> > * include a series of time related datatypes (Date, Time, Duration,
> > Timestamp). These datatypes should have standard infix operators (+, -,
> > ..) like integers and so on... I think I have to modify the
> > EvaluationVisitor. Is this the best course of action?
> >
> > * include predefined methods that, if applied on an attribute, have
> > access to the model information of that attribute (i.e. which class they
> > belong, in addition to the actual instance).
> > For instance, lets assume book have an attribute called author. And the
> > "LOTR" book instance has "Tolkien" as its author attribute. Then the
> > predefined method LOTR.author.info() should be able to know that it is
> > invoked on the "author" attribute of a "book" class.
> > Do you have any idea on how to implement these methods?
> >
> > Thank you all,
> >
> > Elio
> >

--=-8MhLTci7kWwSwTQDlMnA
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Ed, Elio,<BR>
<BR>
Yes, OCL is trained to look for Java names &quot;plus&quot;, &quot;minus&quot;, &quot;lessThan&quot;, &quot;greaterThan&quot;, etc. to implement these symbolic operators, but it does expect to find the symbolic names (e.g., &quot;+&quot;, &quot;&lt;&quot;) in the model's EClass.&nbsp; The &quot;&lt;&quot; / &quot;lessThan&quot; operation is particularly handy because it allows your type to be used in &quot;orderedBy&quot; iterators.<BR>
<BR>
One of the callOperation() or some such methods in the EvaluationEnvironment type hierarchy has the mapping from symbolic to Java names, in looking up the Method objects to invoke reflectively.&nbsp; I should, of course, have documented it in the SDK's developer guide, too&nbsp; :-(<BR>
<BR>
Cheers,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Sat, 2009-08-29 at 06:52 +0100, Ed Willink wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hi Elio, Ed

[Ed: you may be able to provide a simple solution for b).]

a) parser modification

The parser is intended to be extended rather than modified. Be very wary
of modifying; you will have te re-engineer each time MDT-OCL improves.
That said we are in the process of migrating from LPG 1 to LPG 2,
<A HREF="https://bugs.eclipse.org/bugs/show_bug.cgi?id=242153">https://bugs.eclipse.org/bugs/show_bug.cgi?id=242153</A>, which will require
about four trivial edit procedures to existing extensions.

b) operators

In your Ecore model of custom data types (EClass not EDataType) you can
add operations such as &quot;+&quot;, which you can then use them naturally in
OCL. Unfortunately these give a validation error in EMF so you cannot
genModel them.

I'm not sure if the situation is any better for a UML model.

This is a spelling problem I've been considering already: For OCL it
must be &quot;+&quot; for Java it must be perhaps &quot;_plus&quot;. (OMG) OCL needs to
specify an encoding scheme for awkward characters and to specify a
concrete syntax access scheme. MDT-OCL supports access via double quotes
e.g:

def: &quot;+&quot;(d : Date) ...

I'm afraid I don't know of any solution to making Date + Date work today.

The XSD support for EMF provides a form of renaming. I've copied this to
Ed Merks who may be able to explain how it could be exploited.

c) call path

I'm not very familiar with the EvaluationEnvironment, so nearly all of
what I'm about to suggest may already be the current MDT-OCL functionality.

You can introduce a derived LOTREnvironment which is created at each
stage of evaluation, with a reference to its outer context. At any point
these references give you the call path. You can then add custom methods
to evaluate any function of the call path that you like. Perhaps you
encapsulate these all in a richer Environment object and implement just
a single .oclEnvironment() method to access it. If you get this working
it might make for a useful contribution to MDT-OCL and a submission for
a future OCL specification.

Regards

Ed Willink

Elio Damaggio wrote:
&gt; Hi all,
&gt;
&gt; I am modifying the OCL parser/evaluator in order to (besides other things):
&gt;
&gt; * include a series of time related datatypes (Date, Time, Duration,
&gt; Timestamp). These datatypes should have standard infix operators (+, -,
&gt; ..) like integers and so on... I think I have to modify the
&gt; EvaluationVisitor. Is this the best course of action?
&gt;
&gt; * include predefined methods that, if applied on an attribute, have
&gt; access to the model information of that attribute (i.e. which class they
&gt; belong, in addition to the actual instance).
&gt; For instance, lets assume book have an attribute called author. And the
&gt; &quot;LOTR&quot; book instance has &quot;Tolkien&quot; as its author attribute. Then the
&gt; predefined method LOTR.author.info() should be able to know that it is
&gt; invoked on the &quot;author&quot; attribute of a &quot;book&quot; class.
&gt; Do you have any idea on how to implement these methods?
&gt;
&gt; Thank you all,
&gt;
&gt; Elio
&gt;
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-8MhLTci7kWwSwTQDlMnA--
Re: custom operators and functions using model information [message #484261 is a reply to message #483183] Fri, 04 September 2009 21:59 Go to previous messageGo to next message
Elio Damaggio is currently offline Elio DamaggioFriend
Messages: 8
Registered: July 2009
Junior Member
Hi Christian,

I was able to have the operator work :)

How is the situation for unary operators?
Is there a way to define those for custom datatypes?
Thanks,

Elio


Christian W. Damus wrote:

> Hi, Ed, Elio,

> Yes, OCL is trained to look for Java names "plus", "minus", "lessThan",
> "greaterThan", etc. to implement these symbolic operators, but it does
> expect to find the symbolic names (e.g., "+", "<") in the model's
> EClass. The "<" / "lessThan" operation is particularly handy because it
> allows your type to be used in "orderedBy" iterators.

> One of the callOperation() or some such methods in the
> EvaluationEnvironment type hierarchy has the mapping from symbolic to
> Java names, in looking up the Method objects to invoke reflectively. I
> should, of course, have documented it in the SDK's developer guide,
> too :-(

> Cheers,

> Christian


> On Sat, 2009-08-29 at 06:52 +0100, Ed Willink wrote:

>> Hi Elio, Ed
>>
>> [Ed: you may be able to provide a simple solution for b).]
>>
>> a) parser modification
>>
>> The parser is intended to be extended rather than modified. Be very wary
>> of modifying; you will have te re-engineer each time MDT-OCL improves.
>> That said we are in the process of migrating from LPG 1 to LPG 2,
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=242153, which will require
>> about four trivial edit procedures to existing extensions.
>>
>> b) operators
>>
>> In your Ecore model of custom data types (EClass not EDataType) you can
>> add operations such as "+", which you can then use them naturally in
>> OCL. Unfortunately these give a validation error in EMF so you cannot
>> genModel them.
>>
>> I'm not sure if the situation is any better for a UML model.
>>
>> This is a spelling problem I've been considering already: For OCL it
>> must be "+" for Java it must be perhaps "_plus". (OMG) OCL needs to
>> specify an encoding scheme for awkward characters and to specify a
>> concrete syntax access scheme. MDT-OCL supports access via double quotes
>> e.g:
>>
>> def: "+"(d : Date) ...
>>
>> I'm afraid I don't know of any solution to making Date + Date work today.
>>
>> The XSD support for EMF provides a form of renaming. I've copied this to
>> Ed Merks who may be able to explain how it could be exploited.
>>
>> c) call path
>>
>> I'm not very familiar with the EvaluationEnvironment, so nearly all of
>> what I'm about to suggest may already be the current MDT-OCL functionality.
>>
>> You can introduce a derived LOTREnvironment which is created at each
>> stage of evaluation, with a reference to its outer context. At any point
>> these references give you the call path. You can then add custom methods
>> to evaluate any function of the call path that you like. Perhaps you
>> encapsulate these all in a richer Environment object and implement just
>> a single .oclEnvironment() method to access it. If you get this working
>> it might make for a useful contribution to MDT-OCL and a submission for
>> a future OCL specification.
>>
>> Regards
>>
>> Ed Willink
>>
>> Elio Damaggio wrote:
>> > Hi all,
>> >
>> > I am modifying the OCL parser/evaluator in order to (besides other
things):
>> >
>> > * include a series of time related datatypes (Date, Time, Duration,
>> > Timestamp). These datatypes should have standard infix operators (+, -,
>> > ..) like integers and so on... I think I have to modify the
>> > EvaluationVisitor. Is this the best course of action?
>> >
>> > * include predefined methods that, if applied on an attribute, have
>> > access to the model information of that attribute (i.e. which class they
>> > belong, in addition to the actual instance).
>> > For instance, lets assume book have an attribute called author. And the
>> > "LOTR" book instance has "Tolkien" as its author attribute. Then the
>> > predefined method LOTR.author.info() should be able to know that it is
>> > invoked on the "author" attribute of a "book" class.
>> > Do you have any idea on how to implement these methods?
>> >
>> > Thank you all,
>> >
>> > Elio
>> >
Re: custom operators and functions using model information [message #484271 is a reply to message #483183] Sat, 05 September 2009 07:32 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Christian, Elio
> One of the callOperation() or some such methods in the
> EvaluationEnvironment type hierarchy has the mapping from symbolic to
> Java names, in looking up the Method objects to invoke reflectively. I
> should, of course, have documented it in the SDK's developer guide, too :-(

It's in getJavaMethodFor.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=288694 raised to get this
useful facility consistently realised and backed up by an OMG Issue.

Regards

Ed Willink
Re: custom operators and functions using model information [message #485087 is a reply to message #484261] Thu, 10 September 2009 13:42 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

--=-rN+MwqQkJEDAtVtxrai5
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Elio,

The only unary operator currently recognized by OCL is "-" (possibly
"+", but I rather doubt that). For that, the getJavaMethodFor(...)
method will indicate the translation.

There is no facility for defining arbitrary infix operators in OCL. The
grammar fixes them quite strictly.

Cheers,

Christian


On Fri, 2009-09-04 at 21:59 +0000, Elio Damaggio wrote:

> Hi Christian,
>
> I was able to have the operator work :)
>
> How is the situation for unary operators?
> Is there a way to define those for custom datatypes?
> Thanks,
>
> Elio
>
>
> Christian W. Damus wrote:
>
> > Hi, Ed, Elio,
>
> > Yes, OCL is trained to look for Java names "plus", "minus", "lessThan",
> > "greaterThan", etc. to implement these symbolic operators, but it does
> > expect to find the symbolic names (e.g., "+", "<") in the model's
> > EClass. The "<" / "lessThan" operation is particularly handy because it
> > allows your type to be used in "orderedBy" iterators.
>
> > One of the callOperation() or some such methods in the
> > EvaluationEnvironment type hierarchy has the mapping from symbolic to
> > Java names, in looking up the Method objects to invoke reflectively. I
> > should, of course, have documented it in the SDK's developer guide,
> > too :-(
>
> > Cheers,
>
> > Christian
>
>
> > On Sat, 2009-08-29 at 06:52 +0100, Ed Willink wrote:
>
> >> Hi Elio, Ed
> >>
> >> [Ed: you may be able to provide a simple solution for b).]
> >>
> >> a) parser modification
> >>
> >> The parser is intended to be extended rather than modified. Be very wary
> >> of modifying; you will have te re-engineer each time MDT-OCL improves.
> >> That said we are in the process of migrating from LPG 1 to LPG 2,
> >> https://bugs.eclipse.org/bugs/show_bug.cgi?id=242153, which will require
> >> about four trivial edit procedures to existing extensions.
> >>
> >> b) operators
> >>
> >> In your Ecore model of custom data types (EClass not EDataType) you can
> >> add operations such as "+", which you can then use them naturally in
> >> OCL. Unfortunately these give a validation error in EMF so you cannot
> >> genModel them.
> >>
> >> I'm not sure if the situation is any better for a UML model.
> >>
> >> This is a spelling problem I've been considering already: For OCL it
> >> must be "+" for Java it must be perhaps "_plus". (OMG) OCL needs to
> >> specify an encoding scheme for awkward characters and to specify a
> >> concrete syntax access scheme. MDT-OCL supports access via double quotes
> >> e.g:
> >>
> >> def: "+"(d : Date) ...
> >>
> >> I'm afraid I don't know of any solution to making Date + Date work today.
> >>
> >> The XSD support for EMF provides a form of renaming. I've copied this to
> >> Ed Merks who may be able to explain how it could be exploited.
> >>
> >> c) call path
> >>
> >> I'm not very familiar with the EvaluationEnvironment, so nearly all of
> >> what I'm about to suggest may already be the current MDT-OCL functionality.
> >>
> >> You can introduce a derived LOTREnvironment which is created at each
> >> stage of evaluation, with a reference to its outer context. At any point
> >> these references give you the call path. You can then add custom methods
> >> to evaluate any function of the call path that you like. Perhaps you
> >> encapsulate these all in a richer Environment object and implement just
> >> a single .oclEnvironment() method to access it. If you get this working
> >> it might make for a useful contribution to MDT-OCL and a submission for
> >> a future OCL specification.
> >>
> >> Regards
> >>
> >> Ed Willink
> >>
> >> Elio Damaggio wrote:
> >> > Hi all,
> >> >
> >> > I am modifying the OCL parser/evaluator in order to (besides other
> things):
> >> >
> >> > * include a series of time related datatypes (Date, Time, Duration,
> >> > Timestamp). These datatypes should have standard infix operators (+, -,
> >> > ..) like integers and so on... I think I have to modify the
> >> > EvaluationVisitor. Is this the best course of action?
> >> >
> >> > * include predefined methods that, if applied on an attribute, have
> >> > access to the model information of that attribute (i.e. which class they
> >> > belong, in addition to the actual instance).
> >> > For instance, lets assume book have an attribute called author. And the
> >> > "LOTR" book instance has "Tolkien" as its author attribute. Then the
> >> > predefined method LOTR.author.info() should be able to know that it is
> >> > invoked on the "author" attribute of a "book" class.
> >> > Do you have any idea on how to implement these methods?
> >> >
> >> > Thank you all,
> >> >
> >> > Elio
> >> >
>
>

--=-rN+MwqQkJEDAtVtxrai5
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Elio,<BR>
<BR>
The only unary operator currently recognized by OCL is &quot;-&quot; (possibly &quot;+&quot;, but I rather doubt that).&nbsp; For that, the getJavaMethodFor(...) method will indicate the translation.<BR>
<BR>
There is no facility for defining arbitrary infix operators in OCL.&nbsp; The grammar fixes them quite strictly.<BR>
<BR>
Cheers,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Fri, 2009-09-04 at 21:59 +0000, Elio Damaggio wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hi Christian,

I was able to have the operator work :)

How is the situation for unary operators?
Is there a way to define those for custom datatypes?
Thanks,

Elio


Christian W. Damus wrote:

&gt; Hi, Ed, Elio,

&gt; Yes, OCL is trained to look for Java names &quot;plus&quot;, &quot;minus&quot;, &quot;lessThan&quot;,
&gt; &quot;greaterThan&quot;, etc. to implement these symbolic operators, but it does
&gt; expect to find the symbolic names (e.g., &quot;+&quot;, &quot;&lt;&quot;) in the model's
&gt; EClass. The &quot;&lt;&quot; / &quot;lessThan&quot; operation is particularly handy because it
&gt; allows your type to be used in &quot;orderedBy&quot; iterators.

&gt; One of the callOperation() or some such methods in the
&gt; EvaluationEnvironment type hierarchy has the mapping from symbolic to
&gt; Java names, in looking up the Method objects to invoke reflectively. I
&gt; should, of course, have documented it in the SDK's developer guide,
&gt; too :-(

&gt; Cheers,

&gt; Christian


&gt; On Sat, 2009-08-29 at 06:52 +0100, Ed Willink wrote:

&gt;&gt; Hi Elio, Ed
&gt;&gt;
&gt;&gt; [Ed: you may be able to provide a simple solution for b).]
&gt;&gt;
&gt;&gt; a) parser modification
&gt;&gt;
&gt;&gt; The parser is intended to be extended rather than modified. Be very wary
&gt;&gt; of modifying; you will have te re-engineer each time MDT-OCL improves.
&gt;&gt; That said we are in the process of migrating from LPG 1 to LPG 2,
&gt;&gt; <A HREF="https://bugs.eclipse.org/bugs/show_bug.cgi?id=242153">https://bugs.eclipse.org/bugs/show_bug.cgi?id=242153</A>, which will require
&gt;&gt; about four trivial edit procedures to existing extensions.
&gt;&gt;
&gt;&gt; b) operators
&gt;&gt;
&gt;&gt; In your Ecore model of custom data types (EClass not EDataType) you can
&gt;&gt; add operations such as &quot;+&quot;, which you can then use them naturally in
&gt;&gt; OCL. Unfortunately these give a validation error in EMF so you cannot
&gt;&gt; genModel them.
&gt;&gt;
&gt;&gt; I'm not sure if the situation is any better for a UML model.
&gt;&gt;
&gt;&gt; This is a spelling problem I've been considering already: For OCL it
&gt;&gt; must be &quot;+&quot; for Java it must be perhaps &quot;_plus&quot;. (OMG) OCL needs to
&gt;&gt; specify an encoding scheme for awkward characters and to specify a
&gt;&gt; concrete syntax access scheme. MDT-OCL supports access via double quotes
&gt;&gt; e.g:
&gt;&gt;
&gt;&gt; def: &quot;+&quot;(d : Date) ...
&gt;&gt;
&gt;&gt; I'm afraid I don't know of any solution to making Date + Date work today.
&gt;&gt;
&gt;&gt; The XSD support for EMF provides a form of renaming. I've copied this to
&gt;&gt; Ed Merks who may be able to explain how it could be exploited.
&gt;&gt;
&gt;&gt; c) call path
&gt;&gt;
&gt;&gt; I'm not very familiar with the EvaluationEnvironment, so nearly all of
&gt;&gt; what I'm about to suggest may already be the current MDT-OCL functionality.
&gt;&gt;
&gt;&gt; You can introduce a derived LOTREnvironment which is created at each
&gt;&gt; stage of evaluation, with a reference to its outer context. At any point
&gt;&gt; these references give you the call path. You can then add custom methods
&gt;&gt; to evaluate any function of the call path that you like. Perhaps you
&gt;&gt; encapsulate these all in a richer Environment object and implement just
&gt;&gt; a single .oclEnvironment() method to access it. If you get this working
&gt;&gt; it might make for a useful contribution to MDT-OCL and a submission for
&gt;&gt; a future OCL specification.
&gt;&gt;
&gt;&gt; Regards
&gt;&gt;
&gt;&gt; Ed Willink
&gt;&gt;
&gt;&gt; Elio Damaggio wrote:
&gt;&gt; &gt; Hi all,
&gt;&gt; &gt;
&gt;&gt; &gt; I am modifying the OCL parser/evaluator in order to (besides other
things):
&gt;&gt; &gt;
&gt;&gt; &gt; * include a series of time related datatypes (Date, Time, Duration,
&gt;&gt; &gt; Timestamp). These datatypes should have standard infix operators (+, -,
&gt;&gt; &gt; ..) like integers and so on... I think I have to modify the
&gt;&gt; &gt; EvaluationVisitor. Is this the best course of action?
&gt;&gt; &gt;
&gt;&gt; &gt; * include predefined methods that, if applied on an attribute, have
&gt;&gt; &gt; access to the model information of that attribute (i.e. which class they
&gt;&gt; &gt; belong, in addition to the actual instance).
&gt;&gt; &gt; For instance, lets assume book have an attribute called author. And the
&gt;&gt; &gt; &quot;LOTR&quot; book instance has &quot;Tolkien&quot; as its author attribute. Then the
&gt;&gt; &gt; predefined method LOTR.author.info() should be able to know that it is
&gt;&gt; &gt; invoked on the &quot;author&quot; attribute of a &quot;book&quot; class.
&gt;&gt; &gt; Do you have any idea on how to implement these methods?
&gt;&gt; &gt;
&gt;&gt; &gt; Thank you all,
&gt;&gt; &gt;
&gt;&gt; &gt; Elio
&gt;&gt; &gt;


</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-rN+MwqQkJEDAtVtxrai5--
Previous Topic:Expressions involving undefined values
Next Topic:OCL query to find classes
Goto Forum:
  


Current Time: Wed Apr 24 14:44:59 GMT 2024

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

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

Back to the top