3

Is there a possibility to prevent line wrapping for the some special cases in the Eclipse code style fromatter? I mean in particular the javafx property definition blocks. By default the code style are next:

private StringProperty name = new SimpleStringProperty();

  public StringProperty nameProperty() {
    return name;
  }

  public String getName() {
    return name.get();
  }

  public void setName(String value) {
    this.name.set(value);
  }

I attempts provide more compact style without line wrapping:

  private StringProperty name = new SimpleStringProperty();
  public StringProperty nameProperty() { return name; }
  public String getName() { return name.get(); }
  public void setName(String value) { this.name.set(value); }
sdorof
  • 525
  • 6
  • 21
  • 4
    Way around would be formatting those sections yourself and using "[How to turn off the Eclipse code formatter for certain sections of Java code?](https://stackoverflow.com/q/1820908)" to prevent formatter from doing its job there. – Pshemo Oct 06 '17 at 18:22

1 Answers1

2

Yes, it is possible to prevent line wrapping. Like @Pshemo said, you can toggle the eclipse formatter. So your above code becomes:

// @formatter:off
private StringProperty name = new SimpleStringProperty();
public StringProperty nameProperty() { return name; }
public String getName() { return name.get(); }
public void setName(String value) { this.name.set(value); }
// @formatter:on

The comments turn the formatter off then on again to prevent the formatter from changing that code when you press ctrl + shift + f.

Steampunkery
  • 3,839
  • 2
  • 19
  • 28