prettier-java

Prettier Java Plugin

APACHE-2.0 License

Downloads
1.3M
Stars
1K
Committers
33

Bot releases are hidden (Show)

prettier-java -

Published by clementdessoude almost 4 years ago

Enhancements

  • Support of Java 15 ! 🚀

  • Support of Text blocks

  • Support of new switch rules and yield statements

  • Improve throws rendering (From @jhaber: #384)

// Input

void throwException7(String string1, String string2, String string3, String string4) throws RuntimeException {
  throw new RuntimeException();
}

// Prettier 0.8.3

void throwException7(
  String string1,
  String string2,
  String string3,
  String string4
)
  throws RuntimeException {
  throw new RuntimeException();
}

// Prettier 1.0.0

void throwException7(
  String string1,
  String string2,
  String string3,
  String string4
) throws RuntimeException {
  throw new RuntimeException();
}

Fixes

  • Parsing of unannPrimitiveType in primary (#421)

Miscellaneous

  • Update dependencies
prettier-java - v0.8.3

Published by pascalgrimaud about 4 years ago

prettier-java - v0.8.2

Published by pascalgrimaud about 4 years ago

prettier-java - v0.8.1

Published by clementdessoude about 4 years ago

Changelog v0.8.1

Enhancements

  • Generated a type definition for the Java parser (#422)

Fixes

  • Wrong indent in some chained methods invocation (#404)
// Input
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();


  }
}
// Output
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)
// Throws in Prettier 0.8.0
double[][]::new

// Prettier 0.9.0
double[][]::new
prettier-java - v0.8.0

Published by clementdessoude over 4 years ago

Changelog - 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)
    // Input
    public enum Enum {
    }
    
    // Prettier v0.7.1
    public enum Enum {
      ,
    }
    
    // Prettier v0.8.0
    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)
prettier-java - v0.7.1

Published by clementdessoude over 4 years ago

Latest v0.7.1

Fixes

Re-Writer

  • Fix stable formatting for fields and methods with annotations (#369)

Miscellaneous

prettier-java -

Published by clementdessoude over 4 years ago

CHANGELOG v0.7.0

Enhancements

Re-Writer

  • Add support for trailing commas option (#354)

    For enumerations:

    // Input
    public enum Enum {
      ONE, TWO, THREE
    }
    
    // Output
    public enum Enum {
      ONE,
      TWO,
      THREE,
    }
    

    For arrays:

    // Input
    public class T {
      void t() {
        int[] ints = { 1, 2, 3, };
        int[] ints = { aVeryLongArrayValue, anotherVeryLongArrayValue, andYetAnotherVeryLongArrayValue };
      }
    }
    
    // Output
    public class T {
      void t() {
        int[] ints = { 1, 2, 3 };
        int[] ints = {
          aVeryLongArrayValue,
          anotherVeryLongArrayValue,
          andYetAnotherVeryLongArrayValue,
        };
      }
    }
    
  • By default, remove trailing comma in arrays (#354)

    // Input
    public class T {
      void t() {
        int[] ints = { 1, 2, 3, };
      }
    }
    
    // Output
    public class T {
      void t() {
        int[] ints = { 1, 2, 3 };
      }
    }
    
  • Allow blank lines in enumerations' constant list (#350)

    // Input
    public enum OtherEnum {
      ONE, TWO,
    
      THREE,
    
    
    
      FOUR,
      /* Five */
      FIVE,
    
      /* Six */
      SIX
    
    
    }
    
    // Output
    public enum OtherEnum {
      ONE,
      TWO,
    
      THREE,
    
      FOUR,
      /* Five */
      FIVE,
    
      /* Six */
      SIX
    }
    
  • Always add a blank line between an enumeration's constants and declarations (#351)

    // This input
    public enum EnumWithExtraCommaAndEnumBodyDeclarations {
      THIS_IS_GOOD("abc"),
      THIS_IS_FINE("abc");
      public static final String thisWillBeDeleted = "DELETED";
    }
    
    // will be formatted to this output
    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)

    // Input
    public class Test {
      public TestField testField;;
    
      @Override
      public void someMethod() {}
    }
    
    // Output (v0.6.0)
    public class Test {
      public TestField testField;
      @Override
      public void someMethod() {}
    }
    
    // Output (v0.7.0)
    public class Test {
      public TestField testField;
    
      @Override
      public void someMethod() {}
    }
    
  • Fix line wrapping in switch statements (#359)

    // Input
    public String shouldWrapEvenForSmallSwitchCases() {
      switch (answer) { case "YES": return "YES"; default: return "NO"; }
    }
    // Output (v0.6.0)
    public String shouldWrapEvenForSmallSwitchCases() {
      switch (answer) { case "YES": return "YES"; default: return "NO"; }
    }
    
    // Output (v0.7.0)
    public String shouldWrapEvenForSmallSwitchCases() {
      switch (answer) {
        case "YES":
          return "YES";
        default:
          return "NO";
      }
    }
    
  • Fix stable reformating of comments in binary expression (#353)

    // Input
    public boolean binaryOperationWithComments() {
      boolean a = one || two >> 1 // one
        // two
        // three
        || // five
        // four
        three;
    
      boolean b = one || two >> 1 // one
        // two
        // three
        ||
        three;
    
      boolean c = one || two >> 1 // one
        // two
        // three
        || three;
    
      return a || b || c;
    }
    
    // Output (v0.6.0)
    public boolean binaryOperationWithComments() {
      boolean a =
        one ||
        two >> 1 // two // one
        // three
        || // five
        // four
        three;
    
      boolean b =
        one ||
        two >> 1 // two // one
        // three
        ||
        three;
    
      boolean c =
        one ||
        two >> 1 // two // one
        // three
        ||
        three;
    
      return a || b || c;
    }
    
    // Output (v0.7.0)
    public boolean binaryOperationWithComments() {
      boolean a =
        one ||
        two >> 1 || // one
        // five
        // two
        // three
        // four
        three;
    
      boolean b =
        one ||
        two >> 1 || // one
        // two
        // three
        three;
    
      boolean c =
        one ||
        two >> 1 || // one
        // two
        // three
        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)

    // Input
    public class T {
      int i;
      // comment
    }
    
    // Output (v0.6.0)
    public class T {
      int i;
    // comment
    }
    
    // Output (v0.7.0)
    public class T {
      int i;
      // comment
    }
    
  • Fix respect of blank lines with comments (#348)

    // Input
    void t() {
      int i;
      // comment
      int j;
    }
    
    // Output (v0.6.0)
    void t() {
      int i;
    
      // comment
      int j;
    }
    
    // Output (v0.7.0)
    void t() {
      int i;
      // comment
      int j;
    }
    
prettier-java -

Published by clementdessoude almost 5 years ago

prettier-java -

Published by clementdessoude almost 5 years ago

Package Rankings
Top 1.1% on Npmjs.org
Top 8.17% on Proxy.golang.org
Badges
Extracted from project README
npm-prettier-plugin-java npm-java-parser