Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » How to get the name of the .model file and the folder it resides in?
How to get the name of the .model file and the folder it resides in? [message #1862300] Thu, 23 November 2023 08:28 Go to next message
Ehsan Ahmad is currently offline Ehsan AhmadFriend
Messages: 37
Registered: April 2018
Member
Hi,
I am trying to generate code from using EGL and EGX. I generated class and file name must be same as the file name of the model and it must be placed in a generated folder with the name same as the folder of the model file.

For example, the model file name is "betaFile.model" and it is the folder "alphaFolder". The generator must create a folder "alphaFolder" and then place "betaFile.java" in it.

How to access the model file name "betaFile" and its container "alphaFolder" so that i can set the target in the EGX file as follows:

target: "src/" + package + "/" + c.name + ".java"
to get
src/alphaFolder/betFile.java

thanks
Re: How to get the name of the .model file and the folder it resides in? [message #1862303 is a reply to message #1862300] Thu, 23 November 2023 10:38 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 Ehsan,

If you're using EMF and your model is named M in the run configuration,
M.resource.uri
should return the URI from which the model was loaded.

Thanks,
Dimitris
Re: How to get the name of the .model file and the folder it resides in? [message #1862307 is a reply to message #1862303] Thu, 23 November 2023 18:05 Go to previous messageGo to next message
Ehsan Ahmad is currently offline Ehsan AhmadFriend
Messages: 37
Registered: April 2018
Member
Hi Dimitris,
Yes, I am using EMF and it worked.
So, I must hard code the model name (M) in my EOL program.
Is there any other way of getting URI so that the same EOL program can work with other models as well?
Thank you.

[Updated on: Thu, 23 November 2023 18:06]

Report message to a moderator

Re: How to get the name of the .model file and the folder it resides in? [message #1862309 is a reply to message #1862307] Thu, 23 November 2023 20:18 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

You can get the URI of the model containing any (EMF-based) model element using
element.eResource().uri


Thanks,
Dimitris
Re: How to get the name of the .model file and the folder it resides in? [message #1862312 is a reply to message #1862309] Thu, 23 November 2023 22:57 Go to previous messageGo to next message
Ehsan Ahmad is currently offline Ehsan AhmadFriend
Messages: 37
Registered: April 2018
Member
Dear Dimitris,

Perfect.

The following statements are working for me.
MyModel.all.first.eResource().uri.trimFileExtension().lastSegment.println(); 
MyModel.all.first.eResource().uri.segment(State.all.first.eResource().uri.segmentCount-2).println();


MyModel is the top most element in the model.

Thank you

[Updated on: Thu, 23 November 2023 23:04]

Report message to a moderator

Re: How to get the name of the .model file and the folder it resides in? [message #1862333 is a reply to message #1862312] Sun, 26 November 2023 09:38 Go to previous message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

That's great - thanks for sharing you solution!

Cheers,
Dimitris
Previous Topic:Installing Epsilon with Dockerfile
Next Topic:How to query Sequence<Any> for enum in EMF model?
Goto Forum:
  


Current Time: Sat Apr 27 10:15:33 GMT 2024

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

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

Back to the top