Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Xcore] abstract operation or derived feature
[Xcore] abstract operation or derived feature [message #1116590] Wed, 25 September 2013 16:26 Go to next message
Jens von Pilgrim is currently offline Jens von Pilgrim
Messages: 295
Registered: July 2009
Senior Member
Hi,

probably I'm missing something... is it really not possible to declare
an abstract operation or derived feature?

Motivation:

I would like this feature as I sometimes kind of "pull up" operations or
features to super classes in order to prevent client code from
implementing endless instanceof cascaded.

E.g., given the two classes

abstract class Base {}
class Special extends Base {
int special
}
class NotSoSpecial extends Base {
}


it would be nice to "pull up" at least the getter, if the default value
for special could be determined, e.g.

abstract class Base {
abstract op int getSpecial()
// or abstract derived int special
}
class Special extends Base {
int special
}
class NotSoSpecial extends Base {
op int getSpecial() { return 0; }
// or derived int special get { return 0; }
}

Well, in the example, I could simple provide a default implementation in
Base. However, this does not work if, due to some inheritance reasons,
the generated implementation of Special cannot inherit from Base: In
that cast, the operation defined in Base is added to Special, and the
getter for the property is renamed to getSpecial_().

Although I could work around that by declaring the operation in Base
without an implementation and provide implementations in derived
classes. However in that case, I have to manually ensure that all
subclasses override this method properly, otherwise sooner or later the
default generated method is called, throwing an
UnsupportedOperationException.

Regards,
Jens
Re: [Xcore] abstract operation or derived feature [message #1117071 is a reply to message #1116590] Thu, 26 September 2013 04:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26088
Registered: July 2009
Senior Member
Jens,

Comments below.

On 25/09/2013 6:26 PM, Jens v.P. wrote:
> Hi,
>
> probably I'm missing something... is it really not possible to declare
> an abstract operation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=393076
> or derived feature?
You mean an abstract derived feature?
>
> Motivation:
>
> I would like this feature as I sometimes kind of "pull up" operations
> or features to super classes in order to prevent client code from
> implementing endless instanceof cascaded.
>
> E.g., given the two classes
>
> abstract class Base {}
> class Special extends Base {
> int special
> }
> class NotSoSpecial extends Base {
> }
>
>
> it would be nice to "pull up" at least the getter, if the default
> value for special could be determined, e.g.
>
> abstract class Base {
> abstract op int getSpecial()
> // or abstract derived int special
> }
> class Special extends Base {
> int special
> }
> class NotSoSpecial extends Base {
> op int getSpecial() { return 0; }
> // or derived int special get { return 0; }
> }
>
> Well, in the example, I could simple provide a default implementation
> in Base. However, this does not work if, due to some inheritance
> reasons, the generated implementation of Special cannot inherit from
> Base: In that cast, the operation defined in Base is added to Special,
> and the getter for the property is renamed to getSpecial_().
Hmmm. That sounds a little odd.
>
> Although I could work around that by declaring the operation in Base
> without an implementation and provide implementations in derived
> classes. However in that case, I have to manually ensure that all
> subclasses override this method properly, otherwise sooner or later
> the default generated method is called, throwing an
> UnsupportedOperationException.
That's the bugzilla above...
>
> Regards,
> Jens
Re: [Xcore] abstract operation or derived feature [message #1117606 is a reply to message #1117071] Thu, 26 September 2013 16:18 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von Pilgrim
Messages: 295
Registered: July 2009
Senior Member
Ed,

On 26.09.13 06:33, Ed Merks wrote:
>> probably I'm missing something... is it really not possible to declare
>> an abstract operation
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=393076

Yes, that's it. I should have searched for bugs first. Thank you for the
link.

>> Base: In that cast, the operation defined in Base is added to Special,
>> and the getter for the property is renamed to getSpecial_().
> Hmmm. That sounds a little odd.

Should I file a bug?

Regards,
Jens
Re: [Xcore] abstract operation or derived feature [message #1117611 is a reply to message #1117606] Thu, 26 September 2013 16:20 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26088
Registered: July 2009
Senior Member
Jens,

Comments below.

On 26/09/2013 6:18 PM, Jens v.P. wrote:
> Ed,
>
> On 26.09.13 06:33, Ed Merks wrote:
>>> probably I'm missing something... is it really not possible to declare
>>> an abstract operation
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=393076
>
> Yes, that's it. I should have searched for bugs first. Thank you for
> the link.
>
>>> Base: In that cast, the operation defined in Base is added to Special,
>>> and the getter for the property is renamed to getSpecial_().
>> Hmmm. That sounds a little odd.
>
> Should I file a bug?
It sounds kind of deliberate (I suppose the operation could then call
this generated getter) rather than accidental but it's probably worth to
have a close look.
>
> Regards,
> Jens
Previous Topic:ComposedAdapterFactory delegates to generated factory for dynamic EObject
Next Topic:ClassCastException when editing property sheet value
Goto Forum:
  


Current Time: Thu Oct 02 06:42:30 GMT 2014

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

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