Skip to main content



      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 10:42 Go to next message
Eclipse UserFriend
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 14:01 Go to previous messageGo to next message
Eclipse UserFriend
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
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 11:15 Go to previous messageGo to next message
Eclipse UserFriend
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 11:18] by 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 15:25 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

~Christian
Re: How to set file encoding of generated file from my dsl file [message #819508 is a reply to message #819321] Mon, 12 March 2012 21:40 Go to previous messageGo to next message
Eclipse UserFriend
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] Mon, 12 March 2012 22:48 Go to previous messageGo to next message
Eclipse UserFriend
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 01:49 Go to previous messageGo to next message
Eclipse UserFriend
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 02:31 Go to previous messageGo to next message
Eclipse UserFriend
Bind it in the UI module too
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 03:34 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 15:14:41 EDT 2025

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

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

Back to the top