Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Differences in URI values
Differences in URI values [message #1751843] Mon, 16 January 2017 02:39 Go to next message
Eclipse UserFriend
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 02:40] by Moderator

Re: Differences in URI values [message #1751844 is a reply to message #1751843] Mon, 16 January 2017 02:52 Go to previous messageGo to next message
Eclipse UserFriend
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 03:01 Go to previous messageGo to next message
Eclipse UserFriend
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 03:06 Go to previous messageGo to next message
Eclipse UserFriend
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 03:39 Go to previous messageGo to next message
Eclipse UserFriend
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 04:00 Go to previous messageGo to next message
Eclipse UserFriend
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 04:16 Go to previous messageGo to next message
Eclipse UserFriend
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 04:59 Go to previous messageGo to next message
Eclipse UserFriend
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 05:29 Go to previous messageGo to next message
Eclipse UserFriend
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 05:30 Go to previous messageGo to next message
Eclipse UserFriend
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 05:32 Go to previous messageGo to next message
Eclipse UserFriend
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 05:46 Go to previous messageGo to next message
Eclipse UserFriend
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] Tue, 17 January 2017 22:02 Go to previous messageGo to next message
Eclipse UserFriend
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] Tue, 17 January 2017 22:45 Go to previous message
Eclipse UserFriend
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: Mon May 12 06:35:06 EDT 2025

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

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

Back to the top