Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Method not found for child class based on a class from another model
Method not found for child class based on a class from another model [message #1861333] Fri, 06 October 2023 11:56 Go to next message
Alexander Zemtsov is currently offline Alexander ZemtsovFriend
Messages: 2
Registered: October 2023
Junior Member
Hello everyone!

Let me describe the problem I faced on a little example (Obeo modelling project is attached).

I have two metamodels: A and B. A has a root element and a class BaseClass.
index.php/fa/43555/0/

The B model has a class ChildClass which inherits from BaseClass of model A.
index.php/fa/43556/0/

I defined methods for BaseClass which are a getter and a setter for an attribute name.
operation a!BaseClass getName(): String {
	return self.name;
}

operation a!BaseClass setName(name: String) {
	self.name = name;
}


My sample script runs through all items of my model A and creates new items of ChildClass from the model B.
import "a.eol";

var root = a!Root.all().first();

for (item in root.items) {
	("Processing item " + item.getName()).println();
	
	var newItem = new b!ChildClass();
	newItem.name = item.getName() + "_child";
}


It works fine. But if I replace =name with a setter it fails.

import "a.eol";

var root = a!Root.all().first();

for (item in root.items) {
	("Processing item " + item.getName()).println();
	
	var newItem = new b!ChildClass();
	newItem.setName(item.getName() + "_child");
}


What I expect is successful execution of the script since ChildClass inherits from BaseClass.
What I got is an error:
Method 'setName' not found for: ChildClass [name=null, ]


I suppose, my models load wrong way. Please help me to understand what exactly goes wrong and how to fix it.

Thanks a lot in andvance
Re: Method not found for child class based on a class from another model [message #1861374 is a reply to message #1861333] Mon, 09 October 2023 18:02 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Hi Alexander,

operation a!BaseClass setName() { ... } adds an operation setName to elements of type BaseClass that belong to the a model. Therefore trying to call setName on elements that belong to the b model fails as expected.

To be able to call setName on elements from both models a and b you need to define it in the context of an alias (e.g. operation x!BaseClass setName() { ... } and then assign the x alias to both models a and b in your run configuration.

Does this answer your question?

Thanks,
Dimitris
Re: Method not found for child class based on a class from another model [message #1861382 is a reply to message #1861374] Tue, 10 October 2023 06:39 Go to previous messageGo to next message
Alexander Zemtsov is currently offline Alexander ZemtsovFriend
Messages: 2
Registered: October 2023
Junior Member
Hello Dimitris,

Thank you for your answer. You have just confirmed my hunch about that.
Usually, I use metamodels loaded from a plugin installed in Obeo. And the scenario I described in my question runs ok. That is what confused me.
I updated my scripts and now it works fine regardless of how metamodels loaded.

Thank you again!
Re: Method not found for child class based on a class from another model [message #1861384 is a reply to message #1861382] Tue, 10 October 2023 07:30 Go to previous message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

It's good to hear that your scripts work well now. If you run into any more issues, please give us a shout.

Thanks,
Dimitris
Previous Topic:Flexmi anonymous root
Next Topic:Java and epsilon ecl syncronizathion
Goto Forum:
  


Current Time: Sat Apr 27 07:21:36 GMT 2024

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

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

Back to the top