Prettier Java Plugin
Thanks to @jtkiesel for all of these contributions !
// 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;}
// 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();
}
}
// 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;
};
}
}
public class Test {
public static final String REGEX = "^\s$";
}
// 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;
}
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 {}
}
// 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) {}
}
// 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 {}
}