Skip to content

Releases: jhipster/prettier-java

v1.6.2

25 May 13:26
Compare
Choose a tag to compare

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) {}
}

v1.6.1

06 Jan 13:16
Compare
Choose a tag to compare

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 {}
}

v1.6.0

14 Nov 11:21
Compare
Choose a tag to compare

Latest v1.6.0

Enhancements

  • Improve formatting of records parameters with annotations
// Input
public record Record(
    @JsonSerialize(using = StatusSerializer.class, nullsUsing = NullSerializer.class)
    @Schema(type = "integer", description = "Some fancy description")
    Status status,

    @NotNull
    Integer number
) {}

public record Record(
    @JsonSerialize(using = StatusSerializer.class, nullsUsing = NullSerializer.class)
    @Schema(type = "integer", description = "Some fancy description")
    // comment
    Status status,


    // another comment
    @NotNull
    Integer number
) {}

// Prettier v1.5.0
public record Record(
  @JsonSerialize(
    using = StatusSerializer.class,
    nullsUsing = NullSerializer.class
  ) @Schema(
    type = "integer",
    description = "Some fancy description"
  ) Status status,
  @NotNull Integer number
) {}

public record Record(
  @JsonSerialize(
    using = StatusSerializer.class,
    nullsUsing = NullSerializer.class
  ) @Schema(type = "integer", description = "Some fancy description") // comment
  Status status,
  // another comment
  @NotNull Integer number
) {}

// Prettier v1.6.0
public record Record(
  @JsonSerialize(
    using = StatusSerializer.class,
    nullsUsing = NullSerializer.class
  )
  @Schema(type = "integer", description = "Some fancy description")
  Status status,

  @NotNull Integer number
) {}

public record Record(
  @JsonSerialize(
    using = StatusSerializer.class,
    nullsUsing = NullSerializer.class
  )
  @Schema(type = "integer", description = "Some fancy description")
  // comment
  Status status,

  // another comment
  @NotNull Integer number
) {}

Fixes

  • Fix casting with additional bounds
// Input
class Example {
  void should_cast_with_single_element() {
    var myElem = (int) othrElement;
    var myElem = (A) othrElement;
    var myElem = (A) (othrElement, value) -> othrElement + value;
    var myElem = (Aaeaozeaonzeoazneaozenazonelkadndpndpazdpazdpazdpazdpazeazpeaazdpazdpazpdazdpa) othrElement;
  }

  void should_cast_with_additional_bounds() {
    foo((A & B) obj);
    foo((A & B & C) obj);
    foo((Aaeaozeaonzeoazneaozenazone & Bazoieoainzeonaozenoazne & Cjneazeanezoanezoanzeoaneonazeono) obj);
    foo((Aaeaozeaonzeoazneaozenazone & Bazoieoainzeonaozenoazne & Cjneazeanezoanezoanzeoaneonazeono) (othrElement, value) -> othrElement + value);
  }
}

// Prettier v1.5.0
class Example {

  void should_cast_with_single_element() {
    var myElem = (int) othrElement;
    var myElem = (A) othrElement;
    var myElem = (A) (othrElement, value) -> othrElement + value;
    var myElem = (Aaeaozeaonzeoazneaozenazonelkadndpndpazdpazdpazdpazdpazeazpeaazdpazdpazpdazdpa) othrElement;
  }

  void should_cast_with_additional_bounds() {
    foo((A) & B obj);
    foo((A) & B& C obj);
    foo(
      (Aaeaozeaonzeoazneaozenazone) & Bazoieoainzeonaozenoazne& Cjneazeanezoanezoanzeoaneonazeono obj
    );
    foo(
      (Aaeaozeaonzeoazneaozenazone) & Bazoieoainzeonaozenoazne& Cjneazeanezoanezoanzeoaneonazeono (
          othrElement,
          value
        ) ->
        othrElement + value
    );
  }
}

// Prettier v1.6.0
class Example {

  void should_cast_with_single_element() {
    var myElem = (int) othrElement;
    var myElem = (A) othrElement;
    var myElem = (A) (othrElement, value) -> othrElement + value;
    var myElem = (Aaeaozeaonzeoazneaozenazonelkadndpndpazdpazdpazdpazdpazeazpeaazdpazdpazpdazdpa) othrElement;
  }

  void should_cast_with_additional_bounds() {
    foo((A & B) obj);
    foo((A & B & C) obj);
    foo(
      (
        Aaeaozeaonzeoazneaozenazone
        & Bazoieoainzeonaozenoazne
        & Cjneazeanezoanezoanzeoaneonazeono
      ) obj
    );
    foo(
      (
        Aaeaozeaonzeoazneaozenazone
        & Bazoieoainzeonaozenoazne
        & Cjneazeanezoanezoanzeoaneonazeono
      ) (othrElement, value) -> othrElement + value
    );
  }
}

v1.5.0

16 Oct 09:28
Compare
Choose a tag to compare

Latest v1.5.0

