Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eclipse java code style formatter: prevent line wrapping for the special cases

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); }
like image 428
sdorof Avatar asked Aug 17 '26 00:08

sdorof


1 Answers

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.

like image 57
Steampunkery Avatar answered Aug 19 '26 13:08

Steampunkery