Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How to add power operation to the primitive type Integer?
How to add power operation to the primitive type Integer? [message #1724048] Sat, 20 February 2016 08:48 Go to next message
Roberto Saltini is currently offline Roberto SaltiniFriend
Messages: 24
Registered: February 2016
Junior Member
Hi All,

What is the best way to add the operation power(i: Integer): Integer to the primitive type Integer.

The only solution that I am able to envision is to define a new DataType (e.g. Integer_with_power) that generalise the DataType Integer and defines the operation power(i: Integer): Integer and define the body of this operation via OCL.

Is there any better way do achieve the same result?

Regards,

Roberto

[Updated on: Sat, 20 February 2016 09:32]

Report message to a moderator

Re: How to add power function to the primitive type Integer? [message #1724051 is a reply to message #1724048] Sat, 20 February 2016 09:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Now that OCL standard libraries are extensible, the 'correct' way is to
use the Math.oclstdlib library. Unfortunately it's on the to-do list as
is a tutorial on how to do it. If you're enthusiastic you can look at
the *.oclstdlib extension libraries for OCL CG, or for QVTd or the JUnit
tests.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=415146

Also on the to-do list is the 'java:java.lang.Math.pow'(a, b) direct
from OCL invocation.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=378206

The simplest way using OCLinEcore is to add a bogus class Math to your
model and define Math.pow(mantissa : Integer, expoent : Integer). If at
least one of your classes implements Math, you can use it as a bogus
self for self.pow(a, b).

Or in UML you can define a DataType with an OCLforUML::Integer
stereotype. No need to generalize Integer.

In either case you can implement the body in Java.

Using Complete OCL you can define the inefficient

package ocl
context Integer
def pow(Integer : b) = if b > 1 then self*pow(b-1) elseif b = 1 then
self else 1 endif
endpackage

Regards

Ed Willink



On 20/02/2016 08:48, Roberto Saltini wrote:
> Hi All,
>
> What is the better way to add the operation power(i: Integer): Integer
> to the primitive type Integer.
>
> The only solution that I am able to envision is to define a new
> DataType (e.g. Integer_with_power) that generalise the DataType
> Integer and defines the operation power(i: Integer): Integer and
> define the body of this operation via OCL.
>
> Is there any better way do achieve the same result?
>
> Regards,
>
> Roberto
Re: How to add power function to the primitive type Integer? [message #1724053 is a reply to message #1724051] Sat, 20 February 2016 10:17 Go to previous messageGo to next message
Roberto Saltini is currently offline Roberto SaltiniFriend
Messages: 24
Registered: February 2016
Junior Member
Hi Ed,

Thank you for the reply.

I am using Papyrus and I am not able to find the profile OCLforUML.

I have also searched in the Mars packages and I cannot find anything that mentions OCLforUML.

Thanks,
Roberto.
Re: How to add power function to the primitive type Integer? [message #1724055 is a reply to message #1724053] Sat, 20 February 2016 11:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Papyrus requires both Papyrus and UML2 profile registrations, but Mars
has only the UML2 registration. This has been fixed in Papyrus since at
least, I think, M4. Quite possibly Mars.1. Certainly Mars.2 next week.

As a workaround, edit the *.uml file with the UML Model Editor and apply
the profile there. Thereafter it is available within Papyrus.

Regards

Ed Willink


On 20/02/2016 10:17, Roberto Saltini wrote:
> Hi Ed,
>
> Thank you for the reply.
>
> I am using Papyrus and I am not able to find the profile OCLforUML.
>
> I have also searched in the Mars packages and I cannot find anything
> that mentions OCLforUML.
>
> Thanks,
> Roberto.
Re: How to add power function to the primitive type Integer? [message #1724109 is a reply to message #1724055] Sun, 21 February 2016 02:00 Go to previous messageGo to next message
Roberto Saltini is currently offline Roberto SaltiniFriend
Messages: 24
Registered: February 2016
Junior Member
Hi Ed,

I am using Mars.3(4.5.3) shipped with the latest stable Papyrus.
I have tried your suggestion to edit the uml file using UML Model Editor, but when I try to apply a new profile I cannot find the profile OCLforUML listed as you can see from the following images.

index.php/fa/25053/0/

These is the list of profiles available as value of the field Applied Profile:
index.php/fa/25054/0/

Regards,
Roberto

[Updated on: Sun, 21 February 2016 02:01]

Report message to a moderator

Re: How to add power function to the primitive type Integer? [message #1724117 is a reply to message #1724109] Sun, 21 February 2016 09:59 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Select a Package

UML Editor(on menu bar)->Package->Apply Profile...

Regards

Ed Willink


On 21/02/2016 02:00, Roberto Saltini wrote:
> Hi Ed,
>
> I am using Mars.3(4.5.3) shipped with the latest stable Papyrus.
> I have tried your suggestion to edit the uml file using UML Model Editor, but when I try to apply a new profile I cannot find the profile OCLforUML listed as you can see from the following images.
>
>
>
>
>
> Regards,
> Roberto
Previous Topic:Non documented dependency for OCLinEcore
Next Topic:Computing derived attribute values with dynamic EMF
Goto Forum:
  


Current Time: Thu Apr 25 19:51:51 GMT 2024

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

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

Back to the top