Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » derived attribute in OCLinEcore editor
derived attribute in OCLinEcore editor [message #827769] Fri, 23 March 2012 19:21 Go to next message
Aran A is currently offline Aran AFriend
Messages: 30
Registered: January 2011
Member

Hello,

I want to define a derived attribute in my ecore model, and my problem is the syntax. Warmer's book describes it using 'derive' keyword (and the same in the Indigo Eclipse Help), but when I write it in the OCLinEcore Editor, I have a syntax error. Scanning in the forum I've seen an example using the 'derivation' keyword, but I still have an error. I've made several attempts, but any improvement. What is the syntax for derived attributes?

class Directory{
attribute name: String[?] { ordered };
attribute upperName: String {derivation: self.name.toUpper();};
}

Thanks in advance,

Aran
Re: derived attribute in OCLinEcore editor [message #827805 is a reply to message #827769] Fri, 23 March 2012 20:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Warmer&Kleppe describe the Complete OCL syntax for independent
complementary OCL documents. This syntax applies when you edit *.ocl.

OCLinEcore is an embedded syntax that borrows from the style of OMG
specifications. You have correctly identified the derivation keyword and
syntax, however you still need to get the Ecore attributes right. You
probably want {derived transient volatile} too as in

attribute upperName: String {derived transient volatile} {derivation:
self.name.toUpper();}

[Yes there should be some validation warnings to help you.]

Regards

Ed Willink



On 23/03/2012 15:21, Missing name Mising name wrote:
>
> Hello,
>
> I want to define a derived attribute in my ecore model, and my problem
> is the syntax. Warmer's book describes it using 'derive' keyword (and
> the same in the Indigo Eclipse Help), but when I write it in the
> OCLinEcore Editor, I have a syntax error. Scanning in the forum I've
> seen an example using the 'derivation' keyword, but I still have an
> error. I've made several attempts, but any improvement. What is the
> syntax for derived attributes?
>
> class Directory{
> attribute name: String[?] { ordered };
> attribute upperName: String {derivation: self.name.toUpper();};
> }
>
> Thanks in advance,
>
> Aran
Re: derived attribute in OCLinEcore editor [message #830929 is a reply to message #827805] Wed, 28 March 2012 08:33 Go to previous messageGo to next message
Aran A is currently offline Aran AFriend
Messages: 30
Registered: January 2011
Member

Hello!

That was the problem, thanks a lot. But I still have problems with the derived attribute.

I write the ecore file (following your instructions), and then I generate the genmodel file (OK), and then, (following the EMF tutorial) I make the steps to generate 'model code', 'edit code' and 'editor code'. In the first step two packages are generated, and one of the files (DirectoryImpl.java) has a compilation error (
UPPER_NAME_EDEFAULT cannot be resolved to a variable) in the line I show.

public class DirectoryImpl extends ...
....
public void eUnset(int featureID) {
switch (featureID) {
case MinheritPackage.SYSTEM__NAME:
....
case MinheritPackage.SYSTEM__UPPER_NAME:
setUpperName(UPPER_NAME_EDEFAULT); <<<<<<<<<<<<
return;
}
}

Is it a bug? or, there is something more that I do wrong?

By the way, despite the compilation error in the generated model code, the editor can be generated and then I can launch. The editor works (I can describe a model with a directory, and when I write its name, automatically the value of 'upperName' attribute is filled in).

Best regards,

Aran
Re: derived attribute in OCLinEcore editor [message #830989 is a reply to message #830929] Wed, 28 March 2012 10:04 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Sorry my earlier comment was slightly misleading. "You probably want
{derived transient volatile} too". You do not want "transient".

You probably need something like the OCLinEcore tutorial

property loans : Loan[*] { derived volatile }
{
derivation: library.loans->select(book = self);
}

Regards

Ed Willink

On 28/03/2012 04:33, Missing name Mising name wrote:
>
> Hello!
>
> That was the problem, thanks a lot. But I still have problems with the
> derived attribute.
> I write the ecore file (following your instructions), and then I
> generate the genmodel file (OK), and then, (following the EMF
> tutorial) I make the steps to generate 'model code', 'edit code' and
> 'editor code'. In the first step two packages are generated, and one
> of the files (DirectoryImpl.java) has a compilation error (
> UPPER_NAME_EDEFAULT cannot be resolved to a variable) in the line I show.
Re: derived attribute in OCLinEcore editor [message #831697 is a reply to message #830989] Thu, 29 March 2012 08:11 Go to previous messageGo to next message
Aran A is currently offline Aran AFriend
Messages: 30
Registered: January 2011
Member
Hi!,

Thanks for your answer.

Before my first message I tried different options and combinations, and I'm sure that I tried with the {derived, volatile} option, and it didn't work, perhaps because I could have another problem in my expression. Anyway, it doesn't matter.

Following your suggestion, I have tried with this expression, and the same problem was there. 'upperName' is an attribute and its value is a String, so, I understand that the String[?] expression is correct.

attribute upperName : String[?] { derived, volatile }
{
derivation: self.name.toUpper();
}

I have made different tries to correct the problem, and finally this expression has worked. As I understand String[*] means that there is a collection of Strings, so for me it's a little bit strange: 'nameUpper' is one String and I have to specify as a collection. But, it works, so for me it's OK.

attribute nameUpper : String[*] { derived, volatile }
{
derivation: self.name.toUpper();
}

Thanks a lot. Best regards,

Aran
Re: derived attribute in OCLinEcore editor [message #831749 is a reply to message #831697] Thu, 29 March 2012 09:32 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If you want an optional string use [?].
If you want a mandatory string use [1].

You should not use [*] unless you want many.

Regards

Ed Willink

On 29/03/2012 04:11, Missing name Mising name wrote:
> Hi!,
>
> Thanks for your answer.
> Before my first message I tried different options and combinations,
> and I'm sure that I tried with the {derived, volatile} option, and it
> didn't work, perhaps because I could have another problem in my
> expression. Anyway, it doesn't matter.
>
> Following your suggestion, I have tried with this expression, and the
> same problem was there. 'upperName' is an attribute and its value is a
> String, so, I understand that the String[?] expression is correct.
>
> attribute upperName : String[?] { derived, volatile }
> {
> derivation: self.name.toUpper();
> }
>
> I have made different tries to correct the problem, and finally this
> expression has worked. As I understand String[*] means that there is a
> collection of Strings, so for me it's a little bit strange:
> 'nameUpper' is one String and I have to specify as a collection. But,
> it works, so for me it's OK.
> attribute nameUpper : String[*] { derived, volatile }
> {
> derivation: self.name.toUpper();
> }
>
> Thanks a lot. Best regards,
>
> Aran
Previous Topic:lack a class "QueryDelegateTextViewer"
Next Topic:OCL AST
Goto Forum:
  


Current Time: Thu Mar 28 10:10:50 GMT 2024

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

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

Back to the top