Latest v2.6.6
Enhancements
- Add typescript support to prettier-plugin-java (#692 by @ntnyq )
Fixes
v2.6.0
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
v2.5.0
Enhancements
Fixes
- No longer ignore whole block when prettier-ignore at start (#603 by @jtkiesel)
Miscellaneous
v2.4.0
Enhancements
- Supports Java 21 record pattern (#611 by @jtkiesel)
- Supports Java 21 preview feature: unnamed class compilation unit (JEP 445) (#615)
v2.3.1
Fixes
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
v2.2.0
Enhancements
- Upgrade prettier version to Prettier v3
v2.1.0
Enhancements
- Support for require-pragma option (Issue #573 closed with #574)
Thanks to @yannick-paz for the contribution !
public class Example {
private int test = -1;
}
public class Example {
private int test = -1;
}
public class Example {
private int test = -1;
}
public class Example {
private int test = -1;
}
Fixes
- Break long assignments after equals (Issue #527 closed with #564)
Thanks to @jtkiesel for the fix !
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();
}
}
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();
}
}
v2.0.0
Breaking changes
- Drop support of Node.js 12
Enhancements
- Support pattern matching guards (Issue #535 closed with #559)
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;
};
}
}
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
open module org.myorg.module {
requires some.required.module;
exports org.myorg.module.exportpackage1;
exports org.myorg.module.exportpackage2;
}
open module org.myorg.module {
requires some.required.module;
exports org.myorg.module.exportpackage1;
exports org.myorg.module.exportpackage2;
}
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
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 abstract static sealed class SealedParent {}
non-sealed interface Inner {}
public abstract static non-sealed class SealedParent {}
static final class SealedChild extends SealedParent {}
}
- Fix incorrect reformating of type bounds in a generic extends clause (Issue #536 closed with #537)
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) {}
}
public class Foo<T> {
public <U extends @NotNullT> void example(U u) {}
public <U extends com.java.Any.@NotNullT> void example(U u) {}
}
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
Fixes
- Fix parsing of nested sealed and non-sealed classes (Issue #522 closed with #523)
public class SealedClasses {
public abstract static sealed class SealedParent permits SealedChild {}
static final class SealedChild extends SealedParent {}
}
public class NestedSealedClasses {
public abstract static sealed class SealedParent permits SealedChild {}
static final class SealedChild extends SealedParent {}
}
v1.6.0
Enhancements
- Improve formatting of records parameters with annotations
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")
Status status,
@NotNull Integer number
) {}
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")
Status status,
@NotNull Integer number
) {}
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")
Status status,
@NotNull Integer number
) {}
Fixes
- Fix casting with additional bounds
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);
}
}
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
);
}
}
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
Enhancements
Split record parameters on several lines if they do not fit on a single line (#509)
public record Person(
String firstName,
String lastName,
String email,
String phoneNumber,
String streetAddress,
String city,
String state,
String zipCode
) {}
public record Person(
String firstName,
String lastName,
String email,
String phoneNumber,
String streetAddress,
String city,
String state,
String zipCode
) {}
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)
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();
};
}
}
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)
public class ComplexGenericClass<
BEAN extends AbstractBean & BeanItemSelect<BEANTYPE>,
BEANTYPE,
CONFIG extends BeanConfig<BEAN, BEANTYPE, CONFIG>
> {}
public class ComplexGenericClass<
BEAN extends AbstractBean & BeanItemSelect<BEANTYPE>,
BEANTYPE,
CONFIG extends BeanConfig<BEAN, BEANTYPE, CONFIG>
> {}
public class ComplexGenericClass<
BEAN extends AbstractBean & BeanItemSelect<BEANTYPE>,
BEANTYPE,
CONFIG extends BeanConfig<BEAN, BEANTYPE, CONFIG>
> {}
v1.4.0
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
Fixes
- Fix interface member detection to support inner records
(From @rnorth: #492)
- Remove yarn-error.log file from releases
v1.3.0
Enhancements
- Add a space after generic constructor type parameters (#485)
public <T> GenericConstructor(T genericParameter) {}
public <T>GenericConstructor(T genericParameter) {}
public <T> GenericConstructor(T genericParameter) {}
v1.2.0
Enhancements
- Supports of instance of pattern matching (#476)
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);
}
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)
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;
}
}
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;
}
}
Miscellaneous
v1.1.1
Fixes
- Fix parsing records inside class declarations
and records with simplified constructors
(#470)
Miscellaneous
- Update links to Chevrotain library (From @Austin-Scott: #472)
v1.1.0
Enhancements
- Supports of Records (#460)
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() {}
}
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() {}
}
v1.0.2
Fixes
- Keep space between annotation and type identifiers in unannClassType expressions (#455)
class T {
SomeClass.@Valid SomeInnerClass someInnerClass = someClass.getInteractions().get(0);
void process(
Map.@NonNull Entry<String, SkeletonConfiguration> entry,
@NonNull Map<String, Object> context
) {}
}
class T {
SomeClass.@ValidSomeInnerClass someInnerClass = someClass
.getInteractions()
.get(0);
void process(
Map.@NonNullEntry<String, SkeletonConfiguration> entry,
@NonNull Map<String, Object> context
) {}
}
class T {
SomeClass.@Valid SomeInnerClass someInnerClass = someClass
.getInteractions()
.get(0);
void process(
Map.@NonNull Entry<String, SkeletonConfiguration> entry,
@NonNull Map<String, Object> context
) {}
}
- Fix inconsistent indentation between chained method on method and new object (#456)
class T {
public void method() {
new Foo(stuff, thing, "auaaaaaaaaa some very long stuff", "some more")
.bar(10);
foo(stuff, thing, "some very longuuuuuuuuuuuuuu stuff", "some more")
.bar(10);
}
}
class T {
public void method() {
new Foo(stuff, thing, "auaaaaaaaaa some very long stuff", "some more")
.bar(10);
foo(stuff, thing, "some very longuuuuuuuuuuuuuu stuff", "some more")
.bar(10);
}
}
class T {
public void method() {
new Foo(stuff, thing, "auaaaaaaaaa some very long stuff", "some more")
.bar(10);
foo(stuff, thing, "some very longuuuuuuuuuuuuuu stuff", "some more")
.bar(10);
}
}
- Fix unstable formatting for method invocations with only comments (#457)
class T {
public void method() {
Arrays.asList(
);
}
}
class T {
public void method() {
Arrays.asList(
);
}
}
class T {
public void method() {
Arrays.asList(
);
}
}
Miscellaneous
- Update lodash dependency to 4.17.21 (#458)
v1.0.1
Fixes
- Correct spaces emplacement in multi-value switch expression case label (#440)
public class Test {
public void test(TestEnum testEnum) {
switch (testEnum) {
case FOO -> System.out.println("Foo!");
case BAR, BAZ -> System.out.println("Not Foo!");
}
}
}
public class Test {
public void test(TestEnum testEnum) {
switch (testEnum) {
case FOO -> System.out.println("Foo!");
case BAR, BAZ -> System.out.println("Not Foo!");
}
}
}
public class Test {
public void test(TestEnum testEnum) {
switch (testEnum) {
case FOO -> System.out.println("Foo!");
case BAR, BAZ -> System.out.println("Not Foo!");
}
}
}
Miscellaneous
- Update prettier dependency to 2.2.1
v1.0.0
Enhancements
void throwException7(String string1, String string2, String string3, String string4) throws RuntimeException {
throw new RuntimeException();
}
void throwException7(
String string1,
String string2,
String string3,
String string4
)
throws RuntimeException {
throw new RuntimeException();
}
void throwException7(
String string1,
String string2,
String string3,
String string4
) throws RuntimeException {
throw new RuntimeException();
}
Fixes
- Parsing of unannPrimitiveType in primary (#421)
Miscellaneous
v0.8.2
Fixes
Revert: Parsing of unannPrimitiveType in primary (#421).
It was causing a breaking change in the java-parser
uses exact dependencies when releasing a new version of java-parser and prettier-plugin-java
v0.8.1
Enhancements
- Generated a type definition for the Java parser (#422)
Fixes
- Wrong indent in some chained methods invocation (#404)
class Indent {
void indetMethod() {
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
);
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo();
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo()
.anotherInvocation(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
);
myInstanceObject
.assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo();
}
}
class Indent {
void indetMethod() {
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
);
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo();
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo()
.anotherInvocation(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
);
myInstanceObject
.assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo();
}
}
- Parsing of unannPrimitiveType in primary (#421)
double[][]::new
double[][]::new
v0.8.0
Enhancements
- Possibility to run the Prettier Java package on every entrypoint defined in the following list (#395):
[
"variableInitializerList",
"block",
"blockStatements",
"blockStatement",
"localVariableDeclarationStatement",
"localVariableDeclaration",
"localVariableType",
"statement",
"statementWithoutTrailingSubstatement",
"emptyStatement",
"labeledStatement",
"expressionStatement",
"statementExpression",
"ifStatement",
"assertStatement",
"switchStatement",
"switchBlock",
"switchCase",
"switchLabel",
"enumConstantName",
"whileStatement",
"doStatement",
"forStatement",
"basicForStatement",
"forInit",
"forUpdate",
"statementExpressionList",
"enhancedForStatement",
"breakStatement",
"continueStatement",
"returnStatement",
"throwStatement",
"synchronizedStatement",
"tryStatement",
"catches",
"catchClause",
"catchFormalParameter",
"catchType",
"finally",
"tryWithResourcesStatement",
"resourceSpecification",
"resourceList",
"resource",
"resourceInit",
"variableAccess",
"isBasicForStatement",
"isLocalVariableDeclaration",
"classDeclaration",
"normalClassDeclaration",
"classModifier",
"typeParameters",
"typeParameterList",
"superclass",
"superinterfaces",
"interfaceTypeList",
"classBody",
"classBodyDeclaration",
"classMemberDeclaration",
"fieldDeclaration",
"fieldModifier",
"variableDeclaratorList",
"variableDeclarator",
"variableDeclaratorId",
"variableInitializer",
"unannType",
"unannPrimitiveType",
"unannReferenceType",
"unannClassOrInterfaceType",
"unannClassType",
"unannInterfaceType",
"unannTypeVariable",
"methodDeclaration",
"methodModifier",
"methodHeader",
"result",
"methodDeclarator",
"receiverParameter",
"formalParameterList",
"formalParameter",
"variableParaRegularParameter",
"variableArityParameter",
"variableModifier",
"throws",
"exceptionTypeList",
"exceptionType",
"methodBody",
"instanceInitializer",
"staticInitializer",
"constructorDeclaration",
"constructorModifier",
"constructorDeclarator",
"simpleTypeName",
"constructorBody",
"explicitConstructorInvocation",
"unqualifiedExplicitConstructorInvocation",
"qualifiedExplicitConstructorInvocation",
"enumDeclaration",
"enumBody",
"enumConstantList",
"enumConstant",
"enumConstantModifier",
"enumBodyDeclarations",
"isClassDeclaration",
"identifyClassBodyDeclarationType",
"isDims",
"constantExpression",
"expression",
"lambdaExpression",
"lambdaParameters",
"lambdaParametersWithBraces",
"lambdaParameterList",
"inferredLambdaParameterList",
"explicitLambdaParameterList",
"lambdaParameter",
"regularLambdaParameter",
"lambdaParameterType",
"lambdaBody",
"ternaryExpression",
"binaryExpression",
"unaryExpression",
"unaryExpressionNotPlusMinus",
"primary",
"primaryPrefix",
"primarySuffix",
"fqnOrRefType",
"fqnOrRefTypePartRest",
"fqnOrRefTypePartCommon",
"fqnOrRefTypePartFirst",
"parenthesisExpression",
"castExpression",
"primitiveCastExpression",
"referenceTypeCastExpression",
"newExpression",
"unqualifiedClassInstanceCreationExpression",
"classOrInterfaceTypeToInstantiate",
"typeArgumentsOrDiamond",
"diamond",
"methodInvocationSuffix",
"argumentList",
"arrayCreationExpression",
"arrayCreationDefaultInitSuffix",
"arrayCreationExplicitInitSuffix",
"dimExprs",
"dimExpr",
"classLiteralSuffix",
"arrayAccessSuffix",
"methodReferenceSuffix",
"identifyNewExpressionType",
"isLambdaExpression",
"isCastExpression",
"isPrimitiveCastExpression",
"isReferenceTypeCastExpression",
"isRefTypeInMethodRef",
"interfaceDeclaration",
"normalInterfaceDeclaration",
"interfaceModifier",
"extendsInterfaces",
"interfaceBody",
"interfaceMemberDeclaration",
"constantDeclaration",
"constantModifier",
"interfaceMethodDeclaration",
"interfaceMethodModifier",
"annotationTypeDeclaration",
"annotationTypeBody",
"annotationTypeMemberDeclaration",
"annotationTypeElementDeclaration",
"annotationTypeElementModifier",
"defaultValue",
"annotation",
"elementValuePairList",
"elementValuePair",
"elementValue",
"elementValueArrayInitializer",
"elementValueList",
"identifyInterfaceBodyDeclarationType",
"identifyAnnotationBodyDeclarationType",
"isSimpleElementValueAnnotation",
"literal",
"integerLiteral",
"floatingPointLiteral",
"booleanLiteral",
"moduleName",
"packageName",
"typeName",
"expressionName",
"methodName",
"packageOrTypeName",
"ambiguousName",
"compilationUnit",
"ordinaryCompilationUnit",
"modularCompilationUnit",
"packageDeclaration",
"packageModifier",
"importDeclaration",
"typeDeclaration",
"moduleDeclaration",
"moduleDirective",
"requiresModuleDirective",
"exportsModuleDirective",
"opensModuleDirective",
"usesModuleDirective",
"providesModuleDirective",
"requiresModifier",
"isModuleCompilationUnit",
"primitiveType",
"numericType",
"integralType",
"floatingPointType",
"referenceType",
"classOrInterfaceType",
"classType",
"interfaceType",
"typeVariable",
"dims",
"typeParameter",
"typeParameterModifier",
"typeBound",
"additionalBound",
"typeArguments",
"typeArgumentList",
"typeArgument",
"wildcard",
"wildcardBounds"
];
Fixes
Re-Writer
Fix formatting of empty enums to not insert commas when trailing-comma is enabled #385)
public enum Enum {}
public enum Enum {
}
public enum Enum {}
Fix formatting of enum with comments #385)
Miscellaneous
- Update prettier dependency to 2.0.5 (#379) & (#400)
- Binary artefacts creation for each release (#399)
- Document Maven plugin (#394)
-
v0.7.1
Fixes
Re-Writer
- Fix stable formatting for fields and methods with annotations (#369)
Miscellaneous
v0.7.0
Enhancements
Re-Writer
Add support for trailing commas option (#354)
For enumerations:
public enum Enum {
ONE,
TWO,
THREE
}
public enum Enum {
ONE,
TWO,
THREE
}
For arrays:
public class T {
void t() {
int[] ints = { 1, 2, 3 };
int[] ints = {
aVeryLongArrayValue,
anotherVeryLongArrayValue,
andYetAnotherVeryLongArrayValue
};
}
}
public class T {
void t() {
int[] ints = { 1, 2, 3 };
int[] ints = {
aVeryLongArrayValue,
anotherVeryLongArrayValue,
andYetAnotherVeryLongArrayValue
};
}
}
By default, remove trailing comma in arrays (#354)
public class T {
void t() {
int[] ints = { 1, 2, 3 };
}
}
public class T {
void t() {
int[] ints = { 1, 2, 3 };
}
}
Allow blank lines in enumerations' constant list (#350)
public enum OtherEnum {
ONE,
TWO,
THREE,
FOUR,
FIVE,
SIX
}
public enum OtherEnum {
ONE,
TWO,
THREE,
FOUR,
FIVE,
SIX
}
Always add a blank line between an enumeration's constants and declarations (#351)
public enum EnumWithExtraCommaAndEnumBodyDeclarations {
THIS_IS_GOOD("abc"),
THIS_IS_FINE("abc");
public static final String thisWillBeDeleted = "DELETED";
}
public enum EnumWithExtraCommaAndEnumBodyDeclarations {
THIS_IS_GOOD("abc"),
THIS_IS_FINE("abc");
public static final String thisWillBeDeleted = "DELETED";
}
Fixes
Re-Writer
Fix blank lines with empty statements (#360)
public class Test {
public TestField testField;
@Override
public void someMethod() {}
}
public class Test {
public TestField testField;
@Override
public void someMethod() {}
}
public class Test {
public TestField testField;
@Override
public void someMethod() {}
}
Fix line wrapping in switch statements (#359)
public String shouldWrapEvenForSmallSwitchCases() {
switch (answer) { case "YES": return "YES"; default: return "NO"; }
}
public String shouldWrapEvenForSmallSwitchCases() {
switch (answer) { case "YES": return "YES"; default: return "NO"; }
}
public String shouldWrapEvenForSmallSwitchCases() {
switch (answer) {
case "YES":
return "YES";
default:
return "NO";
}
}
Fix stable reformating of comments in binary expression (#353)
public boolean binaryOperationWithComments() {
boolean a = one || two >> 1
||
three;
boolean b = one || two >> 1
||
three;
boolean c = one || two >> 1
|| three;
return a || b || c;
}
public boolean binaryOperationWithComments() {
boolean a =
one ||
two >> 1
||
three;
boolean b =
one ||
two >> 1
||
three;
boolean c =
one ||
two >> 1
||
three;
return a || b || c;
}
public boolean binaryOperationWithComments() {
boolean a =
one ||
two >> 1 ||
three;
boolean b =
one ||
two >> 1 ||
three;
boolean c =
one ||
two >> 1 ||
three;
return a || b || c;
}
Fix comments indentation when they are at the end of a block: indent the comments based on the block they are in (#345)
public class T {
int i;
}
public class T {
int i;
}
public class T {
int i;
}
Fix respect of blank lines with comments (#348)
void t() {
int i;
int j;
}
void t() {
int i;
int j;
}
void t() {
int i;
int j;
}
v0.6.0
Enhancements
Parser
- Optimize parser performance by reducing the global maxLookahead to 1 (#321)
Re-Writer
Support // formater-off
and // formater-on
comments to disable formating on some parts of the code (#323)
public class PrettierIgnoreClass {
public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) {
}
}
public class PrettierIgnoreClass {
public void myMethod(
int param1,
int param2,
int param3,
int param4,
int param5,
int param6,
int param7,
int param8,
int param9,
int param10
) {}
}
public class PrettierIgnoreClass {
public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) {
}
}
public class PrettierIgnoreClass {
public void myMethod(
int param1,
int param2,
int param3,
int param4,
int param5,
int param6,
int param7,
int param8,
int param9,
int param10
) {}
}
Print enums' values on their own line (#319)
public enum Enum {
SOME_ENUM,
ANOTHER_ENUM,
LAST_ENUM
}
public enum Enum {
SOME_ENUM,
ANOTHER_ENUM,
LAST_ENUM
}
Remove extra comma in enums (#319)
public enum EnumWithExtraComma {
SOME_ENUM,
ANOTHER_ENUM,
LAST_ENUM
}
public enum Enum {
SOME_ENUM,
ANOTHER_ENUM,
LAST_ENUM
}
Respect case when sorting imports (#330)
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.concurrent.*;
import java.util.concurrent.*;
import java.util.concurrent.Semaphore;
import java.util.concurrent.Semaphore;
import java.util.functioN.Consumer;
import java.util.functioN.Consumer;
import java.util.function.Consumer;
import java.util.function.Consumer;
import java.util.function.ConsumerTwo;
import java.util.function.ConsumerTwo;
Improve formatting of lambda expressions when they break (#333)
public void lambdaWithoutBracesWhichBreak() {
call(x -> foo.isVeryVeryVeryLongConditionTrue() &&
foo.isAnotherVeryVeryLongConditionTrue());
}
public void lambdaWithoutBracesWhichBreak() {
call(
x ->
foo.isVeryVeryVeryLongConditionTrue() &&
foo.isAnotherVeryVeryLongConditionTrue()
);
}
Don't indent binary operators (#329)
@Annotation(
"This operation with two very long string should break" +
"in a very nice way"
)
public void method() {}
@Annotation(
"This operation with two very long string should break" +
"in a very nice way"
)
public void method() {}
Improve ternary expression line wrapping (#318)
return (columnIndex == null) ? ImmutableMap.<R, V>of()
: new Column(columnIndex);
return (columnIndex == null)
? ImmutableMap.<R, V>of()
: new Column(columnIndex);
Improve formatting of variable initialization with methods (#332)
boolean willDrop = predictDropResponse.getSendResult().isIgnorableFailure() || predictDropResponse.getSendResult().isFatalError();
boolean willDrop =
predictDropResponse.getSendResult().isIgnorableFailure() ||
predictDropResponse.getSendResult().isFatalError();
Fixes
Parser
- Fix brackets considered as a cast with byte shifting or comparison
(e.g.
(left) << right
or (left) < right
). The parser is now able to parse completely the ElasticSearch Repository (#325)
Re-Writer
Fix stable reformating of variable declaration with comments (#336)
Map<String, String> map =
new HashMap<>(someMethodThatReturnsAMap());
Map<String, String> map =
new HashMap<>(someMethodThatReturnsAMap());
Miscellaneous
- Check stable reformating for repositories in tests (#335)
- Add template for submitting an issue (#340)
v0.5.1
Fixes
- Fix parsing and printing of variable arity parameters with dims (#310)
- Fix package size (#317)
v0.5.0
Enhancements
Parser
- Optimize parser initialisation (#295)
Re-Writer
Sort class, method and field modifiers (#302). See this doc for more information
final private static @Annotation String S = "abc";
@Annotation
private static final String S = "abc";
Fixes
Parser
- Fix lexer gap: align use of
transitive
keyword with the specs (#297)
Re-Writer
- Fix enforcement of printWidth for nodes with leading comments (#278)
- Fix switch statements indentation with comments (#278)
- Fix unstable formating when wrapping in return statements (#294)
- Fix variable arity parameters formating (#304)
Miscellaneous
- Drop testing on Node 8 and add testing on Node 13
v0.4.0
Enhancements
public enum EnumWhichBreak {
ONE_VALUE,
TWO_VALUE,
THREE_VALUE,
FOUR_VALUE,
FIVE_VALUE,
SIX_VALUE,
SEVEN_VALUE,
EIGHT_VALUE,
NINE_VALUE,
TEN_VALUE
}
would be transformed in:
public enum EnumWhichBreak {
ONE_VALUE,
TWO_VALUE,
THREE_VALUE,
FOUR_VALUE,
FIVE_VALUE,
SIX_VALUE,
SEVEN_VALUE,
EIGHT_VALUE,
NINE_VALUE,
TEN_VALUE
}
When
public enum EnumWhichNotBreak {
SOME_ENUM,
ANOTHER_ENUM,
LAST_ENUM
}
would be kept as it is:
public enum EnumWhichNotBreak {
SOME_ENUM,
ANOTHER_ENUM,
LAST_ENUM
}
- Remove extra semicolons in enums when possible (#266)
public enum EnumWhichNotBreak {
SOME_ENUM,
ANOTHER_ENUM,
LAST_ENUM
}
would be transformed in:
public enum EnumWhichNotBreak {
SOME_ENUM,
ANOTHER_ENUM,
LAST_ENUM
}
when the following is kept as it is:
public enum Enum {
THIS_IS_GOOD("abc"), THIS_IS_FINE("abc");
public static final String thisWillBeDeleted = "DELETED";
private final String value;
public Enum(String value) {
this.value = value;
}
public String toString() {
return "STRING";
}
- Organise imports according to Google style (#273 and #281)
package my.own.pkg;
import static abc.def;
import static abc.def.Another;
import static abc.def.Something;
import static java.utils.*;
import static something.Different;
import abc.def;
import abc.def.Another;
import abc.def.Something;
import java.utils.*;
import one.last;
import something.Different;
public class PackageAndImports {}
is transformed in:
package my.own.pkg;
import static abc.def;
import static abc.def.Another;
import static abc.def.Something;
import static java.utils.*;
import static something.Different;
import abc.def;
import abc.def.Another;
import abc.def.Something;
import java.utils.*;
import one.last;
import something.Different;
public class PackageAndImports {}
- Better display of local variable declarations (#283)
public boolean localVariableDeclarationWhichBreak() {
@Nullable final BackupStatus lastStatus = BackupStatus.fromDbValue(backupRepository.getLastStatus());
final BackupStatus lastStatus = BackupStatus.fromDbValue(backupRepository.getLastStatus());
@Nullable BackupStatus lastStatus = BackupStatus.fromDbValue(backupRepository.getLastStatus());
BackupStatus lastStatus = BackupStatus.fromDbValue(backupRepository.getLastStatus());
}
public boolean localVariableDeclarationWhichDoNotBreak() {
@Nullable final BackupStatus lastStatus = value;
final BackupStatus lastStatus = value;
@Nullable BackupStatus lastStatus = value;
BackupStatus lastStatus = value;
}
is transformed in:
public boolean localVariableDeclarationWhichBreak() {
@Nullable
final BackupStatus lastStatus = BackupStatus.fromDbValue(
backupRepository.getLastStatus()
);
final BackupStatus lastStatus = BackupStatus.fromDbValue(
backupRepository.getLastStatus()
);
@Nullable
BackupStatus lastStatus = BackupStatus.fromDbValue(
backupRepository.getLastStatus()
);
BackupStatus lastStatus = BackupStatus.fromDbValue(
backupRepository.getLastStatus()
);
}
public boolean localVariableDeclarationWhichDoNotBreak() {
@Nullable
final BackupStatus lastStatus = value;
final BackupStatus lastStatus = value;
@Nullable
BackupStatus lastStatus = value;
BackupStatus lastStatus = value;
}
- Improve binary operations indentation (#255):
Obj newObject = new Object().something().more().and().that().as().well().but().not().something();
Object.test.creation thisObject = classWithName.invocationOne().invocationTwo();
Object.test.creation thisObject1 = classWithName.invocationOne(argument1, argument2, argument3);
Object.test.creation thisObject2 = classWithName.invocationOne(argument1, argument2, argument3).invocationTwo();
Object.test.creation thisObject3 = classWithName.invocationOne().invocationTwo(argument1, argument2, argument3);
Object.test.creation thisObject4 = classWithName.invocationOne(argument1, argument2, argument3).invocationTwo(argument1, argument2);
Object.test.creation thisObject5 = classWithName.invocationOne(argument1WithAVeryVeryVeryVeryLongName, argument2, argument3).attributeOne.attributeTwo
.invocationTwo(argument1, argument2).attributeThree.invocationThree();
Object.test.creation thisObject6 = classWithName.invocationOne(argument1, argument2,
argument3).attributeOne.attributeTwo.invocationTwo(argument1, argument2).attributeThree.invocationThree();
is transformed in:
Obj newObject = new Object()
.something()
.more()
.and()
.that()
.as()
.well()
.but()
.not()
.something();
Object.test.creation thisObject = classWithName
.invocationOne()
.invocationTwo();
Object.test.creation thisObject1 = classWithName.invocationOne(
argument1,
argument2,
argument3
);
Object.test.creation thisObject2 = classWithName
.invocationOne(argument1, argument2, argument3)
.invocationTwo();
Object.test.creation thisObject3 = classWithName
.invocationOne()
.invocationTwo(argument1, argument2, argument3);
Object.test.creation thisObject4 = classWithName
.invocationOne(argument1, argument2, argument3)
.invocationTwo(argument1, argument2);
Object.test.creation thisObject5 = classWithName
.invocationOne(
argument1WithAVeryVeryVeryVeryLongName,
argument2,
argument3
)
.attributeOne.attributeTwo.invocationTwo(argument1, argument2)
.attributeThree.invocationThree();
Object.test.creation thisObject6 = classWithName
.invocationOne(argument1, argument2, argument3)
.attributeOne.attributeTwo.invocationTwo(argument1, argument2)
.attributeThree.invocationThree();
- Improve return statement rendering (#255)
Object returnSomethingWhichDoNotBreak() {
return oneVariable + secondVariable;
}
Object returnSomethingWhichBreak() {
return oneVariable + secondVariable + thirdVariable + fourthVariable + fifthVariable + sixthVariable + seventhVariable;
}
Object returnSomethingWhichBreakAndAlreadyInParenthesis() {
return (
oneVariable +
secondVariable +
thirdVariable +
fourthVariable +
fifthVariable +
sixthVariable +
seventhVariable
);
}
is transformed in:
Object returnSomethingWhichDoNotBreak() {
return oneVariable + secondVariable;
}
Object returnSomethingWhichBreak() {
return (
oneVariable +
secondVariable +
thirdVariable +
fourthVariable +
fifthVariable +
sixthVariable +
seventhVariable
);
}
Object returnSomethingWhichBreakAndAlreadyInParenthesis() {
return (
oneVariable +
secondVariable +
thirdVariable +
fourthVariable +
fifthVariable +
sixthVariable +
seventhVariable
);
}
Fixed
- Add missing
lodash
dependency (#265)
- Fix blocks comments formatting (#280)