Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Differences in URI values
Differences in URI values [message #1751843] Mon, 16 January 2017 07:39 Go to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I want to get the URI of my data.
So, I have this object called x.

I noticed that I can get the URI in different ways.
[1] x.eContainingFeature.eContainer.eResource.URI
[2] x.eResource.URI
[3] x.eContainer.eResource.URI

What are the differences of these 3 URI values? Should I expect them to always contain the same values?

[Updated on: Mon, 16 January 2017 07:40]

Report message to a moderator

Re: Differences in URI values [message #1751844 is a reply to message #1751843] Mon, 16 January 2017 07:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 10325
Registered: July 2009
Senior Member
no

(2) and (3) should give you the same result,
but (1) navigates from the model to the metamodel and thus will give you the metamodels resource
Re: Differences in URI values [message #1751846 is a reply to message #1751844] Mon, 16 January 2017 08:01 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
sorry, i am not very familiar with the terminology.
what is the difference between model and metamodel?
what are the instances where the URI in model differs from the one in metamodel?
Re: Differences in URI values [message #1751847 is a reply to message #1751846] Mon, 16 January 2017 08:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 10325
Registered: July 2009
Senior Member
an easy analogy would be the terms classes and objects/instances

in emf lets say there is a class Person that has/owns an Adress what has an Attribute name
you have a Person "Hugo" that lives at "AStreet".

having the "AStreet" in hand "eContainer" will gives you "Hugo"
but eContainingFeature will give you "Field adress of Type Adress of Class Person"

i recommend some basic reading on EMF
Re: Differences in URI values [message #1751848 is a reply to message #1751847] Mon, 16 January 2017 08:39 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Ok, thanks for the info.

Is there a way to set the eResource details? I found eSet() that will set the eContainingFeature. How to set the eResource variable?
Re: Differences in URI values [message #1751849 is a reply to message #1751848] Mon, 16 January 2017 09:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 10325
Registered: July 2009
Senior Member
you do it by added the root eobject to the resource.
but that should happend automatically.

can you elaborate on what you are doing?
Re: Differences in URI values [message #1751851 is a reply to message #1751849] Mon, 16 January 2017 09:16 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I have two different but similar grammars.

Kids
-> name
-> address

Child
-> name
-> address

Kids is the old grammar. Then, I have to support the Child grammar. However, I have to treat both Kids and Child classes as one.
Thus, during transform, I add all the Child objects into the Kids object.
During generation and validation, I have to know the file and line number where each entry is configured.
So, I have this code:

for(m: rs.allContents.toIterable.filter(typeof(Child))) //rs is a ResourceSet
		{
			val x = MyDslFactory::eINSTANCE.createKids
			x.name = m.name
			x.address = m.address
			x.eSet(x.eContainingFeature, m.eContainingFeature)
			aKidsList.add(x)
		}


I haven't found any way to set the resource so I can retrieve the URI information later. How to do it?
Re: Differences in URI values [message #1751854 is a reply to message #1751851] Mon, 16 January 2017 09:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 10325
Registered: July 2009
Senior Member
which uri information? the one of m or the one of aKidsLists owner?
Re: Differences in URI values [message #1751859 is a reply to message #1751854] Mon, 16 January 2017 10:29 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I want to copy the URI information of m to x.
Re: Differences in URI values [message #1751861 is a reply to message #1751859] Mon, 16 January 2017 10:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 10325
Registered: July 2009
Senior Member
then you have to create a string placeholder for that
Re: Differences in URI values [message #1751862 is a reply to message #1751861] Mon, 16 January 2017 10:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 10325
Registered: July 2009
Senior Member
our you create a source cross reference for that

MyObject: ..... sourceEObject=[ecore::EObject|EObject] ...

Re: Differences in URI values [message #1751867 is a reply to message #1751862] Mon, 16 January 2017 10:46 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 67
Registered: January 2016
Location: Kiel
Member

It's still unclear what you are trying to do but, you can create and attach EAdapters to EObject if you want to attach additional information.
Re: Differences in URI values [message #1752025 is a reply to message #1751867] Wed, 18 January 2017 03:02 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Thanks for the info. In the end, I decided to change the grammar as it is simpler to implement.

I noticed that the containing feature is also in the container itself.
Thus, is it safe to assume that for an object x:
x.eContainingFeature is always equal to x.eContainer.eContainingFeature?
Re: Differences in URI values [message #1752029 is a reply to message #1752025] Wed, 18 January 2017 03:45 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 28285
Registered: July 2009
Senior Member
No, this isn't a safe general assumption. The first is the feature of the container of x that actually contains x, i.e., you could call x.eContainer.eGet(x.eContainingFeature) and expect to find x in the result. The second is the feature that contains the container of x. They might be the same feature, but generally not because generally the container will have a completely different set of features because it's a completely different class of object.
Previous Topic:Ecore and GenModel annotation not found in xcore files
Next Topic:Xtext Summit @ EclipseCon France
Goto Forum:
  


Current Time: Tue Mar 28 00:54:06 GMT 2017

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

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