Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Newline formatting wrong
Newline formatting wrong [message #1777979] Thu, 07 December 2017 04:32 Go to next message
Eclipse UserFriend
I try to format my Xtext based source code.
It contains as line separator the 2 codes 0d 0a (hex values).

When I format some source files then in some lines of the formatted source there is only the code 0a (hex value), the 0d is missing.

I just use the standard formatting API 2.

What can be the cause of my problem?
Re: Newline formatting wrong [message #1777980 is a reply to message #1777979] Thu, 07 December 2017 04:39 Go to previous messageGo to next message
Eclipse UserFriend
are you on windows?
have a look at
FormatterPreferenceValuesProvider and see that it provides as line separator?
Re: Newline formatting wrong [message #1777983 is a reply to message #1777980] Thu, 07 December 2017 05:13 Go to previous messageGo to next message
Eclipse UserFriend
I am on Windows.

How can I access the provider during a Junit test?

And how can I set it to an OS independant value? At least during the test.

[Updated on: Thu, 07 December 2017 05:20] by Moderator

Re: Newline formatting wrong [message #1777985 is a reply to message #1777983] Thu, 07 December 2017 05:44 Go to previous messageGo to next message
Eclipse UserFriend
how do you test formatting.

class XbaseFormatterTester extends FormatterTester {

def void assertFormattedExpression((FormatterTestRequest)=>void test) {
val prefix = "{" + Strings.newLine
val postfix = Strings.newLine + "}"
val (FormatterTestRequest)=>void setup = [
test.apply(it)
preferences[
put(FormatterPreferenceKeys.maxLineWidth, 80)
]
expectation = prefix + expectationOrToBeFormatted.toString.trim.indent("\t") + postfix
toBeFormatted = prefix + toBeFormatted.toString.trim.indent("\t") + postfix
]
assertFormatted(setup)
}

as you can see FormatterTestRequest allows to set preferences
Re: Newline formatting wrong [message #1777987 is a reply to message #1777985] Thu, 07 December 2017 06:05 Go to previous messageGo to next message
Eclipse UserFriend
I just use a plain test class with these annotations:

@RunWith(XtextRunner)
@InjectWith(Fop2InjectorProvider)
class FO2FormatterTest extends Assert {

and these injections

@Inject
extension ParseHelper<Model>
@Inject
extension ISerializer


And the test looks like this:

assertEquals(expected, input.parse.serialize(SaveOptions.newBuilder.format().getOptions()))

where expected is the expected formatted string and input is the unformatted string.


Is there some documentation on how to use the FormatterTestHelper ?

[Updated on: Thu, 07 December 2017 06:14] by Moderator

Re: Newline formatting wrong [message #1777991 is a reply to message #1777987] Thu, 07 December 2017 06:29 Go to previous messageGo to next message
Eclipse UserFriend
no there is no documentation. you need to have a look at ecisiting usages e.g. in the xtext codebase
Re: Newline formatting wrong [message #1778032 is a reply to message #1777991] Fri, 08 December 2017 06:36 Go to previous messageGo to next message
Eclipse UserFriend
I fixed my test environment by converting all \r\n occurences to \n and then comparing the expected and formatted results.

In my production environment the linefeed is determined by the project settings and this is always \n.

[Updated on: Fri, 08 December 2017 06:38] by Moderator

Re: Newline formatting wrong [message #1778169 is a reply to message #1778032] Mon, 11 December 2017 08:14 Go to previous message
Eclipse UserFriend
Hi

Since EMF 2.9 the line ending is determined by

saveOptions.put(Resource.OPTION_LINE_DELIMITER, "\n");

passed to one of the (XML)Resource.save() methods. You can try to be clever about re-using old file styles, project/workspace/system preferences, but IMHO just use "\n" regardless. (I'm a Windows user).

Set breakpoints on the save to discover why your test environment is 'wrong'.

Regards

Ed Willink


Previous Topic:Generating piece of code after selecting proposal provider in DSL editor.
Next Topic:Maven parallel build with Xtext
Goto Forum:
  


Current Time: Fri Jul 25 09:12:32 EDT 2025

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

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

Back to the top