1

I can't seem to find the formatter settings to prevent Eclipse from putting block style declarations on the same line.

For example, if I type the code like this:

private string[] myData={
    "someValue1",
    "someValue2",
    "someValue3",
    "someValue4",
    "someValue5",
    "someValue5"
}

Upon running Eclipse's Auto Formatter, the previous declaration then looks like:

private string[] myData={
    "someValue1", "someValue2", "someValue3", "someValue4", "someValue5", "someValue5"};

Is there a way to avoid this?

TN888
  • 7,659
  • 9
  • 48
  • 84
user3308774
  • 1,354
  • 4
  • 16
  • 20
  • possible duplicate of [eclipse conditional formatting braces only for multiple lines](http://stackoverflow.com/questions/5665247/eclipse-conditional-formatting-braces-only-for-multiple-lines) – Chandrayya G K May 28 '14 at 05:40

2 Answers2

1

You can toggle the formatter by adding these tags:

//@formatter:off
private string[] myData = {
    "someValue1",
    "someValue2",
    "someValue3",
    "someValue4",
    "someValue5",
    "someValue5"
}
//@formatter:on
martinez314
  • 12,162
  • 5
  • 36
  • 63
1
  • go to your formatter profile to the tab "Line Wrapping".
  • on the list (left) you choose "Array initializers" from "Expressions".
  • then bellow the list you choose "Wrap all elements, every element on a new line" from the "Line wrapping policy":
herrlock
  • 1,454
  • 1
  • 13
  • 16
  • Almost a good answer. This forces Eclipse to do wrap for array initializers with every element on a new line. The OP asked for something different however - to prevent joining in block declarations. That is achievable on the same panel, by clicking "Never join already wrapped lines" – Ordous May 27 '14 at 17:36