Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Newline formatting wrong
Newline formatting wrong [message #1777979] Thu, 07 December 2017 09:32 Go to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
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 09:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
are you on windows?
have a look at
FormatterPreferenceValuesProvider and see that it provides as line separator?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Newline formatting wrong [message #1777983 is a reply to message #1777980] Thu, 07 December 2017 10:13 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
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 10:20]

Report message to a moderator

Re: Newline formatting wrong [message #1777985 is a reply to message #1777983] Thu, 07 December 2017 10:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Newline formatting wrong [message #1777987 is a reply to message #1777985] Thu, 07 December 2017 11:05 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
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 11:14]

Report message to a moderator

Re: Newline formatting wrong [message #1777991 is a reply to message #1777987] Thu, 07 December 2017 11:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
no there is no documentation. you need to have a look at ecisiting usages e.g. in the xtext codebase

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Newline formatting wrong [message #1778032 is a reply to message #1777991] Fri, 08 December 2017 11:36 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
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 11:38]

Report message to a moderator

Re: Newline formatting wrong [message #1778169 is a reply to message #1778032] Mon, 11 December 2017 13:14 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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: Thu Mar 28 15:42:07 GMT 2024

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

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

Back to the top