Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » how to open a file in the actual project
how to open a file in the actual project [message #1162222] Wed, 30 October 2013 08:27 Go to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
in the XTEND for my generator i want to access files which are under the roof of my current project.
I evaluate resource.URI.trimSegments(2) which will result in "platform:\resource\abf"
but this does not work well with my
new FileReader(resource.URI.trimSegments(2)+"\\!includefiles\\a.sampletext")

How can I get an absolute path to my project directory out of "platform:\resource\abf"?
Or is theresomething which returns the path of the workspace aka "platform:\resource"
Re: how to open a file in the actual project [message #1162241 is a reply to message #1162222] Wed, 30 October 2013 08:43 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Check out the URIConverter registered to the ResourceSet. You should not rely on FileReader nor on Windows style paths, just URIs and getting an InputStream for them.

Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: how to open a file in the actual project [message #1162273 is a reply to message #1162241] Wed, 30 October 2013 09:11 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Hi Karsten,

I have not found a hint in the XTEXT or XTEND documentation.
as I am a novice on the XTEND,XTEXT,JAVA,... I have problems to interpret the infos I googled.

Perhaps I have caused some confusion: This "includefile" are not to be included in the generator and evaluated there, its just a term from the customer which denotes some files with simple text to be added to the generated output here and there.

Can you give me a little help how to implement this?

Under my project roof, I have a directory "boilerplatetex" where "a.sampletext" resides.
In my generator, I want to grab the contents of this file, modify it and add it to the output.

Its just some boilerplate text to be included; depending on customers choice, these boilerplatefiles may later reside in a fixed directory on a windows fileserver or under the different projects. I need an option to handle all of these situations.

TIA, Uli

[Updated on: Wed, 30 October 2013 09:31]

Report message to a moderator

Re: how to open a file in the actual project [message #1162355 is a reply to message #1162222] Wed, 30 October 2013 10:16 Go to previous messageGo to next message
Thomas Fritsch is currently offline Thomas FritschFriend
Messages: 28
Registered: April 2013
Location: Germany
Junior Member
May be this helps.

import org.eclipse.xtext.ui.refactoring.impl.ProjectUtil

@Inject ProjectUtil projectUtil

val inputStream = projectUtil.findFileStorage(uri, false).getContents()
Re: how to open a file in the actual project [message #1162363 is a reply to message #1162355] Wed, 30 October 2013 10:25 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Hi Thomas,

I added your lines to my generator.xtend, but got a lot off error markers
Re: how to open a file in the actual project [message #1162472 is a reply to message #1162222] Wed, 30 October 2013 11:55 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Maybe I have to explain a little bit more:

I work on my generator.xtend.

Then I launch an eclipse runtime.

There I have a java project
abf
|--src
. |- abc.mydsl

|--textfiles
. |- my.text

And I create another java project XYZ
XYZ
|--src
. |- abc.mydsl

|--textfiles
. |- my.text

The src/abc.mydsl is the one I edit and save.
With the doGenerate, I want to access the textfiles/my.text of the project my DSL file belongs to

[Updated on: Wed, 30 October 2013 11:57]

Report message to a moderator

Previous Topic:EnumLiteralDeclaration: problem getting the values of the reference
Next Topic:Data Type rule help? [RESOLVED]
Goto Forum:
  


Current Time: Tue Apr 16 04:06:18 GMT 2024

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

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

Back to the top