Home » Modeling » OCL » derived attribute in OCLinEcore editor
|
Re: derived attribute in OCLinEcore editor [message #827805 is a reply to message #827769] |
Fri, 23 March 2012 20:28 |
Ed Willink Messages: 7670 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 |
Aran A 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 #831697 is a reply to message #830989] |
Thu, 29 March 2012 08:11 |
Aran A 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 |
Ed Willink Messages: 7670 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
|
|
|
Goto Forum:
Current Time: Wed Sep 25 12:19:27 GMT 2024
Powered by FUDForum. Page generated in 0.03947 seconds
|