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 |
Elio Damaggio 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 |
Ed Willink Messages: 7670 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 |
Ed Merks Messages: 33218 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 |
|
--=-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 "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.<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. I should, of course, have documented it in the SDK's developer guide, too :-(<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 "+", 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
>
</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 |
Elio Damaggio 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 #485087 is a reply to message #484261] |
Thu, 10 September 2009 13:42 |
|
--=-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 "-" (possibly "+", but I rather doubt that). For that, the getJavaMethodFor(...) method will indicate the translation.<BR>
<BR>
There is no facility for defining arbitrary infix operators in OCL. 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:
> 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,
>> <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 "+", 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
>> >
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>
--=-rN+MwqQkJEDAtVtxrai5--
|
|
|
Goto Forum:
Current Time: Thu Sep 26 08:30:50 GMT 2024
Powered by FUDForum. Page generated in 0.04554 seconds
|