Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [XCORE] How to customize/override attribute getter/setter ?
[XCORE] How to customize/override attribute getter/setter ? [message #1400541] Mon, 14 July 2014 10:56 Go to next message
xjn Mising nameFriend
Messages: 20
Registered: May 2010
Junior Member
Hi,

i try to customize/override attribute setters.
The attribute is not dervied, i only woluld like to have some additional code.


Here is my test code, Xtext validation is OK, but
no special body is generated for the setter valueA.


package test

abstract class AbstractBase
{
    /* attribute with overridden setter, XText validation is OK ! */
    int valueA
    set
    {
        checkValue(valueA)
    } // !error! no modified setter generated in AbstractBaseImpl class !
    //
    /* check method, should be abstract */
    op int checkValue(int value)
}

class A extends AbstractBase
{
    /* special check method for class A */
    op int checkValue(int value) {
        if (value < -10)
            throw new IllegalArgumentException()
        value
    }
}

class B extends AbstractBase
{
    /* special check method for class B */
    op int checkValue(int value) {
        if (value > 10)
            throw new IllegalArgumentException()
        value
    }
}


Where is my mistake ?

Thx for help


br
xjn
Re: [XCORE] How to customize/override attribute getter/setter ? [message #1400587 is a reply to message #1400541] Mon, 14 July 2014 12:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Xin,

Sorry, that doesn't work. It's only designed to work for derived
features, and even then, only for the getter, and then even many-valued
features are tricky to implement. The setters will be complex to deal
with because you don't want to bypass the notification code.


On 14/07/2014 12:56 PM, xjn Mising name wrote:
> Hi,
>
> i try to customize/override attribute setters. The attribute is not
> dervied, i only woluld like to have some additional code.
>
>
> Here is my test code, Xtext validation is OK, but no special body is
> generated for the setter valueA.
>
>
>
> package test
>
> abstract class AbstractBase
> {
> /* attribute with overridden setter, XText validation is OK ! */
> int valueA
> set
> {
> checkValue(valueA)
> } // !error! no modified setter generated in AbstractBaseImpl class !
> //
> /* check method, should be abstract */
> op int checkValue(int value)
> }
>
> class A extends AbstractBase
> {
> /* special check method for class A */
> op int checkValue(int value) {
> if (value < -10)
> throw new IllegalArgumentException()
> value
> }
> }
>
> class B extends AbstractBase
> {
> /* special check method for class B */
> op int checkValue(int value) {
> if (value > 10)
> throw new IllegalArgumentException()
> value
> }
> }
>
>
> Where is my mistake ?
>
> Thx for help
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [XCORE] How to customize/override attribute getter/setter ? [message #1400665 is a reply to message #1400587] Mon, 14 July 2014 14:38 Go to previous messageGo to next message
xjn Mising nameFriend
Messages: 20
Registered: May 2010
Junior Member
Ed,

your answer to not support that is not that good and
really a bit unexpected ...

---

In the XCore syntax this is allowed, for derived and non
derived attributes, both, to override set/get.

Shouldn't at least get/set with bodies for attributes and set
with bodies for derived attributes provide a validation error
in the editor ?

And please, don't tell me again to open a bugzilla for this Smile

--

As i said before in some message, i'm using modelling for over 20
years and now got the job to migrate all our proprietary modelling
to a de-facto-/pseudo-standard like EMF/XCore.

And many of the expected modelling features are not available or does
not work as expected with EMF/XCore, or are too slow, up to be unusable ...

---

I'm sorry, i like your work, i like the ideas, but I currently don't
know how to use it for "real life" projects.

The support of loading/saving, notification, validation and UI-/XML-
support seems not to be worth many of the drawbacks, I currently run
into.

---

There are many things to extend the EMF, i.e. :

- support Class Constants

- support Methods on Enum

- support extensible Singletons

- ...

---

There are many things to extend the XCore, i.e. :

- support "val" and "local val" on class as final static
constants, without getter/setter in interface

- support "var" on class as variables
without getter/setter in interface

- support additional argument based constructors in the
Factory

- support Xbase Validation without EMF-Annotions

- ...

---

I'm not focused to Java, as I said, many of my models has to
be migrated from C to Java.

May be I don't understand targeting of your work, please
advise me.

I'm a bit frustrated :)Wink

thx for response



br
xjn
Re: [XCORE] How to customize/override attribute getter/setter ? [message #1400735 is a reply to message #1400665] Mon, 14 July 2014 16:42 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Xjn,

Comments below.


On 14/07/2014 4:38 PM, xjn xjn wrote:
> Ed,
>
> your answer to not support that is not that good and really a bit
> unexpected ...
>
> ---
>
> In the XCore syntax this is allowed, for derived and non derived
> attributes, both, to override set/get.
Yes, the plan is to make it work, eventually.
>
> Shouldn't at least get/set with bodies for attributes and set with
> bodies for derived attributes provide a validation error in the editor ?
I suppose. I probably shouldn't have put it in the syntax until I'd
implemented it properly.
>
> And please, don't tell me again to open a bugzilla for this :)
>
> --
>
> As i said before in some message, i'm using modelling for over 20
> years and now got the job to migrate all our proprietary modelling to
> a de-facto-/pseudo-standard like EMF/XCore.
I see.
>
> And many of the expected modelling features are not available or does
> not work as expected with EMF/XCore, or are too slow, up to be
> unusable ...
I can't comment on what you're using before...
>
> ---
>
> I'm sorry, i like your work, i like the ideas, but I currently don't
> know how to use it for "real life" projects.
I know the Canadian Space Agency is using Xcore for a very large
project, so it's definitely used in real life.
>
> The support of loading/saving, notification, validation and UI-/XML-
> support seems not to be worth many of the drawbacks, I currently run
> into.
The alternatives, though, are few and far between, aren't they?
>
> ---
>
> There are many things to extend the EMF, i.e. :
>
> - support Class Constants
>
> - support Methods on Enum
>
> - support extensible Singletons
It wouldn't kill you to write Java code.
>
> - ...
>
> ---
>
> There are many things to extend the XCore, i.e. :
>
> - support "val" and "local val" on class as final static constants,
> without getter/setter in interface
Pretty much support every feature possible in Java would be on the list,
but that's a huge effort and no one pays for the results.

>
> - support "var" on class as variables without getter/setter in interface
>
> - support additional argument based constructors in the Factory
>
> - support Xbase Validation without EMF-Annotions
>
> - ...
>
> ---
>
> I'm not focused to Java, as I said, many of my models has to be
> migrated from C to Java.
Most people use EMF as a Java generator (and use the structured Ecore
editor or the Ecore Tools graphical editor to create their models).
They write by hand the things that EMF doesn't generate.
>
> May be I don't understand targeting of your work, please advise me.
>
> I'm a bit frustrated :);)
If you're hoping to not write any Java code for your more complex types
of problems, i.e., you're not just defining a data model, but you're
want to express a lot of behavior and other concepts that go well beyond
what Ecore captures, that's not a goal you're going to achieve. I don't
know of any solution that will help you achieve that.
>
> thx for response
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:migration: EString attribute to ERference
Next Topic:[CDO] getOldValue call on notification return null if auditing is disabled
Goto Forum:
  


Current Time: Thu Apr 18 05:38:46 GMT 2024

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

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

Back to the top