Prettier Java Versions Save

Prettier Java Plugin

[email protected]

2 months ago

Enhancements

Fixes

  • Consistent break after equals (Issue #638 fixed by #641 by @jtkiesel)
  • Properly break and indent lambda with comments (Issue #581 fixed by #604 by @jtkiesel)
  • Do not fail on constructor and method receiver parameter (Issue #607 fixed by #642 by @jtkiesel)
  • No break in single-block switch case (Issue #635 fixed by #636 by @jtkiesel)
  • Non-block if/else statements are now kept on their own lines (Issue #631 fixed by #633 by @jtkiesel)

Misc

[email protected]

5 months ago

Latest v2.5.0

Enhancements

Fixes

  • No longer ignore whole block when prettier-ignore at start (#603 by @jtkiesel)

Miscellaneous

[email protected]

6 months ago

Latest v2.4.0

Enhancements

  • Supports Java 21 record pattern (#611 by @jtkiesel)
  • Supports Java 21 preview feature: unnamed class compilation unit (JEP 445) (#615)

[email protected]

8 months ago

Fixes

  • Correct indentation of assignment operations (#602 by @jtkiesel)

[email protected]

8 months ago

Latest v2.3.0

Enhancements

  • Break long lines on type arguments (#584)
  • Break and indent binary expression with cast properly (#587)
  • Adjust indentation of multiline string (Issue #593 fixed with #596)
  • Improves binary expression formatting (#594)
  • Supports JLS annotation style (#586

Thanks to @jtkiesel for all of these contributions !

Fixes

  • Fix browser compatibility issue when run in browser (Issue #597 fixed with #598) Thanks to @magic-akari for the contribution

[email protected]

10 months ago

Enhancements

  • Upgrade prettier version to Prettier v3

[email protected]

1 year ago

Latest v2.1.0

Enhancements

  • Support for require-pragma option (Issue #573 closed with #574) Thanks to @yannick-paz for the contribution !
// Input
/**
 * @prettier
 */
public class Example { private int test=-1;}

// Output with require-pragma option activated
/**
 * @prettier
 */
public class Example {
  private int test = -1;
}

// Input
public class Example { private int test=-1;}

// Output with require-pragma option activated
public class Example { private int test=-1;}

Fixes

  • Break long assignments after equals (Issue #527 closed with #564) Thanks to @jtkiesel for the fix !
// Input
class Example {

  void example() {
    Object aParticularlyLongAndObnoxiousNameForIllustrativePurposes = new Object()
      .someMethod();

    Object[] aParticularlyLongAndObnoxiousNameForIllustrativePurposes2 = new Object[] {
      new Object(),
      new Object()
    };

    Object aParticularlyLongAndObnoxiousNameForIllustrativePurposes3 = SomeClass.someStaticMethod();

    Object aParticularlyLongAndObnoxiousNameForIllustrativePurposes = someMethod()
      .anotherMethod();

    Object aParticularlyLongAndObnoxiousNameForIllustrativePurposes = anotherValue !=
      null
      ? anotherValue
      : new Object();
  }
}

// Output
class Example {

  void example() {
    Object aParticularlyLongAndObnoxiousNameForIllustrativePurposes =
      new Object().someMethod();

    Object[] aParticularlyLongAndObnoxiousNameForIllustrativePurposes2 =
      new Object[] { new Object(), new Object() };

    Object aParticularlyLongAndObnoxiousNameForIllustrativePurposes3 =
      SomeClass.someStaticMethod();

    Object aParticularlyLongAndObnoxiousNameForIllustrativePurposes =
      someMethod().anotherMethod();

    Object aParticularlyLongAndObnoxiousNameForIllustrativePurposes =
      anotherValue != null ? anotherValue : new Object();
  }
}

[email protected]

1 year ago

Breaking changes

  • Drop support of Node.js 12

Enhancements

  • Support pattern matching guards (Issue #535 closed with #559)
// Input
class T {

    void test(Buyer other) {
        return switch (other) {
            case null -> true;
            case Buyer b && this.bestPrice > b.bestPrice -> true;
            case Buyer b && this.bestPrice > b.bestPrice -> {
                return true;
            }
            case (Buyer b && this.bestPrice > b.bestPrice) -> true;
            case Buyer b && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice -> true;
            case Buyer b && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice -> {
                return true;
            }
            case (Buyer b && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice) -> true;
            case (Buyer b && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice && this.bestPrice > b.bestPrice) -> {
                return true;
            }
            default -> false;
        };
    }
}

// Output
class T {
  void test(Buyer other) {
    return switch (other) {
      case null -> true;
      case Buyer b && this.bestPrice > b.bestPrice -> true;
      case Buyer b && this.bestPrice > b.bestPrice -> {
        return true;
      }
      case (Buyer b && this.bestPrice > b.bestPrice) -> true;
      case Buyer b &&
        this.bestPrice > b.bestPrice &&
        this.bestPrice > b.bestPrice &&
        this.bestPrice > b.bestPrice &&
        this.bestPrice > b.bestPrice -> true;
      case Buyer b &&
        this.bestPrice > b.bestPrice &&
        this.bestPrice > b.bestPrice &&
        this.bestPrice > b.bestPrice &&
        this.bestPrice > b.bestPrice -> {
        return true;
      }
      case (
          Buyer b &&
          this.bestPrice > b.bestPrice &&
          this.bestPrice > b.bestPrice &&
          this.bestPrice > b.bestPrice &&
          this.bestPrice > b.bestPrice
        ) -> true;
      case (
          Buyer b &&
          this.bestPrice > b.bestPrice &&
          this.bestPrice > b.bestPrice &&
          this.bestPrice > b.bestPrice &&
          this.bestPrice > b.bestPrice
        ) -> {
        return true;
      }
      default -> false;
    };
  }
}

Fixes

  • Fix parsing of escaped spaces in strings (Issue #541 closed with #543)
public class Test {

  public static final String REGEX = "^\s$";

}
  • Fix unwanted space in "exports"-statement in module-info.java (Issue #550 closed with #551) Thanks to @BjornJaspers for the fix
// Input
open module org.myorg.module {
  requires some.required.module;

  exports org.myorg.module.exportpackage1;
  exports org.myorg.module.exportpackage2;
}
// Prettier 1.6.2
open module org.myorg.module {
  requires some.required.module;

  exports org.myorg.module.exportpackage1 ;
  exports org.myorg.module.exportpackage2 ;
}
// Prettier 1.6.3
open module org.myorg.module {
  requires some.required.module;

  exports org.myorg.module.exportpackage1;
  exports org.myorg.module.exportpackage2;
}

Misc

  • doc: add VSCode Java import order configuration (#546) Thanks to @derkoe for the contribution

[email protected]

1 year ago

Latest v1.6.2

Fixes

  • Fix parsing of nested sealed and non-sealed classes & interfaces inside interfaces (Issue #533 closed with #538)

public interface Test {
    sealed interface Inner {}

    public static sealed abstract class SealedParent {}

    non-sealed interface Inner {}

    public static non-sealed abstract class SealedParent {}

    final static class SealedChild extends SealedParent {}
}

  • Fix incorrect reformating of type bounds in a generic extends clause (Issue #536 closed with #537)
// Input
public class Foo<T> {

  public <U extends @NotNull T> void example(U u) {}

  public <U extends com.java.Any.@NotNull T> void example(U u) {}
}

// Prettier 1.6.1
public class Foo<T> {

  public <U extends @NotNullT> void example(U u) {}

  public <U extends com.java.Any.@NotNullT> void example(U u) {}
}

// Prettier 1.6.2
public class Foo<T> {

  public <U extends @NotNull T> void example(U u) {}

  public <U extends com.java.Any.@NotNull T> void example(U u) {}
}

[email protected]

2 years ago

Latest v1.6.1

Fixes

  • Fix parsing of nested sealed and non-sealed classes (Issue #522 closed with #523)

// Input
public class SealedClasses {
  public static sealed abstract class SealedParent permits SealedChild {}

  final static class SealedChild extends SealedParent {}
}

// Output
public class NestedSealedClasses {

  public abstract static sealed class SealedParent permits SealedChild {}

  static final class SealedChild extends SealedParent {}
}