Enhancements

  • Split record parameters on several lines if thez do not fit on a single line (#509)

    // Input
    public record Person(
        String firstName, String lastName, String email,
        String phoneNumber,
        String streetAddress,
        String city,
        String state,
        String zipCode
    ) {}
    
    // Prettier 1.4.0
    public record Person(
      String firstName, String lastName, String email, String phoneNumber, String streetAddress, String city, String state, String zipCode
    ) {}
    
    // Prettier 1.5.0
    public record Person(
      String firstName,
      String lastName,
      String email,
      String phoneNumber,
      String streetAddress,
      String city,
      String state,
      String zipCode
    ) {}
  • Support pattern matching in switch statements preview feature (#511)

    // Input
    class T {
      static String formatterPatternSwitch(Object o) {
        return switch (o) {
          case
    
            Integer i ->
    
    
            String.format("int %d", i);
          case Long l    -> String.format("long %d", l);
          case Double d  -> String.format("double %f", d);
          case String s  -> String.format("String %s", s);
          case TOTO  -> String.format("TOTO %s", o);
          case null -> String.format("Null !");
          case default -> String.format("Default !");
          default        -> o.toString();
        };
      }
    }
    
    // Output
    class T {
      static String formatterPatternSwitch(Object o) {
        return switch (o) {
          case Integer i -> String.format("int %d", i);
          case Long l -> String.format("long %d", l);
          case Double d -> String.format("double %f", d);
          case String s -> String.format("String %s", s);
          case TOTO -> String.format("TOTO %s", o);
          case null -> String.format("Null !");
          case default -> String.format("Default !");
          default -> o.toString();
        };
      }
    }
  • Improve printing of class with long typeParameterList (#512)

    // Input
    public class ComplexGenericClass<BEAN extends AbstractBean & BeanItemSelect<BEANTYPE>, BEANTYPE, CONFIG extends BeanConfig<BEAN, BEANTYPE, CONFIG>> {}
    
    // Prettier 1.4.0
    public class ComplexGenericClass<BEAN extends AbstractBean & BeanItemSelect<BEANTYPE>, BEANTYPE, CONFIG extends BeanConfig<BEAN, BEANTYPE, CONFIG>> {}
    
    // Prettier 1.5.0
    public class ComplexGenericClass<
      BEAN extends AbstractBean & BeanItemSelect<BEANTYPE>,
      BEANTYPE,
      CONFIG extends BeanConfig<BEAN, BEANTYPE, CONFIG>
    > {}

Full Changelog: https://github.com/jhipster/prettier-java/compare/v1.4.0...prettier-plugin-java@1.5.0

v1.4.0

29 Aug 14:28
Compare
Choose a tag to compare

Enhancements

  • Improve method invocation with lambda parameters (#497)

Fixes

  • Fix parsing of static imports of yield methods (#499)
  • Improve java-parser types signatures (#496)

v1.3.1

30 Jul 16:08
Compare
Choose a tag to compare

Fixes

  • Fix interface member detection to support inner records
    (From @rnorth: #492)
  • Remove yarn-error.log file from releases

v1.3.0

20 Jun 13:58
Compare
Choose a tag to compare

Enhancements

  • Add a space after generic constructor type parameters (#485)
// Input
public <T> GenericConstructor(T genericParameter) {}

// Prettier 1.2.0
public <T>GenericConstructor(T genericParameter) {}

// Prettier 1.2.1
public <T> GenericConstructor(T genericParameter) {}

v1.2.0

13 Jun 16:44
Compare
Choose a tag to compare

Enhancements

  • Supports of instance of pattern matching (#476)
// Input
if (o instanceof Integer i || p instanceof Point || q instanceof Circle c || r instanceof Square) {
  formatted = String.format("int %d", i);
} else if (o instanceof Long l) {
  formatted = String.format("long %d", l);
} else if (o instanceof Double d) {
  formatted = String.format("double %f", d);
} else if (o instanceof String s) {
  formatted = String.format("String %s", s);
}

// Output
if (
  o instanceof Integer i ||
  p instanceof Point ||
  q instanceof Circle c ||
  r instanceof Square
) {
  formatted = String.format("int %d", i);
} else if (o instanceof Long l) {
  formatted = String.format("long %d", l);
} else if (o instanceof Double d) {
  formatted = String.format("double %f", d);
} else if (o instanceof String s) {
  formatted = String.format("String %s", s);
}
  • Supports of sealed classes and interfaces (#478)
// Input
public sealed class Rectangle
  implements Shape
  permits Square {

  private final double length;
  private final double height;

  public Rectangle(double length, double height) {
    this.length = length;
    this.height = height;
  }

  @Override
  public double area() {
    return length * height;
  }
}

// Output
public sealed class Rectangle implements Shape permits Square {

  private final double length;
  private final double height;

  public Rectangle(double length, double height) {
    this.length = length;
    this.height = height;
  }

  @Override
  public double area() {
    return length * height;
  }
}

Miscallenous

v1.1.1

25 May 06:38
Compare
Choose a tag to compare

Fixes

  • Fix parsing records inside class declarations
    and records with simplified constructors
    (#470)

Miscallenous

v1.1.0

19 May 07:26
Compare
Choose a tag to compare

Enhancements

  • Supports of Records (#460)
// Input
public record Pet(
    @NotNull String name, int age, String... others, Object @Nullable... errorMessageArgs
  ) {
  public Pet {
    if (age < 0) {
      throw new IllegalArgumentException("Age cannot be negative");
    }

    if (name == null || name.isBlank()) {
      throw new IllegalArgumentException("Name cannot be blank");
    }
  }

  public void test() {}
}

// Output
public record Pet(
  @NotNull String name, int age, String... others, Object @Nullable... errorMessageArgs
) {
  public Pet {
    if (age < 0) {
      throw new IllegalArgumentException("Age cannot be negative");
    }

    if (name == null || name.isBlank()) {
      throw new IllegalArgumentException("Name cannot be blank");
    }
  }

  public void test() {}
}