Skip to main content



      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 04:27 Go to next message
Eclipse UserFriend
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 04:43 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: how to open a file in the actual project [message #1162273 is a reply to message #1162241] Wed, 30 October 2013 05:11 Go to previous messageGo to next message
Eclipse UserFriend
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 05:31] by Moderator

Re: how to open a file in the actual project [message #1162355 is a reply to message #1162222] Wed, 30 October 2013 06:16 Go to previous messageGo to next message
Eclipse UserFriend
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 06:25 Go to previous messageGo to next message
Eclipse UserFriend
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 07:55 Go to previous message
Eclipse UserFriend
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 07:57] by Moderator

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


Current Time: Sat Jul 05 06:17:42 EDT 2025

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

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

Back to the top