Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to set file encoding of generated file from my dsl file
How to set file encoding of generated file from my dsl file [message #818388] Sun, 11 March 2012 14:42 Go to next message
Andy Ma is currently offline Andy MaFriend
Messages: 12
Registered: August 2011
Junior Member
Hi there,

E.g: In xtext StateMachine flower dsl example, it transform file of a state machine dsl to a java file, I want to set this java file to encoding "UTF-8" when transforming. In default this file's encoding is inherit from java workspace.

In the xtext documentation there have some encoding presentations,but it seems not hit my requirement, I want to set the generated java file from a state machine dsl file, not the generate file of "src-gen","xtend-gen" in the xtext project.

Is there anyone knows how to solve this problem?
Thanks in advance!
Re: How to set file encoding of generated file from my dsl file [message #818477 is a reply to message #818388] Sun, 11 March 2012 18:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you may have to bind a custom IFileSystemAccess for this e.g. sublassing EclipseResourceFileSystemAccess2 if you want to change it for the BuilderParticipant in the UI.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to set file encoding of generated file from my dsl file [message #819158 is a reply to message #818477] Mon, 12 March 2012 15:15 Go to previous messageGo to next message
Andy Ma is currently offline Andy MaFriend
Messages: 12
Registered: August 2011
Junior Member
Hi Christian,

Thank you for your quick response, I tried as you suggested, but with no success, it seems the binding doesn't success, for method getInputStream, it always use from EclipseResourceFileSystemAccess2, not MyFileSystemAccess, can you help to check where the problem is, what I have done is as follow, thank you very much.

1. I created a class MyFileSystemAccess inherited from EclipseResourceFileSystemAccess2 in package org.eclipse.xtext.example.fowlerdsl like:
public class MyFileSystemAccess extends EclipseResourceFileSystemAccess2 {

	@Override
	protected StringInputStream getInputStream(String contentsAsString,
			String encoding) {
	
		return super.getInputStream(contentsAsString, "UTF-16");
	}
}

2.I bind MyFileSystemAccess to IFileSystemAccess in file StatemachineRuntimeModule:
public class StatemachineRuntimeModule extends org.eclipse.xtext.example.fowlerdsl.AbstractStatemachineRuntimeModule {
	@Override
	public void configure(Binder binder) {
				
		binder.bind(IFileSystemAccess.class).to(MyFileSystemAccess.class);
		super.configure(binder);
	}
}

[Updated on: Mon, 12 March 2012 15:18]

Report message to a moderator

Re: How to set file encoding of generated file from my dsl file [message #819321 is a reply to message #819158] Mon, 12 March 2012 19:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

are you executing this from the ui or standalone. your binding is standalone only.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to set file encoding of generated file from my dsl file [message #819508 is a reply to message #819321] Tue, 13 March 2012 01:40 Go to previous messageGo to next message
Andy Ma is currently offline Andy MaFriend
Messages: 12
Registered: August 2011
Junior Member
Hi Christian,

Currently I am testing it with eclipse UI, running as an eclipse application and create a test project to test the fowlerdsl transforming to java file. What else should I do?
Re: How to set file encoding of generated file from my dsl file [message #819540 is a reply to message #819508] Tue, 13 March 2012 02:48 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-13-03 2:40, Andy Ma wrote:
> Hi Christian,
>
> Currently I am testing it with eclipse UI, running as an eclipse
> application and create a test project to test the fowlerdsl transforming
> to java file. What else should I do?

Did you try binding it in the ui module?

- henrik
Re: How to set file encoding of generated file from my dsl file [message #819621 is a reply to message #819540] Tue, 13 March 2012 05:49 Go to previous messageGo to next message
Andy Ma is currently offline Andy MaFriend
Messages: 12
Registered: August 2011
Junior Member
No,I didn't bind it in the UI module, I bind it in the runtime module, in my code StatemachineRuntimeModule.
Re: How to set file encoding of generated file from my dsl file [message #819641 is a reply to message #819621] Tue, 13 March 2012 06:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Bind it in the UI module too

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to set file encoding of generated file from my dsl file [message #819681 is a reply to message #819641] Tue, 13 March 2012 07:34 Go to previous message
Andy Ma is currently offline Andy MaFriend
Messages: 12
Registered: August 2011
Junior Member
Hi all,
I found the problem, it works now, I need to bind MyFileSystemAccess to EclipseResourceFileSystemAccess2, not to IFileSystemAccess, and there's no need to bind it in UI module.

Thanks for all your support.Smile
Previous Topic:Xtend- Copy files
Next Topic:Decision can match input such as "'.'" using multiple alternatives: 1, 2
Goto Forum:
  


Current Time: Tue Apr 16 19:15:30 GMT 2024

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

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

Back to the top