Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [XCore] Can I reference a EAtribute of a Xcore model on another Xcore model (within the same package(Help with basic XCore. Referencing EAtributes from different xcore files)
[XCore] Can I reference a EAtribute of a Xcore model on another Xcore model (within the same package [message #1428983] Mon, 22 September 2014 16:33 Go to next message
João Bastos is currently offline João BastosFriend
Messages: 9
Registered: September 2014
Junior Member
I have a very simple question. Unfortunately I am very new to EMF, Ecore and Xcore. I started by using Ecore, however, since XCore was text based it was easier for me to work with it.

I made several simple models, but now I want to create a more complex model.

Lets say I want to create a model that defines a System. A System has a Plaform and Activities.

So, I though it would be best to model these two in different Xcore (maybe a mistake)

Now, my problem is:

I have an EClass Resource, within Platform.xcore, that has an attribute String name. I also have a EClass Transfer, within Acitivy.xcore.

Class Transfer
{
contains Resource source
contains Resource target
}
What I want to do know is:

derived String name get
{
source.name + "_" target.name
}
I know I am trying to insert Java code here, but I thought it would work. I get an error, logical, that says this field cannot be applied, there is no type of such in GenModel

I tried also

source.getName()
Error message: no defintion for getName()

I think this might be a stupid question. Maybe I should not have seperated the models. Is there a way of doing this?

OR if this is a simple question and there literature I can read, could you point me to it? I really can only find the wikipedia for XCore and it is not being enough.
Re: [XCore] Can I reference a EAtribute of a Xcore model on another Xcore model (within the same pac [message #1429028 is a reply to message #1428983] Mon, 22 September 2014 17:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30353
Registered: July 2009
Senior Member
João,

Comments below.

On 22/09/2014 7:36 PM, João Bastos wrote:
> I have a very simple question. Unfortunately I am very new to EMF,
> Ecore and Xcore. I started by using Ecore, however, since XCore was
> text based it was easier for me to work with it.
Yes, the editing experience is quite a bit nicer...
>
> I made several simple models, but now I want to create a more complex
> model.
>
> Lets say I want to create a model that defines a System. A System has
> a Plaform and Activities.
>
> So, I though it would be best to model these two in different Xcore
> (maybe a mistake)
It's hard to say.
>
> Now, my problem is:
>
> I have an EClass Resource, within Platform.xcore, that has an
> attribute String name. I also have a EClass Transfer, within
> Acitivy.xcore.
>
> Class Transfer
> {
> contains Resource source
> contains Resource target
> }
> What I want to do know is:
>
> derived String name get
> {
> source.name + "_" target.name
> }
> I know I am trying to insert Java code here, but I thought it would work.
It seems sensible...
> I get an error, logical, that says this field cannot be applied, there
> is no type of such in GenModel
I need to see complete example to understand the errors; after all, in
the above you're missing a '+'...
>
> I tried also
>
> source.getName()
> Error message: no defintion for getName()
This is an error message in your *.xcore? Where are the *.xcore's
located? In the same project? Different projects? How are the
projects related (via MANIFEST.MF dependencies) if different?
>
> I think this might be a stupid question. Maybe I should not have
> seperated the models. Is there a way of doing this?
It even works to have two mutually referencing models, if they're in the
same project...
>
> OR if this is a simple question and there literature I can read, could
> you point me to it?
That's it.
> I really can only find the wikipedia for XCore and it is not being
> enough.
I can answer your questions, but you need to provide complete specific
details.
Re: [XCore] Can I reference a EAtribute of a Xcore model on another Xcore model (within the same pac [message #1429553 is a reply to message #1429028] Tue, 23 September 2014 11:45 Go to previous messageGo to next message
João Bastos is currently offline João BastosFriend
Messages: 9
Registered: September 2014
Junior Member
I apologize for the lack of information and the simple statement of the problem.

I have both .xcore files in the same package.

I have a resource.xcore which is something like this:

package project1.basic

class Resource 
{
	String name
	int ID
	contains Position[1..1] pos
}


And a application.xcore:

package project1.basic

class Transfer
{
	String name
	contains Resource source
	contains Resource target
	derived String name get
	{
		source.name + "_" + target.name
	}
}


The error I am getting is the following:
(The error is on the application.xcore file and on the exact line of "source.name + "_" + target.name")

"Could not resolve reference to JvmIdentifiableElement "name""

If I try to do it via an operation, creating an op for Resource getResourceName(). The error is:

"Could not resolve reference method getResourceName()"


I am sorry to bother with this sort of errors, but I cannot find any information about it, I am also the only one in my group working with this.

I expect something like defining the methods public or private in Java,
but I don't know how to define this in Ecore language.

Can you please give me some insight?
Also can you direct me to some literature I can find on XCore or Ecore?

I have an EMF book, which does not help much with this.

Thank you in advance.

Joao Bastos

[Updated on: Tue, 23 September 2014 11:46]

Report message to a moderator

Re: [XCore] Can I reference a EAtribute of a Xcore model on another Xcore model (within the same pac [message #1429569 is a reply to message #1429553] Tue, 23 September 2014 12:10 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30353
Registered: July 2009
Senior Member
João,

If I have a file A.xcore containing this:

package project1.basic1

class Resource {
String name
int ID
contains Position[1..1] pos
}

class Position
{

}

And a file B.xcore containing this:

package project1.basic2

import project1.basic1.Resource

class Transfer
{
contains Resource source
contains Resource target
derived String name get
{
source.name + "_" + target.name
}
}

And they're both in the model folder of the same project, it all works
correctly.

So the basic problem with your example is that you can't have two
different *.xcore resources with the same package name, i.e., you can't
split a package across multiple files. You also can't have two features
named "name" in Transfer.



On 23/09/2014 1:45 PM, João Bastos wrote:
> I apologize for the lack of information and the simple statement of
> the problem.
>
> I have both .xcore files in the same package.
>
> I have a resource.xcore which is something like this:
>
> package project1.basic
>
> class Resource {
> String name
> int ID
> contains Position[1..1] pos
> }
>
>
> And a application.xcore:
>
>
> package project1.basic
>
> class Transfer
> {
> String name
> contains Resource source
> contains Resource target
> derived String name get
> {
> source.name + "_" + target.name
> }
> }
>
> The error I am getting is the following:
>
> "Could not resolve reference to JvmIdentifiableElement "name""
>
> If I try to do it via an operation, creating an op for Resource
> getResourceName(). The error is:
>
> "Could not resolve reference method getResourceName()"
>
>
> I am sorry to bother with this sort of errors, but I cannot find any
> information about it, I am also the only one in my group working with
> this.
> I expect something like defining the methods public or private in
> Java, but I don't know how to define this in Ecore language.
> Can you please give me some insight?
> Also can you direct me to some literature I can find on XCore or Ecore?
>
> I have an EMF book, which does not help much with this.
>
> Thank you in advance.
>
> Joao Bastos
Re: [XCore] Can I reference a EAtribute of a Xcore model on another Xcore model (within the same pac [message #1429573 is a reply to message #1429569] Tue, 23 September 2014 12:17 Go to previous messageGo to next message
João Bastos is currently offline João BastosFriend
Messages: 9
Registered: September 2014
Junior Member
Ahhhhh, I see. Now I feel kind of stupid.

But that is really helpful, and thank you for the time you took to help me.

Can I ask you a different question also on this thread ?
Re: [XCore] Can I reference a EAtribute of a Xcore model on another Xcore model (within the same pac [message #1429578 is a reply to message #1429573] Tue, 23 September 2014 12:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30353
Registered: July 2009
Senior Member
João,

It's best to ask unrelated questions on a different thread...

On 23/09/2014 2:17 PM, João Bastos wrote:
> Ahhhhh, I see. Now I feel kind of stupid.
>
> But that is really helpful, and thank you for the time you took to
> help me.
>
> Can I ask you a different question also on this thread ?
Previous Topic:EMF complete model
Next Topic:[CDO] Legacy model changes not comitted
Goto Forum:
  


Current Time: Wed Aug 21 00:55:20 GMT 2019

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

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

Back to the top