├── .github ├── ISSUE_TEMPLATE │ └── --formatting.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── binaries.yml │ ├── copyright-update.yml │ ├── github-ci.yml │ ├── github-pages-deploy.yml │ └── github-pages-test.yml ├── .gitignore ├── .husky └── pre-commit ├── .prettierignore ├── .prettierrc.yaml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── RELEASE.md ├── benchmark └── java-parser │ ├── benchmark.js │ └── package.json ├── docs ├── advanced_usage.md ├── checkstyle │ ├── checkstyle.xml │ └── import-checkstyle-configuration.gif └── intellij_imports_config.png ├── eslint.config.mjs ├── lerna.json ├── logo ├── prettier-java-avatar-dark.svg ├── prettier-java-avatar-light.svg ├── prettier-java-banner-dark.svg ├── prettier-java-banner-light.svg ├── prettier-java-icon-dark.svg ├── prettier-java-icon-light.svg ├── prettier-java-logo-dark.svg ├── prettier-java-logo-light.svg ├── prettier-java-wide-dark.svg └── prettier-java-wide-light.svg ├── package.json ├── packages ├── java-parser │ ├── .gitignore │ ├── .mocharc.cjs │ ├── .npmignore │ ├── README.md │ ├── api.d.ts │ ├── docs │ │ ├── comments.md │ │ └── design.md │ ├── package.json │ ├── resources │ │ └── Unicode │ │ │ ├── Unicode License Agreement.html │ │ │ ├── Unicode License Agreement_fichiers │ │ │ └── standard_styles.css │ │ │ └── UnicodeData.txt │ ├── scripts │ │ ├── clone-samples.js │ │ ├── gen-diagrams.js │ │ ├── generate-signature.js │ │ ├── parse-samples.js │ │ ├── single-sample-runner.js │ │ └── unicode.js │ ├── src │ │ ├── comments.js │ │ ├── index.js │ │ ├── lexer.js │ │ ├── parser.js │ │ ├── productions │ │ │ ├── arrays.js │ │ │ ├── blocks-and-statements.js │ │ │ ├── classes.js │ │ │ ├── expressions.js │ │ │ ├── interfaces.js │ │ │ ├── lexical-structure.js │ │ │ ├── names.js │ │ │ ├── packages-and-modules.js │ │ │ └── types-values-and-variables.js │ │ ├── tokens.js │ │ ├── unicodesets.js │ │ └── utils.js │ └── test │ │ ├── blocks-and-statements │ │ ├── switch-case-spec.js │ │ └── yield-statement-spec.js │ │ ├── bugs-spec.js │ │ ├── classes-spec.js │ │ ├── compilation-unit │ │ └── unnamed-class-compilation-unit-spec.js │ │ ├── pattern-matching │ │ ├── pattern-matching-spec.js │ │ └── unnamed-variables-and-patterns-spec.js │ │ ├── records │ │ └── records-spec.js │ │ ├── samples-spec.js │ │ ├── sealed │ │ └── sealed-spec.js │ │ ├── string-literals.spec.js │ │ ├── template-expression-spec.js │ │ └── test-block-spec.js └── prettier-plugin-java │ ├── .gitignore │ ├── .mocharc.json │ ├── .npmignore │ ├── README.md │ ├── docs │ └── modifiers.md │ ├── index.d.ts │ ├── package.json │ ├── scripts │ ├── clone-samples.js │ ├── single-printer-run │ │ ├── _input.java │ │ └── _output.java │ └── update-test-output.js │ ├── src │ ├── base-cst-printer.ts │ ├── cst-printer.ts │ ├── index.js │ ├── options.js │ ├── parser.js │ ├── printer.js │ ├── printers │ │ ├── arrays.ts │ │ ├── blocks-and-statements.ts │ │ ├── classes.ts │ │ ├── comments │ │ │ ├── comments-utils.ts │ │ │ ├── format-comments.ts │ │ │ └── handle-comments.ts │ │ ├── expressions.ts │ │ ├── interfaces.ts │ │ ├── lexical-structure.ts │ │ ├── names.ts │ │ ├── packages-and-modules.ts │ │ ├── prettier-builder.ts │ │ ├── printer-utils.ts │ │ └── types-values-and-variables.ts │ ├── types │ │ └── utils.ts │ └── utils │ │ ├── index.ts │ │ ├── isEmptyDoc.ts │ │ └── printArgumentListWithBraces.ts │ ├── test-samples │ └── .eslintrc.json │ ├── test │ ├── repository-test │ │ ├── core-test.ts │ │ ├── jhipster-1-test.ts │ │ └── jhipster-2-test.ts │ ├── test-utils.ts │ └── unit-test │ │ ├── annotation_interface_declaration │ │ ├── _input.java │ │ ├── _output.java │ │ └── annotation_interface_declaration-spec.ts │ │ ├── args │ │ ├── _input.java │ │ ├── _output.java │ │ └── args-spec.ts │ │ ├── arrays │ │ ├── _input.java │ │ ├── _output.java │ │ └── arrays-spec.ts │ │ ├── assert │ │ ├── _input.java │ │ ├── _output.java │ │ └── assert-spec.ts │ │ ├── binary_expressions │ │ ├── _input.java │ │ ├── _output.java │ │ └── binary_expressions-spec.ts │ │ ├── blank_lines │ │ ├── _input.java │ │ ├── _output.java │ │ └── blank_lines-spec.ts │ │ ├── bug-fixes │ │ ├── _input.java │ │ ├── _output.java │ │ └── bug-fixes-spec.ts │ │ ├── cast │ │ ├── _input.java │ │ ├── _output.java │ │ └── cast-spec.ts │ │ ├── char_literal │ │ ├── _input.java │ │ ├── _output.java │ │ └── char_literal-spec.ts │ │ ├── classes │ │ ├── _input.java │ │ ├── _output.java │ │ └── multiple_classes-spec.ts │ │ ├── comments │ │ ├── bug-fixes │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── class │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── comments-blocks-and-statements │ │ │ ├── complex │ │ │ │ ├── _input.java │ │ │ │ └── _output.java │ │ │ ├── end-of-block │ │ │ │ ├── _input.java │ │ │ │ └── _output.java │ │ │ ├── if-statement │ │ │ │ ├── _input.java │ │ │ │ └── _output.java │ │ │ └── labeled-statement │ │ │ │ ├── _input.java │ │ │ │ └── _output.java │ │ ├── comments-only │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── comments-spec.ts │ │ ├── edge │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── expression │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── interface │ │ │ ├── _input.java │ │ │ └── _output.java │ │ └── package │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── complex_generic_class │ │ ├── _input.java │ │ ├── _output.java │ │ └── complex_generic_class-spec.ts │ │ ├── constructors │ │ ├── _input.java │ │ ├── _output.java │ │ └── constructors-spec.ts │ │ ├── empty_statement │ │ ├── _input.java │ │ ├── _output.java │ │ └── empty_statement-spec.ts │ │ ├── enum │ │ ├── _input.java │ │ ├── _output.java │ │ └── enum-spec.ts │ │ ├── expressions │ │ ├── _input.java │ │ ├── _output.java │ │ └── expressions-spec.ts │ │ ├── extends_abstract_class │ │ ├── _input.java │ │ ├── _output.java │ │ └── extends_abstract_class-spec.ts │ │ ├── extends_abstract_class_and_implements_interfaces │ │ ├── _input.java │ │ ├── _output.java │ │ └── extends_abstract_class_and_implements_interfaces-spec.ts │ │ ├── for │ │ ├── _input.java │ │ ├── _output.java │ │ └── for-spec.ts │ │ ├── formatter-on-off │ │ ├── begin_with_on │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── class │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── end_with_off │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── inside_block │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── method │ │ │ ├── _input.java │ │ │ └── _output.java │ │ └── multiple │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── generic_class │ │ ├── _input.java │ │ ├── _output.java │ │ └── generic_class-spec.ts │ │ ├── generic_questionmark │ │ ├── _input.java │ │ ├── _output.java │ │ └── generic_questionmark-spec.ts │ │ ├── hello-world │ │ ├── _input.java │ │ ├── _output.java │ │ └── hello-word-spec.ts │ │ ├── if │ │ ├── _input.java │ │ ├── _output.java │ │ └── if-spec.ts │ │ ├── indent │ │ ├── _input.java │ │ ├── _output.java │ │ └── indent-spec.ts │ │ ├── instantiation │ │ ├── _input.java │ │ ├── _output.java │ │ └── instantiation-spec.ts │ │ ├── interface │ │ ├── _input.java │ │ ├── _output.java │ │ └── interface-spec.ts │ │ ├── lambda │ │ ├── _input.java │ │ ├── _output.java │ │ └── lambda-spec.ts │ │ ├── marker_annotations │ │ ├── _input.java │ │ ├── _output.java │ │ └── marker_annotations-spec.ts │ │ ├── member_chain │ │ ├── _input.java │ │ ├── _output.java │ │ └── member_chain-spec.ts │ │ ├── method_reference │ │ ├── _input.java │ │ ├── _output.java │ │ └── method_reference-spec.ts │ │ ├── modifiers │ │ ├── _input.java │ │ ├── _output.java │ │ └── modifiers-spec.ts │ │ ├── modules │ │ ├── _input.java │ │ ├── _output.java │ │ └── modules-spec.ts │ │ ├── package_and_imports │ │ ├── classWithMixedCaseImports │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── classWithMixedImports │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── classWithNoImports │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── classWithOnlyNonStaticImports │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── classWithOnlyStaticImports │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── moduleWithMixedImports │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── moduleWithNoImports │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── moduleWithOnlyNonStaticImports │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── moduleWithOnlyStaticImports │ │ │ ├── _input.java │ │ │ └── _output.java │ │ └── package_and_imports-spec.ts │ │ ├── pattern-matching │ │ ├── _input.java │ │ ├── _output.java │ │ └── pattern-matching-spec.ts │ │ ├── prettier-ignore │ │ ├── block │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── classDeclaration │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── method │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── multiple-ignore │ │ │ ├── _input.java │ │ │ └── _output.java │ │ └── prettier-ignore-spec.ts │ │ ├── records │ │ ├── _input.java │ │ ├── _output.java │ │ └── records-spec.ts │ │ ├── require-pragma │ │ ├── format-pragma │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── invalid-pragma │ │ │ ├── _input.java │ │ │ └── _output.java │ │ ├── prettier-pragma │ │ │ ├── _input.java │ │ │ └── _output.java │ │ └── require-pragma-spec.ts │ │ ├── return │ │ ├── _input.java │ │ ├── _output.java │ │ └── return-spec.ts │ │ ├── sealed │ │ ├── _input.java │ │ ├── _output.java │ │ └── sealed-spec.ts │ │ ├── snippets │ │ ├── arrays │ │ │ ├── array-initializer.spec.ts │ │ │ └── variable-initializer-list.spec.ts │ │ ├── blocks-and-statements │ │ │ └── switch.spec.ts │ │ ├── classes │ │ │ ├── class-body.spec.ts │ │ │ ├── enum-body.spec.ts │ │ │ └── variableDeclarator │ │ │ │ └── test.spec.ts │ │ ├── interfaces │ │ │ └── element-value-array-initializer.spec.ts │ │ ├── names │ │ │ ├── ambiguousName │ │ │ │ └── test.spec.ts │ │ │ ├── expressionName │ │ │ │ └── test.spec.ts │ │ │ ├── methodName │ │ │ │ └── test.spec.ts │ │ │ └── packageOrTypeName │ │ │ │ └── test.spec.ts │ │ └── types-values-and-variables │ │ │ ├── floatingPointType │ │ │ └── test.spec.ts │ │ │ ├── integralType │ │ │ └── test.spec.ts │ │ │ ├── numericType │ │ │ └── test.spec.ts │ │ │ ├── wildcard │ │ │ └── test.spec.ts │ │ │ └── wildcardBounds │ │ │ └── test.spec.ts │ │ ├── switch │ │ ├── _input.java │ │ ├── _output.java │ │ └── switch-spec.ts │ │ ├── synchronized │ │ ├── _input.java │ │ ├── _output.java │ │ └── synchronized-spec.ts │ │ ├── template-expression │ │ ├── _input.java │ │ ├── _output.java │ │ └── template-expression-spec.ts │ │ ├── text-blocks │ │ ├── _input.java │ │ ├── _output.java │ │ └── text-block-spec.ts │ │ ├── throws │ │ ├── _input.java │ │ ├── _output.java │ │ └── throws-spec.ts │ │ ├── try_catch │ │ ├── _input.java │ │ ├── _output.java │ │ └── try_catch-spec.ts │ │ ├── types │ │ ├── _input.java │ │ ├── _output.java │ │ └── types-spec.ts │ │ ├── unnamed-class-compilation-unit │ │ ├── _input.java │ │ ├── _output.java │ │ └── unnamed-class-compilation-unit-spec.ts │ │ ├── unnamed-variables-and-patterns │ │ ├── _input.java │ │ ├── _output.java │ │ └── unnamed-variables-and-patterns-spec.ts │ │ ├── variables │ │ ├── _input.java │ │ ├── _output.java │ │ └── variables-spec.ts │ │ ├── while │ │ ├── _input.java │ │ ├── _output.java │ │ └── while-spec.ts │ │ └── yield-statement │ │ ├── _input.java │ │ ├── _output.java │ │ └── yield-statement-spec.ts │ └── tsconfig.json ├── scripts └── deploy.sh ├── website ├── .gitignore ├── README.md ├── babel.config.js ├── blog │ └── 2023-11-26-2.5.0.md ├── docs │ ├── index.md │ └── installation.mdx ├── docusaurus.config.ts ├── package.json ├── src │ ├── components │ │ └── CodeEditor │ │ │ ├── index.module.css │ │ │ └── index.tsx │ ├── css │ │ └── custom.css │ └── pages │ │ ├── index.module.css │ │ ├── index.tsx │ │ └── playground │ │ ├── index.module.css │ │ └── index.tsx ├── static │ ├── .nojekyll │ └── img │ │ ├── banner-dark.png │ │ ├── favicon.png │ │ ├── icon-dark.svg │ │ ├── icon.svg │ │ ├── wide-dark.svg │ │ └── wide.svg ├── tsconfig.json └── yarn.lock └── yarn.lock /.github/ISSUE_TEMPLATE/--formatting.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "✨ Formatting" 3 | about: Issues for ugly or incorrect code 4 | title: "" 5 | labels: "" 6 | assignees: "" 7 | --- 8 | 9 | 19 | 20 | **Prettier-Java 0.5.1** 21 | 22 | ```sh 23 | # Options (if any): 24 | --print-width 80 25 | ``` 26 | 27 | **Input:** 28 | 29 | ```java 30 | // code snippet 31 | 32 | ``` 33 | 34 | **Output:** 35 | 36 | ```java 37 | // code snippet 38 | 39 | ``` 40 | 41 | **Expected behavior:** 42 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## What changed with this PR: 2 | 3 | 4 | 5 | ## Example 6 | 7 | ```java 8 | // Input 9 | 10 | // Output 11 | 12 | ``` 13 | 14 | ## Relative issues or prs: 15 | 16 | 19 | -------------------------------------------------------------------------------- /.github/workflows/binaries.yml: -------------------------------------------------------------------------------- 1 | on: 2 | release: 3 | types: [created] 4 | name: Binary artifacts 5 | jobs: 6 | generate: 7 | env: 8 | # The version needs to match with the one used in the printer 9 | PRETTIER_CORE_LIB_VERSION: 3.2.5 10 | name: Create release artifacts 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout the repository 14 | uses: actions/checkout@v4 15 | with: 16 | path: "prettier-java" 17 | - uses: actions/setup-node@v3 18 | with: 19 | node-version: 20.x 20 | - name: Install tools 21 | run: | 22 | sudo apt update 23 | sudo apt install jq 24 | npm i -g pkg 25 | - name: Installing/Linking dependencies 26 | run: | 27 | cd $GITHUB_WORKSPACE/prettier-java/packages/java-parser 28 | npm i 29 | npm link 30 | cd $GITHUB_WORKSPACE/prettier-java/packages/prettier-plugin-java 31 | npm i 32 | npm link java-parser 33 | - name: Checkout Prettier 34 | uses: actions/checkout@v2 35 | with: 36 | repository: prettier/prettier 37 | ref: refs/tags/${{ env.PRETTIER_CORE_LIB_VERSION }} 38 | path: prettier 39 | - name: Link Prettier-java to Prettier 40 | # We need to give the path to the plugin for pkg 41 | run: | 42 | cd $GITHUB_WORKSPACE/prettier 43 | npm i 44 | npm link prettier-plugin-java 45 | mv package.json package.json.old 46 | jq '.dependencies["prettier-plugin-java"] = "./node_modules/prettier-plugin-java"' package.json.old | cat > package.json 47 | - name: Build the artifacts 48 | run: | 49 | cd $GITHUB_WORKSPACE/prettier 50 | pkg package.json -o $GITHUB_WORKSPACE/prettier-java-${GITHUB_REF##*/} --targets node10-linux-x64,node10-macos-x64,node10-win-x64 51 | - name: Upload the artifacts 52 | uses: skx/github-action-publish-binaries@master 53 | env: 54 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 55 | with: 56 | args: "prettier-java-*" 57 | -------------------------------------------------------------------------------- /.github/workflows/copyright-update.yml: -------------------------------------------------------------------------------- 1 | name: Copyright Update 2 | on: 3 | schedule: 4 | - cron: '0 0 31 12 *' # Repeats December 31st every year 5 | 6 | permissions: 7 | contents: read 8 | 9 | jobs: 10 | build: 11 | permissions: 12 | contents: write # for peter-evans/create-pull-request to create branch 13 | pull-requests: write # for peter-evans/create-pull-request to create a PR 14 | name: copyright update 15 | if: github.repository == 'jhipster/prettier-java' 16 | runs-on: ubuntu-latest 17 | timeout-minutes: 40 18 | steps: 19 | # Checkout 20 | - uses: actions/checkout@v3 21 | with: 22 | ref: main 23 | fetch-depth: 0 24 | # Update the copyright headers 25 | - name: Find and Replace 26 | run: | 27 | CURRENT_YEAR=$(date +'%Y') 28 | NEW_YEAR=$(($CURRENT_YEAR + 1)) 29 | grep -rlZE "Copyright ([0-9]+)-$CURRENT_YEAR" . | xargs -0 sed -i -E "s/Copyright ([0-9]+)-$CURRENT_YEAR/Copyright \1-$NEW_YEAR/g" 30 | # Create PR 31 | - name: Create Pull Request 32 | uses: peter-evans/create-pull-request@v4 33 | with: 34 | token: ${{ secrets.GITHUB_TOKEN }} 35 | commit-message: 'Update copyright headers' 36 | title: 'Update Copyright Headers' 37 | body: 'This is an automated pull request to update the copyright headers' 38 | branch: 'copyright-date-update' 39 | author: 'jhipster-bot ' 40 | -------------------------------------------------------------------------------- /.github/workflows/github-ci.yml: -------------------------------------------------------------------------------- 1 | name: Prettier-java 2 | on: [push, pull_request] 3 | jobs: 4 | tests: 5 | name: unit tests (node ${{ matrix.node_version }}) 6 | runs-on: ubuntu-latest 7 | if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.pull_request.title, '[skip ci]') && !contains(github.event.pull_request.title, '[ci skip]')" 8 | strategy: 9 | matrix: 10 | node_version: 11 | - 20.x 12 | - 22.x 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: actions/setup-node@v3 16 | with: 17 | node-version: ${{ matrix.node_version }} 18 | - uses: actions/setup-java@v3 19 | with: 20 | java-version: 17.x 21 | distribution: zulu 22 | - name: Install dependencies 23 | run: yarn 24 | - name: Run CI 25 | run: yarn run ci 26 | 27 | e2e-tests: 28 | name: ${{ matrix.test_repository }} (node ${{ matrix.node_version }}) 29 | runs-on: ubuntu-latest 30 | if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.pull_request.title, '[skip ci]') && !contains(github.event.pull_request.title, '[ci skip]')" 31 | strategy: 32 | matrix: 33 | test_repository: 34 | - e2e-jhipster1 35 | - e2e-jhipster2 36 | node_version: [22.x] 37 | steps: 38 | - uses: actions/checkout@v4 39 | - uses: actions/setup-node@v3 40 | with: 41 | node-version: ${{ matrix.node_version }} 42 | - uses: actions/setup-java@v3 43 | with: 44 | java-version: 21.x 45 | distribution: zulu 46 | - name: Install dependencies 47 | run: yarn 48 | - name: Build prettier-plugin-java 49 | run: yarn run build:prettier-plugin-java 50 | - name: Run e2e tests 51 | run: yarn run test:prettier-plugin-java test:${{ matrix.test_repository }} 52 | -------------------------------------------------------------------------------- /.github/workflows/github-pages-deploy.yml: -------------------------------------------------------------------------------- 1 | name: GitHub Pages Deploy 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | defaults: 9 | run: 10 | working-directory: ./website 11 | 12 | jobs: 13 | build: 14 | name: Build Docusaurus 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v4 18 | with: 19 | fetch-depth: 0 20 | - uses: actions/setup-node@v4 21 | with: 22 | node-version: 20 23 | cache: yarn 24 | 25 | - name: Install prettier-plugin-java dependencies 26 | working-directory: ./packages/prettier-plugin-java 27 | run: yarn install --frozen-lockfile 28 | - name: Build prettier-plugin-java 29 | working-directory: ./packages/prettier-plugin-java 30 | run: yarn build 31 | 32 | - name: Install dependencies 33 | run: yarn install --frozen-lockfile 34 | - name: Build website 35 | run: yarn build 36 | 37 | - name: Upload Build Artifact 38 | uses: actions/upload-pages-artifact@v3 39 | with: 40 | path: website/build 41 | 42 | deploy: 43 | name: Deploy to GitHub Pages 44 | needs: build 45 | 46 | # Grant GITHUB_TOKEN the permissions required to make a Pages deployment 47 | permissions: 48 | pages: write # to deploy to Pages 49 | id-token: write # to verify the deployment originates from an appropriate source 50 | 51 | # Deploy to the github-pages environment 52 | environment: 53 | name: github-pages 54 | url: ${{ steps.deployment.outputs.page_url }} 55 | 56 | runs-on: ubuntu-latest 57 | steps: 58 | - name: Deploy to GitHub Pages 59 | id: deployment 60 | uses: actions/deploy-pages@v4 61 | -------------------------------------------------------------------------------- /.github/workflows/github-pages-test.yml: -------------------------------------------------------------------------------- 1 | name: GitHub Pages Test 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | 8 | defaults: 9 | run: 10 | working-directory: ./website 11 | 12 | jobs: 13 | build: 14 | name: Build Docusaurus 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v4 18 | with: 19 | fetch-depth: 0 20 | - uses: actions/setup-node@v4 21 | with: 22 | node-version: 20 23 | cache: yarn 24 | 25 | - name: Install prettier-plugin-java dependencies 26 | working-directory: ./packages/prettier-plugin-java 27 | run: yarn install --frozen-lockfile 28 | - name: Build prettier-plugin-java 29 | working-directory: ./packages/prettier-plugin-java 30 | run: yarn build 31 | 32 | - name: Install dependencies 33 | run: yarn install --frozen-lockfile 34 | - name: Test build website 35 | run: yarn build 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | /.vscode 4 | .DS_Store 5 | .idea 6 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | npx lint-staged 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | samples 2 | lerna.json 3 | packages/prettier-plugin-java/samples 4 | packages/prettier-plugin-java/test-samples 5 | packages/prettier-plugin-java/README.md 6 | packages/prettier-plugin-java/dist 7 | CHANGELOG* 8 | website/build 9 | website/.docusaurus 10 | -------------------------------------------------------------------------------- /.prettierrc.yaml: -------------------------------------------------------------------------------- 1 | trailingComma: "none" 2 | useTabs: false 3 | tabWidth: 2 4 | semi: true 5 | singleQuote: false 6 | printWidth: 80 7 | arrowParens: "avoid" 8 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | prettier-java 2 | Copyright 2018-2025 the original author or authors from the JHipster project. 3 | 4 | For more information on the prettier-java project, see https://github.com/jhipster/prettier-java 5 | prettier-java is part of the JHipster organization on GitHub, for more information on JHipster, see https://www.jhipster.tech/ 6 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # RELEASE 2 | 3 | For core contributors, when you want to do a release, follow these steps: 4 | 5 | Go into your local project. 6 | 7 | Be sure to have an origin and upstream. The origin is your fork. The upstream is the official project. You should have something like that: 8 | 9 | ``` 10 | ➜ git remote -v 11 | origin git@github.com:pascalgrimaud/prettier-java.git (fetch) 12 | origin git@github.com:pascalgrimaud/prettier-java.git (push) 13 | upstream git@github.com:jhipster/prettier-java (fetch) 14 | upstream git@github.com:jhipster/prettier-java (push) 15 | ``` 16 | 17 | Update `main` branch and `release` branch in your fork. 18 | 19 | ``` 20 | git checkout release 21 | git fetch upstream 22 | git rebase upstream/release 23 | 24 | git checkout main 25 | git rebase upstream/main 26 | ``` 27 | 28 | Be sure your dependencies is up-to-dated: 29 | 30 | ``` 31 | yarn 32 | ``` 33 | 34 | In `main` branch, launch the release, and answer the questions. It will: 35 | 36 | - change the version (patch, minor or major, accordingly to what you choose) 37 | - tag the version 38 | - push main branch to upstream 39 | - push the tag to upstream 40 | 41 | ``` 42 | yarn run lerna:version 43 | ``` 44 | 45 | Then, if everything looks OK, merge the main branch to the release branch locally, then push the release branch: 46 | 47 | ``` 48 | git checkout release 49 | git merge main 50 | git push upstream/release 51 | ``` 52 | 53 | The Azure Pipelines will build the release branch and publish to NPM. 54 | Then, you need to check if the release is correctly published at: 55 | 56 | - https://www.npmjs.com/package/prettier-plugin-java 57 | - https://www.npmjs.com/package/java-parser 58 | -------------------------------------------------------------------------------- /benchmark/java-parser/benchmark.js: -------------------------------------------------------------------------------- 1 | /* eslint no-console: 0 */ 2 | import path from "path"; 3 | import klawSync from "klaw-sync"; 4 | import fs from "fs"; 5 | import * as npmparser from "java-parser-npm"; 6 | import { performance } from "perf_hooks"; 7 | import url from "url"; 8 | import * as currentparser from "../../packages/java-parser/src/index.js"; 9 | 10 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 11 | const samplesDir = path.resolve( 12 | __dirname, 13 | "../../packages/java-parser/samples/java-design-patterns/flux" 14 | ); 15 | const sampleFiles = klawSync(samplesDir, { nodir: true }); 16 | const javaSampleFiles = sampleFiles.filter(fileDesc => 17 | fileDesc.path.endsWith(".java") 18 | ); 19 | 20 | const javaPathAndText = javaSampleFiles.map(fileDesc => { 21 | const currJavaFileString = fs.readFileSync(fileDesc.path, "utf8"); 22 | const relativePath = path.relative(__dirname, fileDesc.path); 23 | 24 | return { path: relativePath, text: currJavaFileString }; 25 | }); 26 | 27 | function benchmarkParser(parser) { 28 | const start = performance.now(); 29 | javaPathAndText.forEach(javaText => { 30 | try { 31 | parser(javaText.text); 32 | } catch (e) { 33 | console.log(e); 34 | } 35 | }); 36 | const end = performance.now(); 37 | return `${end - start}ms`; 38 | } 39 | 40 | for (let i = 0; i < 3; i++) { 41 | console.log(`NPM Java Parser (${benchmarkParser(npmparser.parse)})`); 42 | console.log( 43 | `Local Repository Java Parser (${benchmarkParser(currentparser.parse)})` 44 | ); 45 | } 46 | -------------------------------------------------------------------------------- /benchmark/java-parser/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "benchmark", 3 | "version": "1.0.1", 4 | "private": true, 5 | "description": "Benchmark for comparing Parsers", 6 | "type": "module", 7 | "exports": "./benchmark.js", 8 | "scripts": { 9 | "start": "node benchmark.js" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/jhipster/prettier-java.git" 14 | }, 15 | "author": "", 16 | "license": "Apache-2.0", 17 | "bugs": { 18 | "url": "https://github.com/jhipster/prettier-java/issues" 19 | }, 20 | "homepage": "https://github.com/jhipster/prettier-java#readme", 21 | "devDependencies": { 22 | "java-parser-npm": "npm:java-parser@2.0.5" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /docs/checkstyle/import-checkstyle-configuration.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhipster/prettier-java/a1b05b474a157165133bff7a86c1d2b88bbfa5b4/docs/checkstyle/import-checkstyle-configuration.gif -------------------------------------------------------------------------------- /docs/intellij_imports_config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhipster/prettier-java/a1b05b474a157165133bff7a86c1d2b88bbfa5b4/docs/intellij_imports_config.png -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from "globals"; 2 | import path from "node:path"; 3 | import { fileURLToPath } from "node:url"; 4 | import js from "@eslint/js"; 5 | import { FlatCompat } from "@eslint/eslintrc"; 6 | 7 | const __filename = fileURLToPath(import.meta.url); 8 | const __dirname = path.dirname(__filename); 9 | const compat = new FlatCompat({ 10 | baseDirectory: __dirname, 11 | recommendedConfig: js.configs.recommended, 12 | allConfig: js.configs.all 13 | }); 14 | 15 | export default [ 16 | { 17 | ignores: [ 18 | "packages/java-parser/samples", 19 | "packages/prettier-plugin-java/samples", 20 | "packages/prettier-plugin-java/test-samples", 21 | "**/node_modules", 22 | "packages/prettier-plugin-java/dist", 23 | "**/babel.config.js", 24 | "website/.docusaurus" 25 | ] 26 | }, 27 | ...compat.extends("eslint:recommended"), 28 | { 29 | languageOptions: { 30 | globals: { 31 | ...globals.node 32 | }, 33 | ecmaVersion: 2020, 34 | sourceType: "module" 35 | }, 36 | rules: { 37 | "no-fallthrough": "off", 38 | curly: "error", 39 | "no-else-return": "error", 40 | "no-inner-declarations": "error", 41 | "no-unneeded-ternary": "error", 42 | "no-useless-return": "error", 43 | "no-console": "error", 44 | "no-var": "error", 45 | "one-var": ["error", "never"], 46 | "prefer-arrow-callback": "error", 47 | "prefer-const": "error", 48 | "react/no-deprecated": "off", 49 | strict: "error", 50 | "symbol-description": "error", 51 | yoda: [ 52 | "error", 53 | "never", 54 | { 55 | exceptRange: true 56 | } 57 | ] 58 | } 59 | }, 60 | { 61 | files: ["packages/*/test/**/*.js"], 62 | languageOptions: { 63 | globals: { 64 | context: true, 65 | describe: true, 66 | it: true, 67 | before: true, 68 | after: true 69 | } 70 | }, 71 | rules: { 72 | strict: "off" 73 | } 74 | } 75 | ]; 76 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*", 4 | "benchmark/*" 5 | ], 6 | "npmClient": "yarn", 7 | "version": "independent" 8 | } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "root", 3 | "private": true, 4 | "homepage": "https://www.jhipster.tech/prettier-java/", 5 | "workspaces": [ 6 | "packages/*", 7 | "benchmark/*" 8 | ], 9 | "scripts": { 10 | "prepare": "husky", 11 | "lerna:version": "lerna version --exact --no-private", 12 | "lerna:publish": "lerna publish from-git --yes", 13 | "ci": "yarn build && yarn lint && yarn format:validate && yarn test", 14 | "ci:all": "yarn run ci && yarn run test:prettier-plugin-java test:e2e-jhipster1 && yarn run test:prettier-plugin-java test:e2e-jhipster2", 15 | "test": "lerna run test --stream", 16 | "test:prettier-plugin-java": "lerna --stream --scope=prettier-plugin-java run", 17 | "lint": "eslint packages/**/*.js", 18 | "format:fix": "prettier --write \"**/*.@(js|json|ts)\"", 19 | "format:validate": "prettier --list-different \"**/*.@(js|json|ts)\"", 20 | "build": "yarn build:prettier-plugin-java && node packages/java-parser/scripts/unicode.js packages/java-parser/resources/Unicode/UnicodeData.txt && prettier --write packages/java-parser/src/unicodesets.js && node packages/java-parser/scripts/gen-diagrams.js", 21 | "build:prettier-plugin-java": "cd packages/prettier-plugin-java && yarn build && cd ../..", 22 | "update-test-outputs": "node packages/prettier-plugin-java/scripts/update-test-output.js" 23 | }, 24 | "lint-staged": { 25 | "*.json": [ 26 | "prettier --write" 27 | ], 28 | "*.js,*.ts": [ 29 | "eslint --fix", 30 | "prettier --write" 31 | ] 32 | }, 33 | "devDependencies": { 34 | "chai": "5.1.2", 35 | "eslint": "9.14.0", 36 | "eslint-config-google": "0.14.0", 37 | "eslint-config-prettier": "9.1.0", 38 | "fs-extra": "11.2.0", 39 | "husky": "9.1.6", 40 | "klaw-sync": "6.0.0", 41 | "lerna": "8.1.9", 42 | "lint-staged": "15.2.10", 43 | "mocha": "10.8.2", 44 | "prettier": "3.4.2", 45 | "sinon": "19.0.2" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/java-parser/.gitignore: -------------------------------------------------------------------------------- 1 | /samples 2 | /diagrams.html 3 | -------------------------------------------------------------------------------- /packages/java-parser/.mocharc.cjs: -------------------------------------------------------------------------------- 1 | // Enabled Additional validation flows during Parser / Lexer Initialization. 2 | process.env["prettier-java-development-mode"] = "enabled"; 3 | 4 | module.exports = {}; 5 | -------------------------------------------------------------------------------- /packages/java-parser/.npmignore: -------------------------------------------------------------------------------- 1 | resources/Unicode/* 2 | docs 3 | samples 4 | scripts 5 | test 6 | .mocharc.cjs 7 | diagrams.html 8 | *.log -------------------------------------------------------------------------------- /packages/java-parser/docs/comments.md: -------------------------------------------------------------------------------- 1 | # Handling comments 2 | 3 | ## Objective 4 | 5 | Attach each comment to a CST node or token as either leading or trailing comment. 6 | 7 | ### Attach comment to the highest node possible 8 | 9 | A comment could often be attached at several nodes or token. For instance, in the following code snippet: 10 | 11 | ```java 12 | // comment 13 | public void t() {} 14 | ``` 15 | 16 | `// comment` could be attached to: 17 | 18 | - the `methodDeclaration` node 19 | - the `methodModifier` node 20 | - the `public` token 21 | 22 | We have made the decision to attach the comment to the highest node possible (the most enclosive one). It makes the more sense to us, and it ease handling comments in the prettier-plugin. 23 | 24 | ### Trailing comments 25 | 26 | A comment should be considered as a trailing comment in very specific cases: 27 | 28 | - If it is on the same line as the node/token it followed, and not on the same line as the node/token it preceded. For instance, `//comment` is considered as a trailing comment in the following code snippet: 29 | 30 | ```java 31 | int i = 1; // comment 32 | int j = 2; 33 | ``` 34 | 35 | - If it is at the end of the file 36 | 37 | ### Consecutives comments 38 | 39 | If there are consecutive comments, each comment will be considered separately. For instance: 40 | 41 | ```java 42 | int i = 1; 43 | // comment1 44 | // comment2 45 | int j = 2; 46 | ``` 47 | 48 | `// comment1` and `// comment2` will be both attached as leading comments to the second `localVariableDeclarationStatement` node. 49 | 50 | When in: 51 | 52 | ```java 53 | int i = 1; // comment1 54 | // comment2 55 | int j = 2; 56 | ``` 57 | 58 | `// comment1` will be attached as a trailing comment to the first `localVariableDeclarationStatement` node and `// comment2` will be attached as a leading comment to the second one. 59 | -------------------------------------------------------------------------------- /packages/java-parser/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "java-parser", 3 | "version": "2.3.4", 4 | "description": "Java Parser in JavaScript", 5 | "type": "module", 6 | "exports": { 7 | ".": { 8 | "types": "./api.d.ts", 9 | "default": "./src/index.js" 10 | } 11 | }, 12 | "repository": "https://github.com/jhipster/prettier-java/tree/main/packages/java-parser", 13 | "license": "Apache-2.0", 14 | "types": "./api.d.ts", 15 | "dependencies": { 16 | "chevrotain": "11.0.3", 17 | "chevrotain-allstar": "0.3.1", 18 | "lodash": "4.17.21" 19 | }, 20 | "scripts": { 21 | "test": "yarn run clone-samples && yarn run test:execute", 22 | "test:execute": "mocha \"test/**/*-spec.js\"", 23 | "clone-samples": "node ./scripts/clone-samples" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/java-parser/scripts/gen-diagrams.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A template for generating syntax diagrams html file. 3 | * See: https://github.com/SAP/chevrotain/tree/master/diagrams for more details 4 | * 5 | * usage: 6 | * - npm install in the parent directory (parser) to install dependencies 7 | * - Run this in file in node.js (node gen_diagrams.js) 8 | * - open the "generated_diagrams.html" that will be created in this folder using 9 | * your favorite browser. 10 | */ 11 | import path from "path"; 12 | import fs from "fs"; 13 | import * as chevrotain from "chevrotain"; 14 | import url from "url"; 15 | import JavaParser from "../src/parser.js"; 16 | 17 | // extract the serialized grammar. 18 | const parserInstance = new JavaParser([]); 19 | const serializedGrammar = parserInstance.getSerializedGastProductions(); 20 | 21 | // create the HTML Text 22 | const htmlText = chevrotain.createSyntaxDiagramsCode(serializedGrammar); 23 | 24 | // Write the HTML file to disk 25 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 26 | const outPath = path.resolve(__dirname, "./"); 27 | fs.writeFileSync(outPath + "/../diagrams.html", htmlText); 28 | -------------------------------------------------------------------------------- /packages/java-parser/scripts/single-sample-runner.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This Script is used to debug the parsing of **small** code snippets. 3 | */ 4 | import javaParserChev from "../src/index.js"; 5 | 6 | const input = ` 7 | public class VariableTypeInference { 8 | 9 | int foo = 0, bar = 1; 10 | } 11 | 12 | `; 13 | 14 | javaParserChev.parse(input, "compilationUnit"); 15 | -------------------------------------------------------------------------------- /packages/java-parser/src/index.js: -------------------------------------------------------------------------------- 1 | import JavaLexer from "./lexer.js"; 2 | import JavaParser from "./parser.js"; 3 | import { attachComments, matchFormatterOffOnPairs } from "./comments.js"; 4 | 5 | const parser = new JavaParser(); 6 | 7 | export const BaseJavaCstVisitor = parser.getBaseCstVisitorConstructor(); 8 | export const BaseJavaCstVisitorWithDefaults = 9 | parser.getBaseCstVisitorConstructorWithDefaults(); 10 | 11 | export function lexAndParse(inputText, entryPoint = "compilationUnit") { 12 | // Lex 13 | const lexResult = JavaLexer.tokenize(inputText); 14 | 15 | if (lexResult.errors.length > 0) { 16 | const firstError = lexResult.errors[0]; 17 | throw Error( 18 | "Sad sad panda, lexing errors detected in line: " + 19 | firstError.line + 20 | ", column: " + 21 | firstError.column + 22 | "!\n" + 23 | firstError.message 24 | ); 25 | } 26 | 27 | const tokens = lexResult.tokens; 28 | parser.input = tokens; 29 | parser.mostEnclosiveCstNodeByStartOffset = {}; 30 | parser.mostEnclosiveCstNodeByEndOffset = {}; 31 | 32 | parser.setOnOffCommentPairs( 33 | matchFormatterOffOnPairs(lexResult.groups.comments) 34 | ); 35 | 36 | // Automatic CST created when parsing 37 | const cst = parser[entryPoint](); 38 | 39 | if (parser.errors.length > 0) { 40 | const error = parser.errors[0]; 41 | throw Error( 42 | "Sad sad panda, parsing errors detected in line: " + 43 | error.token.startLine + 44 | ", column: " + 45 | error.token.startColumn + 46 | "!\n" + 47 | error.message + 48 | "!\n\t->" + 49 | error.context.ruleStack.join("\n\t->") 50 | ); 51 | } 52 | 53 | attachComments( 54 | tokens, 55 | lexResult.groups.comments, 56 | parser.mostEnclosiveCstNodeByStartOffset, 57 | parser.mostEnclosiveCstNodeByEndOffset 58 | ); 59 | 60 | return { cst, tokens }; 61 | } 62 | 63 | export function parse(inputText, entryPoint = "compilationUnit") { 64 | return lexAndParse(inputText, entryPoint).cst; 65 | } 66 | 67 | export default { 68 | lexAndParse, 69 | parse, 70 | BaseJavaCstVisitor, 71 | BaseJavaCstVisitorWithDefaults 72 | }; 73 | -------------------------------------------------------------------------------- /packages/java-parser/src/lexer.js: -------------------------------------------------------------------------------- 1 | import { Lexer } from "chevrotain"; 2 | import { allTokens } from "./tokens.js"; 3 | import { getSkipValidations } from "./utils.js"; 4 | 5 | export default new Lexer(allTokens, { 6 | ensureOptimizations: true, 7 | skipValidations: getSkipValidations() 8 | }); 9 | -------------------------------------------------------------------------------- /packages/java-parser/src/productions/arrays.js: -------------------------------------------------------------------------------- 1 | import { tokenMatcher } from "chevrotain"; 2 | 3 | export function defineRules($, t) { 4 | // https://docs.oracle.com/javase/specs/jls/se22/html/jls-10.html#jls-ArrayInitializer 5 | $.RULE("arrayInitializer", () => { 6 | $.CONSUME(t.LCurly); 7 | $.OPTION(() => { 8 | $.SUBRULE($.variableInitializerList); 9 | }); 10 | $.OPTION2(() => { 11 | $.CONSUME(t.Comma); 12 | }); 13 | $.CONSUME(t.RCurly); 14 | }); 15 | 16 | // https://docs.oracle.com/javase/specs/jls/se22/html/jls-10.html#jls-VariableInitializerList 17 | $.RULE("variableInitializerList", () => { 18 | $.SUBRULE($.variableInitializer); 19 | $.MANY({ 20 | // The optional last "Comma" of an "arrayInitializer" 21 | GATE: () => tokenMatcher(this.LA(2).tokenType, t.RCurly) === false, 22 | DEF: () => { 23 | $.CONSUME(t.Comma); 24 | $.SUBRULE2($.variableInitializer); 25 | } 26 | }); 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /packages/java-parser/src/productions/lexical-structure.js: -------------------------------------------------------------------------------- 1 | export function defineRules($, t) { 2 | // https://docs.oracle.com/javase/specs/jls/se22/html/jls-3.html#jls-Literal 3 | $.RULE("literal", () => { 4 | $.OR([ 5 | { ALT: () => $.SUBRULE($.integerLiteral) }, 6 | { ALT: () => $.SUBRULE($.floatingPointLiteral) }, 7 | { ALT: () => $.SUBRULE($.booleanLiteral) }, 8 | { ALT: () => $.CONSUME(t.CharLiteral) }, 9 | { ALT: () => $.CONSUME(t.TextBlock) }, 10 | { ALT: () => $.CONSUME(t.StringLiteral) }, 11 | { ALT: () => $.CONSUME(t.Null) } 12 | ]); 13 | }); 14 | 15 | // https://docs.oracle.com/javase/specs/jls/se22/html/jls-3.html#jls-IntegerLiteral 16 | $.RULE("integerLiteral", () => { 17 | $.OR([ 18 | { ALT: () => $.CONSUME(t.DecimalLiteral) }, 19 | { ALT: () => $.CONSUME(t.HexLiteral) }, 20 | { ALT: () => $.CONSUME(t.OctalLiteral) }, 21 | { ALT: () => $.CONSUME(t.BinaryLiteral) } 22 | ]); 23 | }); 24 | 25 | // https://docs.oracle.com/javase/specs/jls/se22/html/jls-3.html#jls-FloatingPointLiteral 26 | $.RULE("floatingPointLiteral", () => { 27 | $.OR([ 28 | { ALT: () => $.CONSUME(t.FloatLiteral) }, 29 | { ALT: () => $.CONSUME(t.HexFloatLiteral) } 30 | ]); 31 | }); 32 | 33 | // https://docs.oracle.com/javase/specs/jls/se22/html/jls-3.html#jls-BooleanLiteral 34 | $.RULE("booleanLiteral", () => { 35 | $.OR([{ ALT: () => $.CONSUME(t.True) }, { ALT: () => $.CONSUME(t.False) }]); 36 | }); 37 | } 38 | -------------------------------------------------------------------------------- /packages/java-parser/src/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Should Parser / Lexer Validations be skipped? 3 | * 4 | * By default (productive mode) the validations would be skipped to reduce parser initialization time. 5 | * But during development flows (e.g testing/CI) they should be enabled to detect possible issues. 6 | * 7 | * @returns {boolean} 8 | */ 9 | export function getSkipValidations() { 10 | return ( 11 | (typeof process !== "undefined" && // (not every runtime has a global `process` object 12 | process.env && 13 | process.env["prettier-java-development-mode"] === "enabled") === false 14 | ); 15 | } 16 | -------------------------------------------------------------------------------- /packages/java-parser/test/blocks-and-statements/yield-statement-spec.js: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import * as javaParser from "../../src/index.js"; 3 | 4 | describe("Yield statements", () => { 5 | it("should handle yield as a special keyword", () => { 6 | const input = `String yield;`; 7 | expect(() => javaParser.parse(input, "blockStatement")).to.not.throw(); 8 | }); 9 | 10 | it("should handle yield statements", () => { 11 | const input = `yield len*len;`; 12 | expect(() => javaParser.parse(input, "yieldStatement")).to.not.throw(); 13 | }); 14 | 15 | it("should handle yield statements in switch case", () => { 16 | const input = `switch (d) { 17 | case SATURDAY: d.ordinal(); 18 | default: 19 | int len = d.toString().length(); 20 | yield alen*len; 21 | 22 | }`; 23 | expect(() => javaParser.parse(input, "switchStatement")).to.not.throw(); 24 | }); 25 | 26 | it("should handle return statements switch case", () => { 27 | const input = `return switch (d) { 28 | case SATURDAY, SUNDAY -> d.ordinal(); 29 | default -> { 30 | int len = d.toString().length(); 31 | yield len*len; 32 | } 33 | };`; 34 | expect(() => javaParser.parse(input, "returnStatement")).to.not.throw(); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/java-parser/test/classes-spec.js: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import * as javaParser from "../src/index.js"; 3 | 4 | describe("The Java Parser fixed bugs", () => { 5 | it("should handle multiple variable declaration", () => { 6 | const input = `int foo, bar;`; 7 | expect(() => javaParser.parse(input, "fieldDeclaration")).to.not.throw(); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/java-parser/test/samples-spec.js: -------------------------------------------------------------------------------- 1 | import _ from "lodash"; 2 | import path from "path"; 3 | import klawSync from "klaw-sync"; 4 | import { expect } from "chai"; 5 | import fs from "fs"; 6 | import url from "url"; 7 | import * as javaParser from "../src/index.js"; 8 | 9 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 10 | 11 | describe("The Java Parser", () => { 12 | createSampleSpecs("java-design-patterns"); 13 | createSampleSpecs("spring-boot"); 14 | createSampleSpecs("spring-framework"); 15 | createSampleSpecs("jhipster-bom"); 16 | createSampleSpecs("jhipster-online"); 17 | createSampleSpecs("jhipster-sample-app"); 18 | createSampleSpecs("jhipster-sample-app-cassandra"); 19 | createSampleSpecs("jhipster-sample-app-dto"); 20 | createSampleSpecs("jhipster-sample-app-elasticsearch"); 21 | createSampleSpecs("jhipster-sample-app-gradle"); 22 | createSampleSpecs("jhipster-sample-app-hazelcast"); 23 | createSampleSpecs("jhipster-sample-app-microservice"); 24 | createSampleSpecs("jhipster-sample-app-mongodb"); 25 | createSampleSpecs("jhipster-sample-app-noi18n"); 26 | createSampleSpecs("jhipster-sample-app-oauth2"); 27 | createSampleSpecs("jhipster-sample-app-react"); 28 | createSampleSpecs("jhipster-sample-app-websocket"); 29 | createSampleSpecs("guava"); 30 | createSampleSpecs("demo-java-x"); 31 | }); 32 | 33 | function createSampleSpecs(sampleName) { 34 | context(sampleName + " samples", () => { 35 | const samplesDir = path.resolve(__dirname, "../samples/" + sampleName); 36 | const sampleFiles = klawSync(samplesDir, { nodir: true }); 37 | const javaSampleFiles = sampleFiles.filter(fileDesc => 38 | fileDesc.path.endsWith(".java") 39 | ); 40 | 41 | if (_.isEmpty(sampleFiles)) { 42 | throw `Missing sample-dir: <${samplesDir}> did you forget to clone the samples?`; 43 | } 44 | _.forEach(javaSampleFiles, fileDesc => { 45 | const relativePath = path.relative(__dirname, fileDesc.path); 46 | it(`Can Parse <${relativePath}>`, () => { 47 | const sampleText = fs.readFileSync(fileDesc.path, "utf8"); 48 | expect(() => javaParser.parse(sampleText)).to.not.throw(); 49 | }); 50 | }); 51 | }); 52 | } 53 | -------------------------------------------------------------------------------- /packages/java-parser/test/string-literals.spec.js: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import javaParser from "../src/index.js"; 3 | 4 | describe("String literals", () => { 5 | it("should parse unicode", () => { 6 | const inputs = [ 7 | '"π or \\u03c0"', 8 | '"\\uD83C\\uDF4F"', 9 | '"\\uD83C\\uDF4C"', 10 | '"\\uD83C\\uDF52"', 11 | '"🍎"' 12 | ]; 13 | inputs.forEach(input => { 14 | expect(() => javaParser.parse(input, "literal")).to.not.throw(); 15 | }); 16 | }); 17 | 18 | it("should parse octal literals", () => { 19 | const inputs = ['"\\52"', '"\\133"']; 20 | inputs.forEach(input => { 21 | expect(() => javaParser.parse(input, "literal")).to.not.throw(); 22 | }); 23 | }); 24 | 25 | it("should parse escaped sequence", () => { 26 | const inputs = [ 27 | '"\\b"', 28 | '"\\s"', 29 | '"\\t"', 30 | '"\\n"', 31 | '"\\f"', 32 | '"\\r"', 33 | '"\\""', 34 | '"\\\'"', 35 | '"\\\\"' 36 | ]; 37 | inputs.forEach(input => { 38 | expect(() => javaParser.parse(input, "literal")).to.not.throw(); 39 | }); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/.gitignore: -------------------------------------------------------------------------------- 1 | test-samples/**/* 2 | scripts/single-printer-run 3 | samples/**/* 4 | !test-samples/.eslintrc.json 5 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extension": ["ts"], 3 | "node-option": ["loader=ts-node/esm", "no-warnings"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/.npmignore: -------------------------------------------------------------------------------- 1 | docs 2 | scripts 3 | test 4 | test-samples 5 | samples 6 | *.log 7 | src 8 | dist/test 9 | *-spec.js 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/index.d.ts: -------------------------------------------------------------------------------- 1 | import type { Plugin } from "prettier"; 2 | 3 | declare const plugin: Plugin; 4 | export default plugin; 5 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prettier-plugin-java", 3 | "version": "2.6.8", 4 | "description": "Prettier Java Plugin", 5 | "type": "module", 6 | "exports": { 7 | "types": "./index.d.ts", 8 | "default": "./dist/index.js" 9 | }, 10 | "files": [ 11 | "dist", 12 | "index.d.ts" 13 | ], 14 | "homepage": "https://jhipster.github.io/prettier-java/", 15 | "repository": "https://github.com/jhipster/prettier-java", 16 | "license": "Apache-2.0", 17 | "dependencies": { 18 | "java-parser": "2.3.4", 19 | "lodash": "4.17.21" 20 | }, 21 | "scripts": { 22 | "test": "yarn run test:unit && yarn run test:e2e-core", 23 | "test:unit": "mocha \"test/unit-test/**/*.spec.ts\" \"test/unit-test/**/*-spec.ts\"", 24 | "test:e2e-core": "node scripts/clone-samples e2e-core && mocha \"test/repository-test/core-test.ts\"", 25 | "test:e2e-jhipster1": "node scripts/clone-samples e2e-jhipster1 && mocha \"test/repository-test/jhipster-1-test.ts\"", 26 | "test:e2e-jhipster2": "node scripts/clone-samples e2e-jhipster2 && mocha \"test/repository-test/jhipster-2-test.ts\"", 27 | "test:all": "yarn run test && yarn run test:e2e-jhipster1 && yarn run test:e2e-jhipster2", 28 | "clone-samples": "node scripts/clone-samples.js", 29 | "build": "tsc", 30 | "build:watch": "tsc --inlineSourceMap -w" 31 | }, 32 | "devDependencies": { 33 | "@chevrotain/types": "11.0.3", 34 | "@types/chai": "5.0.1", 35 | "@types/fs-extra": "11.0.4", 36 | "@types/jest": "29.5.14", 37 | "@types/klaw-sync": "6.0.5", 38 | "@types/lodash": "4.17.13", 39 | "@types/node": "18.19.64", 40 | "@types/sinon": "17.0.3", 41 | "ts-node": "10.9.2", 42 | "typescript": "5.6.3" 43 | }, 44 | "peerDependencies": { 45 | "prettier": "^3.0.0" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/scripts/single-printer-run/_input.java: -------------------------------------------------------------------------------- 1 | public enum Enum { 2 | 3 | SOME_ENUM, ANOTHER_ENUM, LAST_ENUM; 4 | 5 | } 6 | 7 | public enum Enum { 8 | 9 | THIS_IS_GOOD("abc"), THIS_IS_FINE("abc"); 10 | 11 | public static final String thisWillBeDeleted = "DELETED"; 12 | 13 | private final String value; 14 | 15 | public Enum(String value) { 16 | this.value = value; 17 | } 18 | 19 | public String toString() { 20 | return "STRING"; 21 | } 22 | 23 | } 24 | 25 | class CLassWithEnum { 26 | 27 | public static enum VALID_THINGS { 28 | 29 | FIRST, SECOND 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/scripts/single-printer-run/_output.java: -------------------------------------------------------------------------------- 1 | public enum Enum { 2 | SOME_ENUM, 3 | ANOTHER_ENUM, 4 | LAST_ENUM, 5 | } 6 | 7 | public enum Enum { 8 | THIS_IS_GOOD("abc"), 9 | THIS_IS_FINE("abc"); 10 | 11 | public static final String thisWillBeDeleted = "DELETED"; 12 | 13 | private final String value; 14 | 15 | public Enum(String value) { 16 | this.value = value; 17 | } 18 | 19 | public String toString() { 20 | return "STRING"; 21 | } 22 | } 23 | 24 | class CLassWithEnum { 25 | 26 | public static enum VALID_THINGS { 27 | FIRST, 28 | SECOND, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/cst-printer.ts: -------------------------------------------------------------------------------- 1 | import { BaseCstPrettierPrinter } from "./base-cst-printer.js"; 2 | import { ArraysPrettierVisitor } from "./printers/arrays.js"; 3 | import { BlocksAndStatementPrettierVisitor } from "./printers/blocks-and-statements.js"; 4 | import { ClassesPrettierVisitor } from "./printers/classes.js"; 5 | import { ExpressionsPrettierVisitor } from "./printers/expressions.js"; 6 | import { InterfacesPrettierVisitor } from "./printers/interfaces.js"; 7 | import { LexicalStructurePrettierVisitor } from "./printers/lexical-structure.js"; 8 | import { NamesPrettierVisitor } from "./printers/names.js"; 9 | import { TypesValuesAndVariablesPrettierVisitor } from "./printers/types-values-and-variables.js"; 10 | import { PackagesAndModulesPrettierVisitor } from "./printers/packages-and-modules.js"; 11 | 12 | // Mixins for the win 13 | mixInMethods( 14 | ArraysPrettierVisitor, 15 | BlocksAndStatementPrettierVisitor, 16 | ClassesPrettierVisitor, 17 | ExpressionsPrettierVisitor, 18 | InterfacesPrettierVisitor, 19 | LexicalStructurePrettierVisitor, 20 | NamesPrettierVisitor, 21 | TypesValuesAndVariablesPrettierVisitor, 22 | PackagesAndModulesPrettierVisitor 23 | ); 24 | 25 | function mixInMethods(...classesToMix: any[]) { 26 | classesToMix.forEach(from => { 27 | const fromMethodsNames = Object.getOwnPropertyNames(from.prototype); 28 | const fromPureMethodsName = fromMethodsNames.filter( 29 | methodName => methodName !== "constructor" 30 | ); 31 | fromPureMethodsName.forEach(methodName => { 32 | // @ts-ignore 33 | BaseCstPrettierPrinter.prototype[methodName] = from.prototype[methodName]; 34 | }); 35 | }); 36 | } 37 | 38 | const prettyPrinter = new BaseCstPrettierPrinter(); 39 | 40 | // TODO: do we need the "path" and "print" arguments passed by prettier 41 | // see https://github.com/prettier/prettier/issues/5747 42 | export function createPrettierDoc(cstNode: any, options: any) { 43 | prettyPrinter.prettierOptions = options; 44 | return prettyPrinter.visit(cstNode); 45 | } 46 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/index.js: -------------------------------------------------------------------------------- 1 | import parse from "./parser.js"; 2 | import print from "./printer.js"; 3 | import options from "./options.js"; 4 | 5 | const languages = [ 6 | { 7 | name: "Java", 8 | parsers: ["java"], 9 | group: "Java", 10 | tmScope: "text.html.vue", // FIXME 11 | aceMode: "html", // FIXME 12 | codemirrorMode: "clike", 13 | codemirrorMimeType: "text/x-java", 14 | extensions: [".java"], 15 | linguistLanguageId: 181, 16 | vscodeLanguageIds: ["java"] 17 | } 18 | ]; 19 | 20 | function locStart(/* node */) { 21 | return -1; 22 | } 23 | 24 | function locEnd(/* node */) { 25 | return -1; 26 | } 27 | 28 | function hasPragma(text) { 29 | return /^\/\*\*[\n][\t\s]+\*\s@(prettier|format)[\n][\t\s]+\*\//.test(text); 30 | } 31 | 32 | const parsers = { 33 | java: { 34 | parse, 35 | astFormat: "java", 36 | locStart, 37 | locEnd, 38 | hasPragma 39 | } 40 | }; 41 | 42 | function canAttachComment(node) { 43 | return node.ast_type && node.ast_type !== "comment"; 44 | } 45 | 46 | function printComment(commentPath) { 47 | const comment = commentPath.getValue(); 48 | 49 | switch (comment.ast_type) { 50 | case "comment": 51 | return comment.value; 52 | default: 53 | throw new Error("Not a comment: " + JSON.stringify(comment)); 54 | } 55 | } 56 | 57 | function clean(ast, newObj) { 58 | delete newObj.lineno; 59 | delete newObj.col_offset; 60 | } 61 | 62 | const printers = { 63 | java: { 64 | print, 65 | // hasPrettierIgnore, 66 | printComment, 67 | canAttachComment, 68 | massageAstNode: clean 69 | } 70 | }; 71 | 72 | export default { 73 | languages, 74 | printers, 75 | parsers, 76 | options 77 | }; 78 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/parser.js: -------------------------------------------------------------------------------- 1 | import javaParser from "java-parser"; 2 | 3 | export default function parse(text, parsers, opts) { 4 | return javaParser.parse(text, opts.entrypoint); 5 | } 6 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/printer.js: -------------------------------------------------------------------------------- 1 | import { createPrettierDoc } from "./cst-printer.js"; 2 | 3 | // eslint-disable-next-line no-unused-vars 4 | export default function genericPrint(path, options, print) { 5 | const node = path.getValue(); 6 | return createPrettierDoc(node, options); 7 | } 8 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/printers/arrays.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ArrayInitializerCtx, 3 | VariableInitializerListCtx 4 | } from "java-parser/api"; 5 | import { 6 | printArrayList, 7 | rejectAndConcat, 8 | rejectAndJoinSeps 9 | } from "./printer-utils.js"; 10 | import { builders } from "prettier/doc"; 11 | import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; 12 | 13 | const { line } = builders; 14 | 15 | export class ArraysPrettierVisitor extends BaseCstPrettierPrinter { 16 | prettierOptions: any; 17 | arrayInitializer(ctx: ArrayInitializerCtx) { 18 | const optionalVariableInitializerList = this.visit( 19 | ctx.variableInitializerList 20 | ); 21 | 22 | return printArrayList({ 23 | list: optionalVariableInitializerList, 24 | extraComma: ctx.Comma, 25 | LCurly: ctx.LCurly[0], 26 | RCurly: ctx.RCurly[0], 27 | trailingComma: this.prettierOptions.trailingComma 28 | }); 29 | } 30 | 31 | variableInitializerList(ctx: VariableInitializerListCtx) { 32 | const variableInitializers = this.mapVisit(ctx.variableInitializer); 33 | const commas = ctx.Comma 34 | ? ctx.Comma.map(comma => { 35 | return rejectAndConcat([comma, line]); 36 | }) 37 | : []; 38 | 39 | return rejectAndJoinSeps(commas, variableInitializers); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/printers/comments/comments-utils.ts: -------------------------------------------------------------------------------- 1 | import { CstElement, IToken } from "java-parser"; 2 | 3 | type LeadingComments = T & { 4 | leadingComments: IToken[]; 5 | }; 6 | 7 | type TrailingComments = T & { 8 | trailingComments: IToken[]; 9 | }; 10 | 11 | export function hasLeadingComments( 12 | token: CstElement 13 | ): token is LeadingComments { 14 | return token.leadingComments !== undefined; 15 | } 16 | 17 | export function hasTrailingComments( 18 | token: CstElement 19 | ): token is TrailingComments { 20 | return token.trailingComments !== undefined; 21 | } 22 | 23 | export function hasLeadingLineComments( 24 | token: CstElement 25 | ): token is LeadingComments { 26 | return ( 27 | token.leadingComments !== undefined && 28 | token.leadingComments.length !== 0 && 29 | token.leadingComments[token.leadingComments.length - 1].tokenType.name === 30 | "LineComment" 31 | ); 32 | } 33 | 34 | export function hasTrailingLineComments( 35 | token: CstElement 36 | ): token is TrailingComments { 37 | return ( 38 | token.trailingComments !== undefined && 39 | token.trailingComments.length !== 0 && 40 | token.trailingComments[token.trailingComments.length - 1].tokenType.name === 41 | "LineComment" 42 | ); 43 | } 44 | 45 | export function hasComments(token: CstElement) { 46 | return hasLeadingComments(token) || hasTrailingComments(token); 47 | } 48 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/printers/lexical-structure.ts: -------------------------------------------------------------------------------- 1 | import { printTokenWithComments } from "./comments/format-comments.js"; 2 | import { join } from "./prettier-builder.js"; 3 | import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; 4 | import { 5 | BooleanLiteralCtx, 6 | FloatingPointLiteralCtx, 7 | IntegerLiteralCtx, 8 | IToken, 9 | LiteralCtx 10 | } from "java-parser"; 11 | import { builders } from "prettier/doc"; 12 | 13 | const { hardline } = builders; 14 | 15 | export class LexicalStructurePrettierVisitor extends BaseCstPrettierPrinter { 16 | literal(ctx: LiteralCtx) { 17 | if (ctx.TextBlock) { 18 | const lines = ctx.TextBlock[0].image.split("\n"); 19 | const open = lines.shift()!; 20 | const baseIndent = Math.min( 21 | ...lines.map(line => line.search(/\S/)).filter(indent => indent >= 0) 22 | ); 23 | return join(hardline, [ 24 | open, 25 | ...lines.map(line => line.slice(baseIndent)) 26 | ]); 27 | } 28 | if (ctx.CharLiteral || ctx.StringLiteral || ctx.Null) { 29 | return printTokenWithComments(this.getSingle(ctx) as IToken); 30 | } 31 | return this.visitSingle(ctx); 32 | } 33 | 34 | integerLiteral(ctx: IntegerLiteralCtx) { 35 | return printTokenWithComments(this.getSingle(ctx) as IToken); 36 | } 37 | 38 | floatingPointLiteral(ctx: FloatingPointLiteralCtx) { 39 | return printTokenWithComments(this.getSingle(ctx) as IToken); 40 | } 41 | 42 | booleanLiteral(ctx: BooleanLiteralCtx) { 43 | return printTokenWithComments(this.getSingle(ctx) as IToken); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/printers/names.ts: -------------------------------------------------------------------------------- 1 | import { buildFqn } from "./printer-utils.js"; 2 | import { printTokenWithComments } from "./comments/format-comments.js"; 3 | import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; 4 | import { 5 | AmbiguousNameCtx, 6 | ExpressionNameCtx, 7 | MethodNameCtx, 8 | ModuleNameCtx, 9 | PackageNameCtx, 10 | PackageOrTypeNameCtx, 11 | TypeIdentifierCtx, 12 | TypeNameCtx 13 | } from "java-parser"; 14 | 15 | export class NamesPrettierVisitor extends BaseCstPrettierPrinter { 16 | typeIdentifier(ctx: TypeIdentifierCtx) { 17 | return printTokenWithComments(ctx.Identifier[0]); 18 | } 19 | 20 | moduleName(ctx: ModuleNameCtx) { 21 | return buildFqn(ctx.Identifier, ctx.Dot); 22 | } 23 | 24 | packageName(ctx: PackageNameCtx) { 25 | return buildFqn(ctx.Identifier, ctx.Dot); 26 | } 27 | 28 | typeName(ctx: TypeNameCtx) { 29 | return buildFqn(ctx.Identifier, ctx.Dot); 30 | } 31 | 32 | expressionName(ctx: ExpressionNameCtx) { 33 | return buildFqn(ctx.Identifier, ctx.Dot); 34 | } 35 | 36 | methodName(ctx: MethodNameCtx) { 37 | return printTokenWithComments(ctx.Identifier[0]); 38 | } 39 | 40 | packageOrTypeName(ctx: PackageOrTypeNameCtx) { 41 | return buildFqn(ctx.Identifier, ctx.Dot); 42 | } 43 | 44 | ambiguousName(ctx: AmbiguousNameCtx) { 45 | return buildFqn(ctx.Identifier, ctx.Dot); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/printers/prettier-builder.ts: -------------------------------------------------------------------------------- 1 | import { IToken } from "java-parser"; 2 | import { builders } from "prettier/doc"; 3 | import Doc = builders.Doc; 4 | import * as formatComments from "./comments/format-comments.js"; 5 | 6 | const processComments = formatComments.processComments as any; 7 | /* 8 | * ------------------------------------------------------------------ 9 | * Wraps the Prettier builder functions to print tokens with comments 10 | * ------------------------------------------------------------------ 11 | */ 12 | 13 | export function concat(docs: (Doc | IToken)[]): Doc { 14 | const concatenation = processComments(docs); 15 | 16 | if (!Array.isArray(docs)) { 17 | return ""; 18 | } 19 | 20 | return concatenation; 21 | } 22 | 23 | export function join(sep: any, docs: (Doc | IToken)[]): Doc { 24 | return builders.join(processComments(sep), processComments(docs)); 25 | } 26 | 27 | export function group(docs: Doc | IToken | (Doc | IToken)[], opts?: any) { 28 | const group = builders.group(processComments(docs), opts); 29 | return group.contents === undefined ? "" : group; 30 | } 31 | 32 | export function fill(docs: (Doc | IToken)[]) { 33 | return builders.fill(processComments(docs)); 34 | } 35 | 36 | export function indent(doc: Doc | IToken) { 37 | const processedDoc = processComments(doc); 38 | if (processedDoc.length === 0) { 39 | return ""; 40 | } 41 | 42 | return builders.indent(processedDoc); 43 | } 44 | 45 | export function dedent(doc: Doc | IToken) { 46 | const processedDoc = processComments(doc); 47 | if (processedDoc.length === 0) { 48 | return ""; 49 | } 50 | 51 | return builders.dedent(processComments(doc)); 52 | } 53 | 54 | export function ifBreak( 55 | breakContents: Doc | IToken, 56 | flatContents: Doc | IToken 57 | ) { 58 | return builders.ifBreak( 59 | processComments(breakContents), 60 | processComments(flatContents) 61 | ); 62 | } 63 | 64 | export function indentIfBreak(contents: Doc | IToken, opts?: any) { 65 | return builders.indentIfBreak(processComments(contents), opts); 66 | } 67 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/types/utils.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AbstractOrdinaryCompilationUnitCtx, 3 | AnnotationCstNode, 4 | CompilationUnitCtx, 5 | CstElement, 6 | CstNode, 7 | IToken, 8 | TypeArgumentsCstNode 9 | } from "java-parser/api"; 10 | 11 | export function isCstNode(tokenOrNode: CstElement): tokenOrNode is CstNode { 12 | return !isIToken(tokenOrNode); 13 | } 14 | 15 | export function isIToken(tokenOrNode: CstElement): tokenOrNode is IToken { 16 | return ( 17 | (tokenOrNode as IToken).tokenType !== undefined && 18 | (tokenOrNode as IToken).image !== undefined 19 | ); 20 | } 21 | 22 | export function isCstElementOrUndefinedIToken( 23 | tokenOrNode: CstElement | undefined 24 | ): tokenOrNode is IToken { 25 | return tokenOrNode !== undefined && isIToken(tokenOrNode); 26 | } 27 | 28 | export const isTypeArgumentsCstNode = ( 29 | cstElement: CstElement 30 | ): cstElement is TypeArgumentsCstNode => { 31 | return (cstElement as CstNode).name === "typeArguments"; 32 | }; 33 | 34 | export const isAnnotationCstNode = ( 35 | cstElement: CstElement 36 | ): cstElement is AnnotationCstNode => { 37 | return (cstElement as CstNode).name === "annotation"; 38 | }; 39 | 40 | export const isOrdinaryCompilationUnitCtx = ( 41 | ctx: CompilationUnitCtx 42 | ): ctx is AbstractOrdinaryCompilationUnitCtx => { 43 | return ( 44 | (ctx as AbstractOrdinaryCompilationUnitCtx).ordinaryCompilationUnit !== 45 | undefined 46 | ); 47 | }; 48 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/utils/index.ts: -------------------------------------------------------------------------------- 1 | export { default as printArgumentListWithBraces } from "./printArgumentListWithBraces.js"; 2 | export { default as isEmptyDoc } from "./isEmptyDoc.js"; 3 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/utils/isEmptyDoc.ts: -------------------------------------------------------------------------------- 1 | import { Doc } from "prettier"; 2 | 3 | const isEmptyDoc = (argument: Doc) => { 4 | return argument === "" || (Array.isArray(argument) && argument.length) === 0; 5 | }; 6 | 7 | export default isEmptyDoc; 8 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/src/utils/printArgumentListWithBraces.ts: -------------------------------------------------------------------------------- 1 | import type { ArgumentListCstNode, ArgumentListCtx, IToken } from "java-parser"; 2 | import { builders } from "prettier/doc"; 3 | import { handleCommentsParameters } from "../printers/comments/handle-comments.js"; 4 | import { indent } from "../printers/prettier-builder.js"; 5 | import { rejectAndConcat } from "../printers/printer-utils.js"; 6 | 7 | const { lineSuffixBoundary, softline } = builders; 8 | 9 | export default function printArgumentListWithBraces( 10 | argumentListNodes: ArgumentListCstNode[] | undefined, 11 | rBrace: IToken, 12 | lBrace: IToken 13 | ) { 14 | const argumentListNode = argumentListNodes?.[0]; 15 | const expressions = argumentListNode?.children.expression ?? []; 16 | if (argumentListNode) { 17 | const { leadingComments, trailingComments } = argumentListNode; 18 | delete argumentListNode.leadingComments; 19 | delete argumentListNode.trailingComments; 20 | if (leadingComments) { 21 | const firstExpression = expressions[0]; 22 | firstExpression.leadingComments = [ 23 | ...leadingComments, 24 | ...(firstExpression.leadingComments ?? []) 25 | ]; 26 | } 27 | if (trailingComments) { 28 | const lastExpression = expressions.at(-1)!; 29 | lastExpression.trailingComments = [ 30 | ...(lastExpression.trailingComments ?? []), 31 | ...trailingComments 32 | ]; 33 | } 34 | } 35 | handleCommentsParameters(lBrace, expressions, rBrace); 36 | 37 | const argumentList = this.visit(argumentListNodes); 38 | const contents = argumentList 39 | ? [argumentList] 40 | : lBrace.trailingComments 41 | ? [softline, lineSuffixBoundary] 42 | : []; 43 | return rejectAndConcat([indent(lBrace), ...contents, rBrace]); 44 | } 45 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test-samples/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true 3 | } 4 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/repository-test/core-test.ts: -------------------------------------------------------------------------------- 1 | import { dirname, resolve } from "path"; 2 | import url from "url"; 3 | import { testRepositorySample } from "../test-utils.js"; 4 | 5 | const __dirname = dirname(url.fileURLToPath(import.meta.url)); 6 | const jhipsterRepository = ["jhipster-bom", "jhipster-sample-app"]; 7 | 8 | describe("prettier-java", () => { 9 | testRepositorySample( 10 | resolve(__dirname, "../../samples/java-design-patterns"), 11 | "true", 12 | [] 13 | ); 14 | 15 | testRepositorySample( 16 | resolve(__dirname, "../../samples/spring-boot"), 17 | "./gradlew", 18 | ["compileJava"] 19 | ); 20 | 21 | jhipsterRepository.forEach(repository => { 22 | testRepositorySample( 23 | resolve(__dirname, `../../samples/${repository}`), 24 | "./mvnw", 25 | ["compile"] 26 | ); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/repository-test/jhipster-1-test.ts: -------------------------------------------------------------------------------- 1 | import { dirname, resolve } from "path"; 2 | import url from "url"; 3 | import { testRepositorySample } from "../test-utils.js"; 4 | 5 | const __dirname = dirname(url.fileURLToPath(import.meta.url)); 6 | const jhipsterRepository = [ 7 | "jhipster-sample-app-microservice", 8 | "jhipster-sample-app-oauth2", 9 | "jhipster-sample-app-websocket", 10 | "jhipster-sample-app-noi18n", 11 | "jhipster-sample-app-hazelcast" 12 | ]; 13 | 14 | describe("prettier-java", () => { 15 | jhipsterRepository.forEach(repository => { 16 | testRepositorySample( 17 | resolve(__dirname, `../../samples/${repository}`), 18 | "./mvnw", 19 | ["compile"] 20 | ); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/repository-test/jhipster-2-test.ts: -------------------------------------------------------------------------------- 1 | import { dirname, resolve } from "path"; 2 | import url from "url"; 3 | import { testRepositorySample } from "../test-utils.js"; 4 | 5 | const __dirname = dirname(url.fileURLToPath(import.meta.url)); 6 | const jhipsterRepository = [ 7 | "jhipster-sample-app-elasticsearch", 8 | "jhipster-sample-app-dto", 9 | "jhipster-sample-app-cassandra", 10 | "jhipster-sample-app-mongodb", 11 | "jhipster-sample-app-react" 12 | ]; 13 | 14 | describe("prettier-java", () => { 15 | jhipsterRepository.forEach(repository => { 16 | testRepositorySample( 17 | resolve(__dirname, `../../samples/${repository}`), 18 | "./mvnw", 19 | ["compile"] 20 | ); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/annotation_interface_declaration/_input.java: -------------------------------------------------------------------------------- 1 | public @interface AnnotationInterfaceDeclaration { 2 | public String value() default ""; 3 | @RandomAnnotation Integer[][] annotatedArray = (Integer[][]) new Object[4][2]; 4 | @RandomBreakingAnnotation(one = "One", two = "Two", three = "Three", four = "Four", five = "Five") 5 | Integer[][] annotatedArray = (Integer[][]) new Object[4][2]; 6 | @RandomAnnotationWithObject({"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"}) 7 | V[][] annotatedArray = (V[][]) new Object[rowList.size()][columnList.size()]; 8 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/annotation_interface_declaration/_output.java: -------------------------------------------------------------------------------- 1 | public @interface AnnotationInterfaceDeclaration { 2 | public String value() default ""; 3 | 4 | @RandomAnnotation 5 | Integer[][] annotatedArray = (Integer[][]) new Object[4][2]; 6 | 7 | @RandomBreakingAnnotation( 8 | one = "One", 9 | two = "Two", 10 | three = "Three", 11 | four = "Four", 12 | five = "Five" 13 | ) 14 | Integer[][] annotatedArray = (Integer[][]) new Object[4][2]; 15 | 16 | @RandomAnnotationWithObject( 17 | { 18 | "One", 19 | "Two", 20 | "Three", 21 | "Four", 22 | "Five", 23 | "Six", 24 | "Seven", 25 | "Eight", 26 | "Nine", 27 | "Ten", 28 | } 29 | ) 30 | V[][] annotatedArray = (V[][]) new Object[rowList.size()][columnList.size()]; 31 | } 32 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/annotation_interface_declaration/annotation_interface_declaration-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/args/_input.java: -------------------------------------------------------------------------------- 1 | public class Args { 2 | 3 | public static void main(String[] args) { 4 | } 5 | 6 | public void none() {} 7 | 8 | public void one(String one) {} 9 | 10 | public void three(String one, Integer two, String three) {} 11 | 12 | public void longListOfParametersThatShouldBreak(String one, Integer two, String three, Integer four, String five, Integer six) {} 13 | 14 | void lastParameterDotDotDot(String str1, String... str2) { 15 | } 16 | 17 | void variableArityParameters(Object @Nullable... errorMessageArgs) {} 18 | 19 | void variableArityParameters(Object[] @Nullable... errorMessageArgs) {} 20 | 21 | void variableArityParameters(byte[] @Nullable... errorMessageArgs) {} 22 | 23 | void variableArityParameters(byte @Nullable... errorMessageArgs) {} 24 | 25 | void variableArityParameters(final String... strings) {} 26 | 27 | void variableArityParameters(byte... bytes) {} 28 | 29 | void variableArityParameters(final String[]... strings) {} 30 | 31 | void variableArityParameters(byte[]... bytes) {} 32 | 33 | } 34 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/args/_output.java: -------------------------------------------------------------------------------- 1 | public class Args { 2 | 3 | public static void main(String[] args) {} 4 | 5 | public void none() {} 6 | 7 | public void one(String one) {} 8 | 9 | public void three(String one, Integer two, String three) {} 10 | 11 | public void longListOfParametersThatShouldBreak( 12 | String one, 13 | Integer two, 14 | String three, 15 | Integer four, 16 | String five, 17 | Integer six 18 | ) {} 19 | 20 | void lastParameterDotDotDot(String str1, String... str2) {} 21 | 22 | void variableArityParameters(Object @Nullable... errorMessageArgs) {} 23 | 24 | void variableArityParameters(Object[] @Nullable... errorMessageArgs) {} 25 | 26 | void variableArityParameters(byte[] @Nullable... errorMessageArgs) {} 27 | 28 | void variableArityParameters(byte @Nullable... errorMessageArgs) {} 29 | 30 | void variableArityParameters(final String... strings) {} 31 | 32 | void variableArityParameters(byte... bytes) {} 33 | 34 | void variableArityParameters(final String[]... strings) {} 35 | 36 | void variableArityParameters(byte[]... bytes) {} 37 | } 38 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/args/args-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/arrays/_input.java: -------------------------------------------------------------------------------- 1 | class Array { 2 | boolean[] skip = new boolean[candidates.length]; 3 | 4 | Class aaaaaaaaaaaaaaaa = new Aaaaaaaaaaaaaaaa[1].getClass(); 5 | Class aaaaaaaaaaaaaaaa = new Aaaaaaaaaaaaaaaa[1111111111111111111].getClass(); 6 | Class aaaaaaaaaaaaaaaa = new Aaaaaaaaaaaaaaaa[]{ new Aaaaaaaaaaaaaaaa() }.getClass(); 7 | } 8 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/arrays/_output.java: -------------------------------------------------------------------------------- 1 | class Array { 2 | 3 | boolean[] skip = new boolean[candidates.length]; 4 | 5 | Class aaaaaaaaaaaaaaaa = new Aaaaaaaaaaaaaaaa< 6 | Bbbbbbbbbbbbbbbb 7 | >[1].getClass(); 8 | Class aaaaaaaaaaaaaaaa = new Aaaaaaaaaaaaaaaa[1111111111111111111] 9 | .getClass(); 10 | Class aaaaaaaaaaaaaaaa = new Aaaaaaaaaaaaaaaa[] { 11 | new Aaaaaaaaaaaaaaaa(), 12 | }.getClass(); 13 | } 14 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/arrays/arrays-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("arrays", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/assert/_input.java: -------------------------------------------------------------------------------- 1 | public class Assert { 2 | 3 | public void assertBooleanExpression(String myVar) { 4 | assert (myVar != null); 5 | } 6 | 7 | public void assertValueExpression(String myVar) { 8 | assert (myVar != null) : "text"; 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/assert/_output.java: -------------------------------------------------------------------------------- 1 | public class Assert { 2 | 3 | public void assertBooleanExpression(String myVar) { 4 | assert (myVar != null); 5 | } 6 | 7 | public void assertValueExpression(String myVar) { 8 | assert (myVar != null) : "text"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/assert/assert-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/binary_expressions/binary_expressions-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/blank_lines/_input.java: -------------------------------------------------------------------------------- 1 | public class BlankLines { 2 | 3 | public int i = 1; 4 | public int j = 2; 5 | 6 | 7 | 8 | public int k = 3; 9 | public int l = 4; 10 | 11 | // Bug Fix: https://github.com/jhipster/prettier-java/issues/368 12 | private String fieldOne; 13 | private String fieldTwo; 14 | @Nullable private String shouldAddLineBeforeAndAfter; 15 | private String fieldThree; 16 | private String fieldFour; 17 | 18 | private String a; 19 | private String b; 20 | private @Nullable String shouldNotAddBlankLines; 21 | private String d; 22 | private String e; 23 | 24 | public int m = 4; 25 | public Constructors() { 26 | this(true); 27 | System.out.println("empty constructor"); 28 | } 29 | public void shouldAddLineBefore() { 30 | System.out.println("Should add empty line before method"); 31 | } 32 | 33 | 34 | 35 | 36 | public void shouldAddOnlyOneLineBefore() { 37 | System.out.println("Should add only one empty line between the two methods"); 38 | } 39 | private C c; 40 | 41 | 42 | public void shouldAlsoAddOnlyOneLineBefore() { 43 | System.out.println("Should add only one empty line between the two class statement"); 44 | } 45 | 46 | public void shouldHandleBlankLinesInBlock() { 47 | int i = 1; 48 | int j = 2; 49 | 50 | 51 | 52 | int k = 3; 53 | int l = 4; 54 | 55 | int m = 4; 56 | // Add a line before comment 57 | int n = 4; 58 | for (int p=0; p<3;p++); 59 | 60 | } 61 | 62 | } 63 | 64 | interface BlankLinesInInterfaces { 65 | // Bug Fix: https://github.com/jhipster/prettier-java/issues/368 66 | String fieldOne; 67 | String fieldTwo; 68 | @Nullable String shouldAddLineBeforeAndAfter; 69 | String fieldThree; 70 | String fieldFour; 71 | 72 | private @Nullable String test(); 73 | private @Nullable static String test(); 74 | private @Nullable String test(); 75 | private @Nullable String test(); 76 | @Nullable 77 | private static String test(); 78 | private @Nullable String test(); 79 | private static String test(); 80 | @Nullable String test(); 81 | } 82 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/blank_lines/blank_lines-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/bug-fixes/_input.java: -------------------------------------------------------------------------------- 1 | class T { 2 | // Fix for https://github.com/jhipster/prettier-java/issues/453 3 | SomeClass.@Valid SomeInnerClass someInnerClass = someClass.getInteractions().get(0); 4 | 5 | // Fix for https://github.com/jhipster/prettier-java/issues/444 6 | void process( 7 | Map.@NonNull Entry entry, 8 | @NonNull Map context 9 | ) {} 10 | } 11 | 12 | // Fix for https://github.com/jhipster/prettier-java/issues/607 13 | class Currency { 14 | Currency(Currency this) {} 15 | 16 | Currency(Currency this, Currency other) {} 17 | 18 | Currency(@AnnotatedUsage Currency this, Currency other) {} 19 | 20 | Currency(@AnnotatedUsage Currency this, String aaaaaaaaaa, String bbbbbbbbbb) {} 21 | 22 | String getCode(Currency this) {} 23 | 24 | int compareTo(Currency this, Currency other) {} 25 | 26 | int compareTo(@AnnotatedUsage Currency this, Currency other) {} 27 | 28 | int compareTo(@AnnotatedUsage Currency this, String aaaaaaaaaa, String bbbbbbbbbb) {} 29 | 30 | class Inner { 31 | Inner(Currency Currency.this) {} 32 | 33 | String getCode(Currency Currency.this) {} 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/bug-fixes/_output.java: -------------------------------------------------------------------------------- 1 | class T { 2 | 3 | // Fix for https://github.com/jhipster/prettier-java/issues/453 4 | SomeClass.@Valid SomeInnerClass someInnerClass = someClass 5 | .getInteractions() 6 | .get(0); 7 | 8 | // Fix for https://github.com/jhipster/prettier-java/issues/444 9 | void process( 10 | Map.@NonNull Entry entry, 11 | @NonNull Map context 12 | ) {} 13 | } 14 | 15 | // Fix for https://github.com/jhipster/prettier-java/issues/607 16 | class Currency { 17 | 18 | Currency(Currency this) {} 19 | 20 | Currency(Currency this, Currency other) {} 21 | 22 | Currency(@AnnotatedUsage Currency this, Currency other) {} 23 | 24 | Currency( 25 | @AnnotatedUsage Currency this, 26 | String aaaaaaaaaa, 27 | String bbbbbbbbbb 28 | ) {} 29 | 30 | String getCode(Currency this) {} 31 | 32 | int compareTo(Currency this, Currency other) {} 33 | 34 | int compareTo(@AnnotatedUsage Currency this, Currency other) {} 35 | 36 | int compareTo( 37 | @AnnotatedUsage Currency this, 38 | String aaaaaaaaaa, 39 | String bbbbbbbbbb 40 | ) {} 41 | 42 | class Inner { 43 | 44 | Inner(Currency Currency.this) {} 45 | 46 | String getCode(Currency Currency.this) {} 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/bug-fixes/bug-fixes-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/cast/_input.java: -------------------------------------------------------------------------------- 1 | public class Cast { 2 | 3 | void should_cast_with_single_element() { 4 | var myElem = (int) othrElement; 5 | var myElem = (A) othrElement; 6 | var myElem = (A) (othrElement, value) -> othrElement + value; 7 | var myElem = (Aaeaozeaonzeoazneaozenazonelkadndpndpazdpazdpazdpazdpazeazpeaazdpazdpazpdazdpa) othrElement; 8 | } 9 | 10 | void should_cast_with_additional_bounds() { 11 | foo((A & B) obj); 12 | foo((A & B & C) obj); 13 | foo((Aaeaozeaonzeoazneaozenazone & Bazoieoainzeonaozenoazne & Cjneazeanezoanezoanzeoaneonazeono) obj); 14 | foo((Aaeaozeaonzeoazneaozenazone & Bazoieoainzeonaozenoazne & Cjneazeanezoanezoanzeoaneonazeono) (othrElement, value) -> othrElement + value); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/cast/_output.java: -------------------------------------------------------------------------------- 1 | public class Cast { 2 | 3 | void should_cast_with_single_element() { 4 | var myElem = (int) othrElement; 5 | var myElem = (A) othrElement; 6 | var myElem = (A) (othrElement, value) -> othrElement + value; 7 | var myElem = 8 | (Aaeaozeaonzeoazneaozenazonelkadndpndpazdpazdpazdpazdpazeazpeaazdpazdpazpdazdpa) othrElement; 9 | } 10 | 11 | void should_cast_with_additional_bounds() { 12 | foo((A & B) obj); 13 | foo((A & B & C) obj); 14 | foo( 15 | ( 16 | Aaeaozeaonzeoazneaozenazone 17 | & Bazoieoainzeonaozenoazne 18 | & Cjneazeanezoanezoanzeoaneonazeono 19 | ) obj 20 | ); 21 | foo( 22 | ( 23 | Aaeaozeaonzeoazneaozenazone 24 | & Bazoieoainzeonaozenoazne 25 | & Cjneazeanezoanezoanzeoaneonazeono 26 | ) (othrElement, value) -> othrElement + value 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/cast/cast-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("cast", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/char_literal/_input.java: -------------------------------------------------------------------------------- 1 | public class CharLiteral { 2 | 3 | final char singleQuote = '\''; 4 | 5 | final char backslash = '\\'; 6 | 7 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/char_literal/_output.java: -------------------------------------------------------------------------------- 1 | public class CharLiteral { 2 | 3 | final char singleQuote = '\''; 4 | 5 | final char backslash = '\\'; 6 | } 7 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/char_literal/char_literal-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/classes/_input.java: -------------------------------------------------------------------------------- 1 | class A {} 2 | 3 | abstract class B {} 4 | 5 | 6 | 7 | class C {} 8 | 9 | public class ClassDeclaration { 10 | 11 | public void testMethod() { 12 | 13 | class LocalClassDeclaration { 14 | } 15 | 16 | } 17 | 18 | } 19 | 20 | class ClassWithSemicolon { 21 | ; 22 | private FieldOneClass fieldOne; 23 | } 24 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/classes/_output.java: -------------------------------------------------------------------------------- 1 | class A {} 2 | 3 | abstract class B {} 4 | 5 | class C {} 6 | 7 | public class ClassDeclaration { 8 | 9 | public void testMethod() { 10 | class LocalClassDeclaration {} 11 | } 12 | } 13 | 14 | class ClassWithSemicolon { 15 | 16 | private FieldOneClass fieldOne; 17 | } 18 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/classes/multiple_classes-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/bug-fixes/_input.java: -------------------------------------------------------------------------------- 1 | // Bug Fix: #279 - See also https://prettier.io/docs/en/rationale.html#comments 2 | class T { 3 | /* 4 | * comment 5 | */ 6 | void t() { 7 | 8 | } 9 | 10 | /* 11 | * comment 12 | */ 13 | void t() { 14 | 15 | } 16 | 17 | /* 18 | * comment 19 | */ 20 | void t() { 21 | 22 | } 23 | 24 | /* 25 | * comment 26 | */ 27 | void t() { 28 | 29 | } 30 | 31 | /* 32 | * line 1 33 | line 2 34 | */ 35 | void t() { 36 | 37 | } 38 | 39 | /* 40 | 41 | *line 2 42 | */ 43 | void t() { 44 | 45 | } 46 | 47 | public static final List XXXXXXXXXXXXXXXXXX = Collections.unmodifiableList( 48 | Arrays.asList(// a 49 | // b 50 | // c 51 | // d 52 | ) 53 | ); 54 | 55 | public static final List XXXXXXXXXXXXXXXXXX = Collections.unmodifiableList( 56 | Arrays.asList(// a 57 | // b 58 | // c 59 | // d 60 | /*e*/) 61 | ); 62 | } 63 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/bug-fixes/_output.java: -------------------------------------------------------------------------------- 1 | // Bug Fix: #279 - See also https://prettier.io/docs/en/rationale.html#comments 2 | class T { 3 | 4 | /* 5 | * comment 6 | */ 7 | void t() {} 8 | 9 | /* 10 | * comment 11 | */ 12 | void t() {} 13 | 14 | /* 15 | * comment 16 | */ 17 | void t() {} 18 | 19 | /* 20 | * comment 21 | */ 22 | void t() {} 23 | 24 | /* 25 | * line 1 26 | line 2 27 | */ 28 | void t() {} 29 | 30 | /* 31 | 32 | *line 2 33 | */ 34 | void t() {} 35 | 36 | public static final List XXXXXXXXXXXXXXXXXX = 37 | Collections.unmodifiableList( 38 | Arrays.asList( // a 39 | // b 40 | // c 41 | // d 42 | ) 43 | ); 44 | 45 | public static final List XXXXXXXXXXXXXXXXXX = 46 | Collections.unmodifiableList( 47 | Arrays.asList( // a 48 | // b 49 | // c 50 | // d 51 | /*e*/ 52 | ) 53 | ); 54 | } 55 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/end-of-block/_input.java: -------------------------------------------------------------------------------- 1 | class A { 2 | 3 | } 4 | 5 | class B { 6 | // alpha 7 | } 8 | 9 | class C { 10 | // alpha 11 | // beta 12 | } 13 | 14 | class D { 15 | // alpha 16 | // beta 17 | /* gamma */ 18 | } 19 | 20 | class E { // alpha 21 | } 22 | 23 | class F {/* alpha */} 24 | 25 | class G { 26 | /* alpha */ 27 | /* beta */ 28 | } 29 | 30 | class H { 31 | /* alpha */ 32 | // beta 33 | } 34 | 35 | 36 | class I { // alpha 37 | // beta 38 | int i; 39 | 40 | // one 41 | // two 42 | /* three */ 43 | } 44 | 45 | class J { 46 | 47 | void one( 48 | 49 | ) {} 50 | 51 | void two( 52 | // alpha 53 | ) {} 54 | 55 | void three( 56 | // alpha 57 | // beta 58 | ) {} 59 | 60 | void four( 61 | // alpha 62 | // beta 63 | /* gamma */ 64 | ) {} 65 | 66 | void five( // alpha 67 | ) {} 68 | 69 | void fiveBis( // alpha 70 | ) { 71 | int i; 72 | } 73 | 74 | void six(/* alpha */) {} 75 | 76 | void seven( 77 | /* alpha */ 78 | /* beta */ 79 | ) {} 80 | 81 | void eight( 82 | /* alpha */ 83 | // beta 84 | ) {} 85 | 86 | void nine( 87 | /* alpha */ 88 | ) {} 89 | 90 | void one( 91 | String one 92 | ) {} 93 | 94 | void two( 95 | String one 96 | // alpha 97 | ) {} 98 | 99 | void three( 100 | String one 101 | // alpha 102 | // beta 103 | ) {} 104 | 105 | void four( 106 | // alpha 107 | String one 108 | // beta 109 | /* gamma */ 110 | ) {} 111 | 112 | void five(String one // alpha 113 | 114 | ) {} 115 | 116 | void six(String one/* alpha */) {} 117 | 118 | void seven( 119 | /* alpha */ 120 | String one 121 | /* beta */ 122 | ) {} 123 | 124 | void eight( 125 | /* alpha */ 126 | String one 127 | // beta 128 | ) {} 129 | 130 | void nine(String one 131 | /* alpha */ 132 | ) {} 133 | } 134 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/end-of-block/_output.java: -------------------------------------------------------------------------------- 1 | class A {} 2 | 3 | class B { 4 | // alpha 5 | } 6 | 7 | class C { 8 | // alpha 9 | // beta 10 | } 11 | 12 | class D { 13 | // alpha 14 | // beta 15 | /* gamma */ 16 | } 17 | 18 | class E { // alpha 19 | } 20 | 21 | class F { 22 | /* alpha */ 23 | } 24 | 25 | class G { 26 | /* alpha */ 27 | /* beta */ 28 | } 29 | 30 | class H { 31 | /* alpha */ 32 | // beta 33 | } 34 | 35 | class I { // alpha 36 | 37 | // beta 38 | int i; 39 | // one 40 | // two 41 | /* three */ 42 | } 43 | 44 | class J { 45 | 46 | void one() {} 47 | 48 | void two( 49 | // alpha 50 | ) {} 51 | 52 | void three( 53 | // alpha 54 | // beta 55 | ) {} 56 | 57 | void four( 58 | // alpha 59 | // beta 60 | /* gamma */ 61 | ) {} 62 | 63 | void five( // alpha 64 | ) {} 65 | 66 | void fiveBis( // alpha 67 | ) { 68 | int i; 69 | } 70 | 71 | void six(/* alpha */) {} 72 | 73 | void seven( 74 | /* alpha */ 75 | /* beta */ 76 | ) {} 77 | 78 | void eight( 79 | /* alpha */ 80 | // beta 81 | ) {} 82 | 83 | void nine( 84 | /* alpha */ 85 | ) {} 86 | 87 | void one(String one) {} 88 | 89 | void two( 90 | String one 91 | // alpha 92 | ) {} 93 | 94 | void three( 95 | String one 96 | // alpha 97 | // beta 98 | ) {} 99 | 100 | void four( 101 | // alpha 102 | String one 103 | // beta 104 | /* gamma */ 105 | ) {} 106 | 107 | void five( 108 | String one // alpha 109 | ) {} 110 | 111 | void six(String one/* alpha */) {} 112 | 113 | void seven( 114 | /* alpha */ 115 | String one 116 | /* beta */ 117 | ) {} 118 | 119 | void eight( 120 | /* alpha */ 121 | String one 122 | // beta 123 | ) {} 124 | 125 | void nine( 126 | String one 127 | /* alpha */ 128 | ) {} 129 | } 130 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/if-statement/_input.java: -------------------------------------------------------------------------------- 1 | class IfStatements { 2 | 3 | void commentsIfLineComment() { 4 | if ( // test 5 | t) { 6 | } 7 | 8 | if (t // test 9 | ) { 10 | } 11 | 12 | if (t) { 13 | } // test 14 | 15 | if ( // test 16 | t) { 17 | } 18 | } 19 | 20 | void commentsIfBlockComment() { 21 | if (/* test */ 22 | t) { 23 | } 24 | 25 | if (t/* test */ 26 | ) { 27 | } 28 | 29 | if (t)/* test */ { 30 | } 31 | 32 | if/* test */ (t) { 33 | } 34 | } 35 | 36 | void commentsElseLineComment() { 37 | if (t) { 38 | } // test 39 | else { 40 | } 41 | 42 | if (t) { 43 | } else { 44 | } // test 45 | } 46 | 47 | void commentsElseBlockComment() { 48 | if (t) { 49 | } /* test */ else { 50 | } 51 | 52 | if (t) { 53 | } else/* test */ { 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/comments-blocks-and-statements/if-statement/_output.java: -------------------------------------------------------------------------------- 1 | class IfStatements { 2 | 3 | void commentsIfLineComment() { 4 | if ( // test 5 | t 6 | ) {} 7 | 8 | if ( 9 | t // test 10 | ) {} 11 | 12 | if (t) {} // test 13 | 14 | if ( // test 15 | t 16 | ) {} 17 | } 18 | 19 | void commentsIfBlockComment() { 20 | if (/* test */t) {} 21 | 22 | if (t/* test */) {} 23 | 24 | if (t) /* test */{} 25 | 26 | if /* test */(t) {} 27 | } 28 | 29 | void commentsElseLineComment() { 30 | if (t) {} // test 31 | else {} 32 | 33 | if (t) {} else {} // test 34 | } 35 | 36 | void commentsElseBlockComment() { 37 | if (t) {} /* test */else {} 38 | 39 | if (t) {} else /* test */{} 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/comments-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(path.resolve(__dirname, "./class")); 9 | testSample(path.resolve(__dirname, "./edge")); 10 | testSample(path.resolve(__dirname, "./expression")); 11 | testSample(path.resolve(__dirname, "./interface")); 12 | testSample(path.resolve(__dirname, "./package")); 13 | testSample( 14 | path.resolve(__dirname, "./comments-blocks-and-statements/complex") 15 | ); 16 | testSample( 17 | path.resolve(__dirname, "./comments-blocks-and-statements/if-statement") 18 | ); 19 | testSample( 20 | path.resolve( 21 | __dirname, 22 | "./comments-blocks-and-statements/labeled-statement" 23 | ) 24 | ); 25 | testSample(path.resolve(__dirname, "./comments-only")); 26 | testSample(path.resolve(__dirname, "./bug-fixes")); 27 | }); 28 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/expression/_input.java: -------------------------------------------------------------------------------- 1 | class Example { 2 | 3 | void example() { 4 | 0 // 5 | + 1; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/expression/_output.java: -------------------------------------------------------------------------------- 1 | class Example { 2 | 3 | void example() { 4 | 0 + // 5 | 1; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/interface/_input.java: -------------------------------------------------------------------------------- 1 | import com.other.interfaces.OfferedI; 2 | import com.other.interfaces.RequiredI; 3 | 4 | /** 5 | * This is the comment describing the interface 6 | */ 7 | public /*a*/interface/*b*/ MyInterface /*a*/extends/*b*/ /*a*/OfferedI/*b*/ /*a*/,/*b*/ /*a*/RequiredI/*b*/ { 8 | 9 | // comment 10 | /** 11 | * Javadoc 12 | * @param p1 parameter 1 13 | * @param p2 parameter 2 14 | * @throws Exception Exception comment 15 | * @throws RuntimeException RuntimeException comment 16 | */ 17 | public void myMethodInterface(Param1 /*a*/p1/*b*/ /*a*/,/*b*/ /*a*/Param2/*b*/ /*a*/p2/*b*/, Param3 p3) /*a*/throws/*b*/ Exception/*a*/,/*b*/ RuntimeException/*a*/;/*b*/ 18 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/interface/_output.java: -------------------------------------------------------------------------------- 1 | import com.other.interfaces.OfferedI; 2 | import com.other.interfaces.RequiredI; 3 | 4 | /** 5 | * This is the comment describing the interface 6 | */ 7 | public /*a*/interface /*b*/MyInterface 8 | /*a*/extends /*b*//*a*/OfferedI/*b*//*a*/, /*b*//*a*/RequiredI /*b*/{ 9 | // comment 10 | /** 11 | * Javadoc 12 | * @param p1 parameter 1 13 | * @param p2 parameter 2 14 | * @throws Exception Exception comment 15 | * @throws RuntimeException RuntimeException comment 16 | */ 17 | public void myMethodInterface( 18 | Param1 /*a*/p1/*b*//*a*/, 19 | /*b*//*a*/Param2 /*b*//*a*/p2/*b*/, 20 | Param3 p3 21 | ) /*a*/throws /*b*/Exception/*a*/, /*b*/RuntimeException /*a*/;/*b*/ 22 | } 23 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/package/_input.java: -------------------------------------------------------------------------------- 1 | /*a*/open/*b*/ /*a*/module/*b*/ soat/*a*/./*b*/vending.machine.gui { 2 | /*a*/requires/*a*/ java.desktopa /*a*/;/*b*/ 3 | requires soat.vending.machine.model; 4 | requires /*a*/transitive/*b*/ soat.core; 5 | /*a*/ exports /*b*/ fr.soat.vending.machine.model /*a*/to/*b*/ another /*a*/,/*b*/ again /*c*/,/*d*/ ano /*a*/;/*b*/ 6 | 7 | // opens 8 | /*a*/ opens /*b*/ fr.soat.vending.machine.model /*a*/to/*b*/ another /*a*/,/*b*/ again /*c*/,/*d*/ ano /*a*/;/*b*/ 9 | 10 | 11 | // uses 12 | /*a*/uses/*b*/ fr.soat.vendinga/*a*/./*b*/machine.services.DrinksService /*a*/;/*b*/ 13 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/comments/package/_output.java: -------------------------------------------------------------------------------- 1 | /*a*/open /*b*//*a*/module /*b*/soat/*a*/./*b*/vending.machine.gui { 2 | /*a*/requires /*a*/java.desktopa/*a*/;/*b*/ 3 | requires soat.vending.machine.model; 4 | requires /*a*/transitive /*b*/soat.core; 5 | /*a*/exports /*b*/fr.soat.vending.machine.model 6 | /*a*/to /*b*/another/*a*/, /*b*/again/*c*/, /*d*/ano/*a*/;/*b*/ 7 | 8 | // opens 9 | /*a*/opens /*b*/fr.soat.vending.machine.model 10 | /*a*/to /*b*/another/*a*/, /*b*/again/*c*/, /*d*/ano/*a*/;/*b*/ 11 | 12 | // uses 13 | /*a*/uses /*b*/fr.soat.vendinga/*a*/./*b*/machine.services.DrinksService/*a*/;/*b*/ 14 | } 15 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/complex_generic_class/_input.java: -------------------------------------------------------------------------------- 1 | public class GenericClass> { 2 | private BEAN bean; 3 | 4 | public GenericClass(BEAN bean) { 5 | this.bean = bean; 6 | } 7 | 8 | public BEAN setBean(BEAN bean) { 9 | this.bean = bean; 10 | return bean; 11 | } 12 | 13 | public > T doSomething(T t) { 14 | return t; 15 | } 16 | 17 | public void addAll(final Collection c) { 18 | for (final E e : c) { 19 | add(e); 20 | } 21 | } 22 | 23 | } 24 | 25 | public abstract class AbstractGenericClass { 26 | public Value getValue() { 27 | return new Value(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/complex_generic_class/_output.java: -------------------------------------------------------------------------------- 1 | public class GenericClass> { 2 | 3 | private BEAN bean; 4 | 5 | public GenericClass(BEAN bean) { 6 | this.bean = bean; 7 | } 8 | 9 | public BEAN setBean(BEAN bean) { 10 | this.bean = bean; 11 | return bean; 12 | } 13 | 14 | public > T doSomething(T t) { 15 | return t; 16 | } 17 | 18 | public void addAll(final Collection c) { 19 | for (final E e : c) { 20 | add(e); 21 | } 22 | } 23 | } 24 | 25 | public abstract class AbstractGenericClass< 26 | Value extends AbstractValue, 27 | Value1 extends AbstractValue, 28 | Value2 extends AbstractValue, 29 | Value3 extends AbstractValue, 30 | Value4 extends AbstractValue, 31 | Value5 extends AbstractValue 32 | > { 33 | 34 | public Value getValue() { 35 | return new Value(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/complex_generic_class/complex_generic_class-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/constructors/_input.java: -------------------------------------------------------------------------------- 1 | public class Constructors { 2 | 3 | public Constructors() { 4 | this(true); 5 | System.out.println("empty constructor"); 6 | } 7 | 8 | Constructors(boolean one) { 9 | super(); 10 | System.out.println("constructor with boolean " + one); 11 | } 12 | 13 | Constructors(boolean one, boolean two) { 14 | this(); 15 | System.out.println("constructor with boolean " + one + " and " + two); 16 | } 17 | 18 | Constructors( 19 | boolean one, 20 | boolean two, 21 | boolean three, 22 | boolean four, 23 | boolean five, 24 | boolean six 25 | ) { 26 | this(); 27 | System.out.println("constructor with six parameters that should wrap"); 28 | } 29 | 30 | Constructors() { 31 | super("lots", "of", "parameters", "when there is not enough space", "should wrap well"); 32 | System.out.println("constructor with super that wraps"); 33 | } 34 | 35 | Constructors() { 36 | super("enough parameter", "fit"); 37 | System.out.println("constructor with super that does not wrap"); 38 | } 39 | 40 | Constructors() { 41 | this("lots", "of", "parameters", "when there is not enough space", "should wrap well"); 42 | System.out.println("constructor with this that wraps"); 43 | } 44 | 45 | Constructors() { 46 | this("enough parameter", "fit"); 47 | System.out.println("constructor with this that does not wrap"); 48 | } 49 | 50 | public GenericConstructor(T genericParameter) {} 51 | public GenericConstructor(T genericParameter) {} 52 | } 53 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/constructors/_output.java: -------------------------------------------------------------------------------- 1 | public class Constructors { 2 | 3 | public Constructors() { 4 | this(true); 5 | System.out.println("empty constructor"); 6 | } 7 | 8 | Constructors(boolean one) { 9 | super(); 10 | System.out.println("constructor with boolean " + one); 11 | } 12 | 13 | Constructors(boolean one, boolean two) { 14 | this(); 15 | System.out.println("constructor with boolean " + one + " and " + two); 16 | } 17 | 18 | Constructors( 19 | boolean one, 20 | boolean two, 21 | boolean three, 22 | boolean four, 23 | boolean five, 24 | boolean six 25 | ) { 26 | this(); 27 | System.out.println("constructor with six parameters that should wrap"); 28 | } 29 | 30 | Constructors() { 31 | super( 32 | "lots", 33 | "of", 34 | "parameters", 35 | "when there is not enough space", 36 | "should wrap well" 37 | ); 38 | System.out.println("constructor with super that wraps"); 39 | } 40 | 41 | Constructors() { 42 | super("enough parameter", "fit"); 43 | System.out.println("constructor with super that does not wrap"); 44 | } 45 | 46 | Constructors() { 47 | this( 48 | "lots", 49 | "of", 50 | "parameters", 51 | "when there is not enough space", 52 | "should wrap well" 53 | ); 54 | System.out.println("constructor with this that wraps"); 55 | } 56 | 57 | Constructors() { 58 | this("enough parameter", "fit"); 59 | System.out.println("constructor with this that does not wrap"); 60 | } 61 | 62 | public GenericConstructor(T genericParameter) {} 63 | 64 | public GenericConstructor(T genericParameter) {} 65 | } 66 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/constructors/constructors-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/empty_statement/empty_statement-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/enum/enum-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/expressions/expressions-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/extends_abstract_class/_input.java: -------------------------------------------------------------------------------- 1 | public class ExtendsAbstractClass extends AbstractClass { 2 | 3 | @Override 4 | public void abstractMethod() { 5 | System.out.println("implemented abstract method"); 6 | } 7 | 8 | @Override 9 | public int hashCode() { 10 | return super.hashCode(); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/extends_abstract_class/_output.java: -------------------------------------------------------------------------------- 1 | public class ExtendsAbstractClass extends AbstractClass { 2 | 3 | @Override 4 | public void abstractMethod() { 5 | System.out.println("implemented abstract method"); 6 | } 7 | 8 | @Override 9 | public int hashCode() { 10 | return super.hashCode(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/extends_abstract_class/extends_abstract_class-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/extends_abstract_class_and_implements_interfaces/_input.java: -------------------------------------------------------------------------------- 1 | public class ExtendsAbstractClassAndImplementsInterfaces extends AbstractClass implements Interface1, Interface2, Interface3, Interface4 { 2 | 3 | @Override 4 | public void abstractMethod() { 5 | System.out.println("implemented abstract method"); 6 | } 7 | 8 | @Override 9 | public void interface1Method() { 10 | System.out.println("implemented interfac1 method"); 11 | } 12 | 13 | @Override 14 | public void interface2Method() { 15 | System.out.println("implemented interface2 method"); 16 | } 17 | 18 | } 19 | 20 | public class ExtendsAbstractClassAndImplementsInterfaces extends AbstractClass implements Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7, Interface8 { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/extends_abstract_class_and_implements_interfaces/_output.java: -------------------------------------------------------------------------------- 1 | public class ExtendsAbstractClassAndImplementsInterfaces 2 | extends AbstractClass 3 | implements Interface1, Interface2, Interface3, Interface4 { 4 | 5 | @Override 6 | public void abstractMethod() { 7 | System.out.println("implemented abstract method"); 8 | } 9 | 10 | @Override 11 | public void interface1Method() { 12 | System.out.println("implemented interfac1 method"); 13 | } 14 | 15 | @Override 16 | public void interface2Method() { 17 | System.out.println("implemented interface2 method"); 18 | } 19 | } 20 | 21 | public class ExtendsAbstractClassAndImplementsInterfaces 22 | extends AbstractClass 23 | implements 24 | Interface1, 25 | Interface2, 26 | Interface3, 27 | Interface4, 28 | Interface5, 29 | Interface6, 30 | Interface7, 31 | Interface8 {} 32 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/extends_abstract_class_and_implements_interfaces/extends_abstract_class_and_implements_interfaces-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/for/_input.java: -------------------------------------------------------------------------------- 1 | public class For { 2 | 3 | public void simpleFor(String[] array) { 4 | for (int i = 0; i < array.length; i++) { 5 | System.out.println(array[i]); 6 | } 7 | } 8 | 9 | public void emptyFor(String[] array) { 10 | for (;;) { 11 | System.out.println(array[i]); 12 | } 13 | } 14 | 15 | public void forEach(List list) { 16 | for (String str : list) { 17 | System.out.println(str); 18 | } 19 | } 20 | 21 | public void continueSimple() { 22 | for (int i = 0; i < 10; i++) { 23 | if (i % 2 == 0) { 24 | continue; 25 | } 26 | System.out.println(i); 27 | } 28 | } 29 | 30 | public void continueWithIdentifier() { 31 | for (int i = 0; i < 10; i++) { 32 | if (i % 2 == 0) { 33 | continue id; 34 | } 35 | System.out.println(i); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/for/_output.java: -------------------------------------------------------------------------------- 1 | public class For { 2 | 3 | public void simpleFor(String[] array) { 4 | for (int i = 0; i < array.length; i++) { 5 | System.out.println(array[i]); 6 | } 7 | } 8 | 9 | public void emptyFor(String[] array) { 10 | for (;;) { 11 | System.out.println(array[i]); 12 | } 13 | } 14 | 15 | public void forEach(List list) { 16 | for (String str : list) { 17 | System.out.println(str); 18 | } 19 | } 20 | 21 | public void continueSimple() { 22 | for (int i = 0; i < 10; i++) { 23 | if (i % 2 == 0) { 24 | continue; 25 | } 26 | System.out.println(i); 27 | } 28 | } 29 | 30 | public void continueWithIdentifier() { 31 | for (int i = 0; i < 10; i++) { 32 | if (i % 2 == 0) { 33 | continue id; 34 | } 35 | System.out.println(i); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/for/for-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/begin_with_on/_input.java: -------------------------------------------------------------------------------- 1 | // @formatter:on 2 | public class PrettierIgnoreClass { 3 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 4 | 5 | } 6 | } 7 | 8 | // @formatter:off 9 | public class PrettierIgnoreClass { 10 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 11 | 12 | } 13 | } 14 | // @formatter:on 15 | public class PrettierIgnoreClass { 16 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/begin_with_on/_output.java: -------------------------------------------------------------------------------- 1 | // @formatter:on 2 | public class PrettierIgnoreClass { 3 | 4 | public void myMethod( 5 | int param1, 6 | int param2, 7 | int param3, 8 | int param4, 9 | int param5, 10 | int param6, 11 | int param7, 12 | int param8, 13 | int param9, 14 | int param10 15 | ) {} 16 | } 17 | 18 | // @formatter:off 19 | public class PrettierIgnoreClass { 20 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 21 | 22 | } 23 | } 24 | 25 | // @formatter:on 26 | public class PrettierIgnoreClass { 27 | 28 | public void myMethod( 29 | int param1, 30 | int param2, 31 | int param3, 32 | int param4, 33 | int param5, 34 | int param6, 35 | int param7, 36 | int param8, 37 | int param9, 38 | int param10 39 | ) {} 40 | } 41 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/class/_input.java: -------------------------------------------------------------------------------- 1 | // @formatter:off 2 | public class PrettierIgnoreClass { 3 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 4 | 5 | } 6 | } 7 | // @formatter:on 8 | public class PrettierIgnoreClass { 9 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/class/_output.java: -------------------------------------------------------------------------------- 1 | // @formatter:off 2 | public class PrettierIgnoreClass { 3 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 4 | 5 | } 6 | } 7 | 8 | // @formatter:on 9 | public class PrettierIgnoreClass { 10 | 11 | public void myMethod( 12 | int param1, 13 | int param2, 14 | int param3, 15 | int param4, 16 | int param5, 17 | int param6, 18 | int param7, 19 | int param8, 20 | int param9, 21 | int param10 22 | ) {} 23 | } 24 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/end_with_off/_input.java: -------------------------------------------------------------------------------- 1 | // @formatter:off 2 | public class PrettierIgnoreClass { 3 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 4 | 5 | } 6 | } 7 | // @formatter:on 8 | public class PrettierIgnoreClass { 9 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 10 | 11 | } 12 | } 13 | 14 | // @formatter:off 15 | public class PrettierIgnoreClass { 16 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 17 | 18 | } 19 | } 20 | 21 | public class PrettierIgnoreClass { 22 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/end_with_off/_output.java: -------------------------------------------------------------------------------- 1 | // @formatter:off 2 | public class PrettierIgnoreClass { 3 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 4 | 5 | } 6 | } 7 | 8 | // @formatter:on 9 | public class PrettierIgnoreClass { 10 | 11 | public void myMethod( 12 | int param1, 13 | int param2, 14 | int param3, 15 | int param4, 16 | int param5, 17 | int param6, 18 | int param7, 19 | int param8, 20 | int param9, 21 | int param10 22 | ) {} 23 | } 24 | 25 | // @formatter:off 26 | public class PrettierIgnoreClass { 27 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 28 | 29 | } 30 | } 31 | 32 | public class PrettierIgnoreClass { 33 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/inside_block/_input.java: -------------------------------------------------------------------------------- 1 | public class PrettierIgnoreClass { 2 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 3 | // @formatter:off 4 | System.out.println("This operation with two very long string should not break because the formatter is off"); 5 | // @formatter:on 6 | System.out.println("This operation with two very long string should break because the formatter is on"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/inside_block/_output.java: -------------------------------------------------------------------------------- 1 | public class PrettierIgnoreClass { 2 | 3 | public void myMethod( 4 | int param1, 5 | int param2, 6 | int param3, 7 | int param4, 8 | int param5, 9 | int param6, 10 | int param7, 11 | int param8, 12 | int param9, 13 | int param10 14 | ) { 15 | // @formatter:off 16 | System.out.println("This operation with two very long string should not break because the formatter is off"); 17 | // @formatter:on 18 | System.out.println( 19 | "This operation with two very long string should break because the formatter is on" 20 | ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/method/_input.java: -------------------------------------------------------------------------------- 1 | public class PrettierIgnoreClass { 2 | // @formatter:off 3 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 4 | 5 | } 6 | // @formatter:on 7 | } 8 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/method/_output.java: -------------------------------------------------------------------------------- 1 | public class PrettierIgnoreClass { 2 | 3 | // @formatter:off 4 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 5 | 6 | } 7 | // @formatter:on 8 | } 9 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/multiple/_input.java: -------------------------------------------------------------------------------- 1 | // @formatter:off 2 | public class PrettierIgnoreClass { 3 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 4 | 5 | } 6 | } 7 | // @formatter:on 8 | public class PrettierIgnoreClass { 9 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 10 | 11 | } 12 | } 13 | // @formatter:off 14 | public class PrettierIgnoreClass { 15 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 16 | 17 | } 18 | } 19 | // @formatter:on 20 | public class PrettierIgnoreClass { 21 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/formatter-on-off/multiple/_output.java: -------------------------------------------------------------------------------- 1 | // @formatter:off 2 | public class PrettierIgnoreClass { 3 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 4 | 5 | } 6 | } 7 | 8 | // @formatter:on 9 | public class PrettierIgnoreClass { 10 | 11 | public void myMethod( 12 | int param1, 13 | int param2, 14 | int param3, 15 | int param4, 16 | int param5, 17 | int param6, 18 | int param7, 19 | int param8, 20 | int param9, 21 | int param10 22 | ) {} 23 | } 24 | 25 | // @formatter:off 26 | public class PrettierIgnoreClass { 27 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 28 | 29 | } 30 | } 31 | 32 | // @formatter:on 33 | public class PrettierIgnoreClass { 34 | 35 | public void myMethod( 36 | int param1, 37 | int param2, 38 | int param3, 39 | int param4, 40 | int param5, 41 | int param6, 42 | int param7, 43 | int param8, 44 | int param9, 45 | int param10 46 | ) {} 47 | } 48 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/generic_class/_input.java: -------------------------------------------------------------------------------- 1 | public class GenericClass { 2 | private BEAN bean; 3 | 4 | public GenericClass(BEAN bean) { 5 | this.bean = bean; 6 | } 7 | 8 | public BEAN setBean(BEAN bean) { 9 | this.bean = bean; 10 | return bean; 11 | } 12 | 13 | public T doSomething(T t) { 14 | return t; 15 | } 16 | 17 | } 18 | 19 | public class ComplexGenericClass< 20 | BEAN extends AbstractBean & BeanItemSelect, 21 | BEANTYPE, 22 | CONFIG extends BeanConfig< 23 | BEAN, 24 | BEANTYPE, 25 | CONFIG 26 | > 27 | > 28 | extends AbstractBeanConfig< 29 | BEAN, 30 | CONFIG 31 | > { 32 | 33 | public List getBean(final Class beanClass) { 34 | return new ArrayList<>(); 35 | } 36 | 37 | } 38 | 39 | public class Foo { 40 | 41 | public void example(U u) {} 42 | 43 | public void example(U u) {} 44 | } 45 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/generic_class/_output.java: -------------------------------------------------------------------------------- 1 | public class GenericClass { 2 | 3 | private BEAN bean; 4 | 5 | public GenericClass(BEAN bean) { 6 | this.bean = bean; 7 | } 8 | 9 | public BEAN setBean(BEAN bean) { 10 | this.bean = bean; 11 | return bean; 12 | } 13 | 14 | public T doSomething(T t) { 15 | return t; 16 | } 17 | } 18 | 19 | public class ComplexGenericClass< 20 | BEAN extends AbstractBean & BeanItemSelect, 21 | BEANTYPE, 22 | CONFIG extends BeanConfig 23 | > 24 | extends AbstractBeanConfig { 25 | 26 | public List getBean(final Class beanClass) { 27 | return new ArrayList<>(); 28 | } 29 | } 30 | 31 | public class Foo { 32 | 33 | public void example(U u) {} 34 | 35 | public void example(U u) {} 36 | } 37 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/generic_class/generic_class-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/generic_questionmark/_input.java: -------------------------------------------------------------------------------- 1 | public class GenericExtends> {} 2 | 3 | public class Simple { 4 | 5 | public void converter(final Converter converter) {} 6 | 7 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/generic_questionmark/_output.java: -------------------------------------------------------------------------------- 1 | public class GenericExtends> {} 2 | 3 | public class Simple { 4 | 5 | public void converter(final Converter converter) {} 6 | } 7 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/generic_questionmark/generic_questionmark-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/hello-world/_input.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Hello, World"); 5 | } 6 | 7 | } 8 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/hello-world/_output.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Hello, World"); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/hello-world/hello-word-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/if/_input.java: -------------------------------------------------------------------------------- 1 | public class If { 2 | 3 | public void simpleIf(boolean one) { 4 | if (one) { 5 | System.out.println("one"); 6 | } 7 | } 8 | 9 | public void ifElse(boolean one) { 10 | if (one) { 11 | System.out.println("one"); 12 | } else { 13 | System.out.println("not one"); 14 | } 15 | } 16 | 17 | public boolean shortIfElse(boolean one) { 18 | return one ? true : false; 19 | } 20 | 21 | public void ifElseIfElse(boolean one, boolean two) { 22 | if (one) { 23 | System.out.println("one"); 24 | } else if (two) { 25 | System.out.println("two"); 26 | } else { 27 | System.out.println("not on or two"); 28 | } 29 | } 30 | 31 | public void ifElseIfElseIfElse(boolean one, boolean two, boolean three) { 32 | if (one) { 33 | System.out.println("one"); 34 | } else if (two) { 35 | System.out.println("two"); 36 | } else if (three) { 37 | System.out.println("three"); 38 | } else { 39 | System.out.println("not on or two or three"); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/if/_output.java: -------------------------------------------------------------------------------- 1 | public class If { 2 | 3 | public void simpleIf(boolean one) { 4 | if (one) { 5 | System.out.println("one"); 6 | } 7 | } 8 | 9 | public void ifElse(boolean one) { 10 | if (one) { 11 | System.out.println("one"); 12 | } else { 13 | System.out.println("not one"); 14 | } 15 | } 16 | 17 | public boolean shortIfElse(boolean one) { 18 | return one ? true : false; 19 | } 20 | 21 | public void ifElseIfElse(boolean one, boolean two) { 22 | if (one) { 23 | System.out.println("one"); 24 | } else if (two) { 25 | System.out.println("two"); 26 | } else { 27 | System.out.println("not on or two"); 28 | } 29 | } 30 | 31 | public void ifElseIfElseIfElse(boolean one, boolean two, boolean three) { 32 | if (one) { 33 | System.out.println("one"); 34 | } else if (two) { 35 | System.out.println("two"); 36 | } else if (three) { 37 | System.out.println("three"); 38 | } else { 39 | System.out.println("not on or two or three"); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/if/if-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/indent/_input.java: -------------------------------------------------------------------------------- 1 | class Indent { 2 | 3 | void indetMethod() { 4 | assertThat( 5 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 6 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 7 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa 8 | ); 9 | 10 | assertThat( 11 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 12 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 13 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa 14 | ) 15 | .isEqualTo(); 16 | 17 | assertThat( 18 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 19 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 20 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa 21 | ) 22 | .isEqualTo() 23 | .anotherInvocation( 24 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 25 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 26 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa 27 | ); 28 | 29 | myinstanceobject 30 | .assertThat( 31 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa 32 | ) 33 | .isEqualTo(); 34 | 35 | 36 | } 37 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/indent/_output.java: -------------------------------------------------------------------------------- 1 | class Indent { 2 | 3 | void indetMethod() { 4 | assertThat( 5 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 6 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 7 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa 8 | ); 9 | 10 | assertThat( 11 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 12 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 13 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa 14 | ).isEqualTo(); 15 | 16 | assertThat( 17 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 18 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 19 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa 20 | ) 21 | .isEqualTo() 22 | .anotherInvocation( 23 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 24 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa, 25 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa 26 | ); 27 | 28 | myinstanceobject 29 | .assertThat( 30 | useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa 31 | ) 32 | .isEqualTo(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/indent/indent-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/instantiation/_input.java: -------------------------------------------------------------------------------- 1 | public class Instantiation { 2 | 3 | public void instantiation() { 4 | new Constructor("few", "arguments"); 5 | 6 | new Constructor( 7 | "a", "really", "big", "quantity", "of", "arguments", 8 | new Nested("that", "have", "nested", new Nested("instantiation"), "everywhere", "!"), 9 | "should", "wrap" 10 | ); 11 | 12 | new MethodWrappingFollowingContstructor().aLongEnoughMethodNameToForceThingsToWrap(); 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/instantiation/_output.java: -------------------------------------------------------------------------------- 1 | public class Instantiation { 2 | 3 | public void instantiation() { 4 | new Constructor("few", "arguments"); 5 | 6 | new Constructor( 7 | "a", 8 | "really", 9 | "big", 10 | "quantity", 11 | "of", 12 | "arguments", 13 | new Nested( 14 | "that", 15 | "have", 16 | "nested", 17 | new Nested("instantiation"), 18 | "everywhere", 19 | "!" 20 | ), 21 | "should", 22 | "wrap" 23 | ); 24 | 25 | new MethodWrappingFollowingContstructor() 26 | .aLongEnoughMethodNameToForceThingsToWrap(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/instantiation/instantiation-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/interface/_input.java: -------------------------------------------------------------------------------- 1 | public interface Interfaces { 2 | 3 | boolean isAvailable(Object propertyId); 4 | 5 | public static final Method METHOD = SomeStatic.findMethod(); 6 | 7 | } 8 | 9 | public interface Interfaces extends Interface1, Interface2, Interface3, Interface4 { 10 | 11 | boolean isAvailable(Object propertyId); 12 | 13 | public static final Method METHOD = SomeStatic.findMethod(); 14 | 15 | } 16 | 17 | public interface Interfaces extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7, Interface8 { 18 | 19 | boolean isAvailable(Object propertyId); 20 | 21 | public static final Method METHOD = SomeStatic.findMethod(); 22 | 23 | } 24 | 25 | private interface Interface { 26 | String STRING_1 = "STRING_1"; 27 | String STRING_2 = "STRING_2"; 28 | class T {} 29 | CustomClass myFirstInterfaceMethod(String string); 30 | CustomOtherClass mySecondInterfaceMethodWithAVeryLongName(String aVeryLongString); 31 | interface I {} 32 | CustomClass myThirdInterfaceMethod(String string); 33 | @Annotation(annotationAttribute = CONSTANT_STRING) 34 | CustomClass annotatedInterfaceMethod(String string); 35 | @Annotation(annotationAttribute = CONSTANT_STRING) 36 | CustomClass otherAnnotatedInterfaceMethod(String string); 37 | CustomClass myFourthInterfaceMethod(String string); 38 | @Annotation(annotationAttribute = CONSTANT_STRING) 39 | String STRING_3 = "STRING_3"; 40 | String STRING_4 = "STRING_4"; 41 | } 42 | 43 | public interface EmptyInterface { 44 | ; 45 | } 46 | 47 | public interface InterfaceWithSemicolon { 48 | ; 49 | String STRING_1 = "STRING_1"; 50 | } 51 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/interface/_output.java: -------------------------------------------------------------------------------- 1 | public interface Interfaces { 2 | boolean isAvailable(Object propertyId); 3 | 4 | public static final Method METHOD = SomeStatic.findMethod(); 5 | } 6 | 7 | public interface Interfaces 8 | extends Interface1, Interface2, Interface3, Interface4 { 9 | boolean isAvailable(Object propertyId); 10 | 11 | public static final Method METHOD = SomeStatic.findMethod(); 12 | } 13 | 14 | public interface Interfaces 15 | extends 16 | Interface1, 17 | Interface2, 18 | Interface3, 19 | Interface4, 20 | Interface5, 21 | Interface6, 22 | Interface7, 23 | Interface8 { 24 | boolean isAvailable(Object propertyId); 25 | 26 | public static final Method METHOD = SomeStatic.findMethod(); 27 | } 28 | 29 | private interface Interface { 30 | String STRING_1 = "STRING_1"; 31 | String STRING_2 = "STRING_2"; 32 | 33 | class T {} 34 | 35 | CustomClass myFirstInterfaceMethod(String string); 36 | CustomOtherClass mySecondInterfaceMethodWithAVeryLongName( 37 | String aVeryLongString 38 | ); 39 | 40 | interface I {} 41 | 42 | CustomClass myThirdInterfaceMethod(String string); 43 | 44 | @Annotation(annotationAttribute = CONSTANT_STRING) 45 | CustomClass annotatedInterfaceMethod(String string); 46 | 47 | @Annotation(annotationAttribute = CONSTANT_STRING) 48 | CustomClass otherAnnotatedInterfaceMethod(String string); 49 | 50 | CustomClass myFourthInterfaceMethod(String string); 51 | 52 | @Annotation(annotationAttribute = CONSTANT_STRING) 53 | String STRING_3 = "STRING_3"; 54 | 55 | String STRING_4 = "STRING_4"; 56 | } 57 | 58 | public interface EmptyInterface {} 59 | 60 | public interface InterfaceWithSemicolon { 61 | String STRING_1 = "STRING_1"; 62 | } 63 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/interface/interface-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/lambda/lambda-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/marker_annotations/_input.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | @SingleMemberAnnotation2( 4 | name = "Something much long that breaks", 5 | date = "01/01/2018" 6 | ) 7 | @SingleMemberAnnotation1(name = "Thorben von Hacht", date = "01/01/2018") 8 | @NormalAnnotation("value") 9 | @MarkerAnnotation 10 | public class MarkerAnnotations { 11 | 12 | @SingleMemberAnnotation2( 13 | name = "Something much long that breaks", 14 | date = "01/01/2018" 15 | ) 16 | @SingleMemberAnnotation1(name = "Thorben von Hacht", date = "01/01/2018") 17 | @NormalAnnotation("value") 18 | @MarkerAnnotation 19 | SomeService service; 20 | 21 | @SingleMemberAnnotation2( 22 | name = "Something much long that breaks", 23 | date = "01/01/2018" 24 | ) 25 | @SingleMemberAnnotation1(name = "Thorben von Hacht", date = "01/01/2018") 26 | @NormalAnnotation("value") 27 | @MarkerAnnotation 28 | public void postConstruct() { 29 | System.out.println("post construct"); 30 | } 31 | 32 | @SuppressWarnings({ "rawtypes", "unchecked" }) 33 | @SuppressWarnings2({ "rawtypes", "unchecked", "something", "something2", "something3", "something4" }) 34 | public void elementValueArrayInitializer(){ 35 | System.out.println("element value array initializer"); 36 | } 37 | 38 | @ArrayInitializersWithKey(key = { "abc", "def" }, key2 = { "ghi", "jkl" }, key3 = { "mno", "pqr" }) 39 | public void arrayInitializerWithKey(){ 40 | System.out.println("element value array initializer with key"); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/marker_annotations/_output.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | @SingleMemberAnnotation2( 4 | name = "Something much long that breaks", 5 | date = "01/01/2018" 6 | ) 7 | @SingleMemberAnnotation1(name = "Thorben von Hacht", date = "01/01/2018") 8 | @NormalAnnotation("value") 9 | @MarkerAnnotation 10 | public class MarkerAnnotations { 11 | 12 | @SingleMemberAnnotation2( 13 | name = "Something much long that breaks", 14 | date = "01/01/2018" 15 | ) 16 | @SingleMemberAnnotation1(name = "Thorben von Hacht", date = "01/01/2018") 17 | @NormalAnnotation("value") 18 | @MarkerAnnotation 19 | SomeService service; 20 | 21 | @SingleMemberAnnotation2( 22 | name = "Something much long that breaks", 23 | date = "01/01/2018" 24 | ) 25 | @SingleMemberAnnotation1(name = "Thorben von Hacht", date = "01/01/2018") 26 | @NormalAnnotation("value") 27 | @MarkerAnnotation 28 | public void postConstruct() { 29 | System.out.println("post construct"); 30 | } 31 | 32 | @SuppressWarnings({ "rawtypes", "unchecked" }) 33 | @SuppressWarnings2( 34 | { 35 | "rawtypes", 36 | "unchecked", 37 | "something", 38 | "something2", 39 | "something3", 40 | "something4", 41 | } 42 | ) 43 | public void elementValueArrayInitializer() { 44 | System.out.println("element value array initializer"); 45 | } 46 | 47 | @ArrayInitializersWithKey( 48 | key = { "abc", "def" }, 49 | key2 = { "ghi", "jkl" }, 50 | key3 = { "mno", "pqr" } 51 | ) 52 | public void arrayInitializerWithKey() { 53 | System.out.println("element value array initializer with key"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/marker_annotations/marker_annotations-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/member_chain/member_chain-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/method_reference/_input.java: -------------------------------------------------------------------------------- 1 | public class MethodReference { 2 | 3 | public void referenceToAStaticMethod() { 4 | call(ContainingClass::staticMethodName); 5 | } 6 | 7 | public referenceToAConstructor() { 8 | call(ClassName::new); 9 | } 10 | 11 | public referenceToAnInstanceMethodOfAnArbitraryObjectOfAParticularType() { 12 | call(ContainingType::methodName); 13 | } 14 | 15 | public referenceToAnInstanceMethodOfAParticularObject() { 16 | call(containingObject::instanceMethodName); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/method_reference/_output.java: -------------------------------------------------------------------------------- 1 | public class MethodReference { 2 | 3 | public void referenceToAStaticMethod() { 4 | call(ContainingClass::staticMethodName); 5 | } 6 | 7 | public referenceToAConstructor() { 8 | call(ClassName::new); 9 | } 10 | 11 | public referenceToAnInstanceMethodOfAnArbitraryObjectOfAParticularType() { 12 | call(ContainingType::methodName); 13 | } 14 | 15 | public referenceToAnInstanceMethodOfAParticularObject() { 16 | call(containingObject::instanceMethodName); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/method_reference/method_reference-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: method reference", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/modifiers/_input.java: -------------------------------------------------------------------------------- 1 | @AnnotationOne 2 | 3 | @AnnotationTwo static public @AnnotationThree interface InterfaceWithModifiers { 4 | static final @AnnotationOne public String INTERFACE_CONSTANT = "abc"; 5 | 6 | @AnnotationOne 7 | @AnnotationTwo default public @AnnotationThree String defaultMethod() { 8 | return INTERFACE_CONSTANT; 9 | } 10 | 11 | static @AnnotationOne public @AnnotationTwo String staticMethod() { 12 | return INTERFACE_CONSTANT; 13 | } 14 | 15 | public @AnnotationOne @AnnotationTwo void twoTrailingAnnotations(); 16 | 17 | @AnnotationOne void onlyAnnotations(); 18 | } 19 | 20 | @AnnotationOne abstract public @AnnotationTwo class AbstractClassWithModifiers { 21 | volatile private @Annotation static String field; 22 | 23 | @AnnotationOne 24 | @AnnotationTwo abstract synchronized protected @AnnotationThree String method(); 25 | 26 | public @AnnotationOne @AnnotationTwo void twoTrailingAnnotations() {} 27 | 28 | @AnnotationOne void onlyAnnotations() {} 29 | } 30 | 31 | final @AnnotationOne static public @AnnotationTwo class ClassWithModifiers { 32 | transient @AnnotationOne final private @AnnotationTwo static String CONSTANT = "abc"; 33 | 34 | final @AnnotationOne static @AnnotationTwo protected @AnnotationThree String CONSTANT_2 = "123"; 35 | 36 | static @AnnotationOne public @AnnotationTwo String staticField; 37 | 38 | public @AnnotationOne @AnnotationTwo String twoTrailingAnnotations; 39 | 40 | @AnnotationOne String onlyAnnotations; 41 | 42 | final @AnnotationOne static @AnnotationTwo synchronized protected @AnnotationThree String method() { 43 | return CONSTANT; 44 | } 45 | 46 | public @AnnotationOne @AnnotationTwo void twoTrailingAnnotations() {} 47 | 48 | @AnnotationOne void onlyAnnotations() {} 49 | } 50 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/modifiers/_output.java: -------------------------------------------------------------------------------- 1 | @AnnotationOne 2 | @AnnotationTwo 3 | @AnnotationThree 4 | public static interface InterfaceWithModifiers { 5 | @AnnotationOne 6 | public static final String INTERFACE_CONSTANT = "abc"; 7 | 8 | @AnnotationOne 9 | @AnnotationTwo 10 | public default @AnnotationThree String defaultMethod() { 11 | return INTERFACE_CONSTANT; 12 | } 13 | 14 | @AnnotationOne 15 | public static @AnnotationTwo String staticMethod() { 16 | return INTERFACE_CONSTANT; 17 | } 18 | 19 | public @AnnotationOne @AnnotationTwo void twoTrailingAnnotations(); 20 | 21 | @AnnotationOne 22 | void onlyAnnotations(); 23 | } 24 | 25 | @AnnotationOne 26 | @AnnotationTwo 27 | public abstract class AbstractClassWithModifiers { 28 | 29 | @Annotation 30 | private static volatile String field; 31 | 32 | @AnnotationOne 33 | @AnnotationTwo 34 | protected abstract synchronized @AnnotationThree String method(); 35 | 36 | public @AnnotationOne @AnnotationTwo void twoTrailingAnnotations() {} 37 | 38 | @AnnotationOne 39 | void onlyAnnotations() {} 40 | } 41 | 42 | @AnnotationOne 43 | @AnnotationTwo 44 | public static final class ClassWithModifiers { 45 | 46 | @AnnotationOne 47 | @AnnotationTwo 48 | private static final transient String CONSTANT = "abc"; 49 | 50 | @AnnotationOne 51 | @AnnotationTwo 52 | protected static final @AnnotationThree String CONSTANT_2 = "123"; 53 | 54 | @AnnotationOne 55 | public static @AnnotationTwo String staticField; 56 | 57 | public @AnnotationOne @AnnotationTwo String twoTrailingAnnotations; 58 | 59 | @AnnotationOne 60 | String onlyAnnotations; 61 | 62 | @AnnotationOne 63 | @AnnotationTwo 64 | protected static final synchronized @AnnotationThree String method() { 65 | return CONSTANT; 66 | } 67 | 68 | public @AnnotationOne @AnnotationTwo void twoTrailingAnnotations() {} 69 | 70 | @AnnotationOne 71 | void onlyAnnotations() {} 72 | } 73 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/modifiers/modifiers-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: modifiers", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/modules/_input.java: -------------------------------------------------------------------------------- 1 | open module soat.vending.machine.gui { 2 | requires java.desktopa ; 3 | requires soat.vending.machine.model; 4 | requires transitive soat.core; 5 | exports fr.soat.vending.machine.model to another , again, ano; 6 | exports fr.soat.vending.machine.model.without.destination ; 7 | 8 | exports fr.soat.vending.machine.model.it.should.be.breaking.but.only.a.part to another , again, ano; 9 | 10 | exports fr.soat.vending.machine.model to another , again, ano, waht, another , again, ano, averyveryveryveryveryveryveryveryveryveryverylongname; 11 | 12 | opens fr.soat.vending.machine.model.without.destination ; 13 | 14 | opens fr.soat.vending.machine.model to another , again,ano ; 15 | 16 | opens fr.soat.vending.machine.model.it.should.be.breaking.but.only.a.part to another , again,ano ; 17 | 18 | opens fr.soat.vending.machine.model to another , again,ano,another , again,ano,another , again,ano,another , again,averyveryveryveryveryveryveryveryveryveryverylongname ; 19 | 20 | 21 | 22 | uses fr.soat.vendinga.machine.services.DrinksService ; 23 | 24 | provides model with another , again,ano ; 25 | 26 | provides fr.soat.vending.machine.model.it.should.be.breaking.but.only.a.part with another , again,ano ; 27 | 28 | provides model with another , again,ano,another , again,ano,another , again,ano,another , again,averyveryveryveryveryveryveryveryveryveryverylongname ; 29 | 30 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/modules/_output.java: -------------------------------------------------------------------------------- 1 | open module soat.vending.machine.gui { 2 | requires java.desktopa; 3 | requires soat.vending.machine.model; 4 | requires transitive soat.core; 5 | exports fr.soat.vending.machine.model to another, again, ano; 6 | exports fr.soat.vending.machine.model.without.destination; 7 | 8 | exports fr.soat.vending.machine.model.it.should.be.breaking.but.only.a.part 9 | to another, again, ano; 10 | 11 | exports fr.soat.vending.machine.model 12 | to 13 | another, 14 | again, 15 | ano, 16 | waht, 17 | another, 18 | again, 19 | ano, 20 | averyveryveryveryveryveryveryveryveryveryverylongname; 21 | 22 | opens fr.soat.vending.machine.model.without.destination; 23 | 24 | opens fr.soat.vending.machine.model to another, again, ano; 25 | 26 | opens fr.soat.vending.machine.model.it.should.be.breaking.but.only.a.part 27 | to another, again, ano; 28 | 29 | opens fr.soat.vending.machine.model 30 | to 31 | another, 32 | again, 33 | ano, 34 | another, 35 | again, 36 | ano, 37 | another, 38 | again, 39 | ano, 40 | another, 41 | again, 42 | averyveryveryveryveryveryveryveryveryveryverylongname; 43 | 44 | uses fr.soat.vendinga.machine.services.DrinksService; 45 | 46 | provides model with another, again, ano; 47 | 48 | provides fr.soat.vending.machine.model.it.should.be.breaking.but.only.a.part 49 | with another, again, ano; 50 | 51 | provides model 52 | with 53 | another, 54 | again, 55 | ano, 56 | another, 57 | again, 58 | ano, 59 | another, 60 | again, 61 | ano, 62 | another, 63 | again, 64 | averyveryveryveryveryveryveryveryveryveryverylongname; 65 | } 66 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/modules/modules-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: modules", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/classWithMixedCaseImports/_input.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.function.Consumer; 3 | import java.util.functioN.Consumer; 4 | import java.util.function.ConsumerTwo; 5 | import java.util.List; 6 | import java.util.concurrent.Semaphore; 7 | import java.util.concurrent.*; 8 | import java.util.Map; 9 | 10 | public class PackageAndImports {} 11 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/classWithMixedCaseImports/_output.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | import java.util.Map; 4 | import java.util.concurrent.*; 5 | import java.util.concurrent.Semaphore; 6 | import java.util.functioN.Consumer; 7 | import java.util.function.Consumer; 8 | import java.util.function.ConsumerTwo; 9 | 10 | public class PackageAndImports {} 11 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/classWithMixedImports/_input.java: -------------------------------------------------------------------------------- 1 | package my.own.pkg; 2 | 3 | import something.Different; 4 | import java.utils.*;;; 5 | import abc.def.Something; 6 | import abc.def.Another;;; 7 | import abc.def; 8 | import static abc.def; 9 | import static something.Different; 10 | import static java.utils.*;;; 11 | import static abc.def.Something; 12 | import static abc.def.Another;;; 13 | import one.last;;; 14 | 15 | public class PackageAndImports {} 16 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/classWithMixedImports/_output.java: -------------------------------------------------------------------------------- 1 | package my.own.pkg; 2 | 3 | import static abc.def; 4 | import static abc.def.Another; 5 | import static abc.def.Something; 6 | import static java.utils.*; 7 | import static something.Different; 8 | 9 | import abc.def; 10 | import abc.def.Another; 11 | import abc.def.Something; 12 | import java.utils.*; 13 | import one.last; 14 | import something.Different; 15 | 16 | public class PackageAndImports {} 17 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/classWithNoImports/_input.java: -------------------------------------------------------------------------------- 1 | package my.own.pkg; 2 | 3 | public class PackageAndImports {} 4 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/classWithNoImports/_output.java: -------------------------------------------------------------------------------- 1 | package my.own.pkg; 2 | 3 | public class PackageAndImports {} 4 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/classWithOnlyNonStaticImports/_input.java: -------------------------------------------------------------------------------- 1 | package my.own.pkg; 2 | 3 | import something.Different; 4 | import java.utils.*;;; 5 | import abc.def.Something; 6 | import abc.def.Another;;; 7 | import abc.def; 8 | import one.last;;; 9 | 10 | public class PackageAndImports {} 11 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/classWithOnlyNonStaticImports/_output.java: -------------------------------------------------------------------------------- 1 | package my.own.pkg; 2 | 3 | import abc.def; 4 | import abc.def.Another; 5 | import abc.def.Something; 6 | import java.utils.*; 7 | import one.last; 8 | import something.Different; 9 | 10 | public class PackageAndImports {} 11 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/classWithOnlyStaticImports/_input.java: -------------------------------------------------------------------------------- 1 | package my.own.pkg; 2 | 3 | import static abc.def; 4 | import static something.Different; 5 | import static java.utils.*;;; 6 | import static abc.def.Something; 7 | import static abc.def.Another;;; 8 | 9 | public class PackageAndImports {} 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/classWithOnlyStaticImports/_output.java: -------------------------------------------------------------------------------- 1 | package my.own.pkg; 2 | 3 | import static abc.def; 4 | import static abc.def.Another; 5 | import static abc.def.Something; 6 | import static java.utils.*; 7 | import static something.Different; 8 | 9 | public class PackageAndImports {} 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/moduleWithMixedImports/_input.java: -------------------------------------------------------------------------------- 1 | import something.Different; 2 | import java.utils.*;;; 3 | import abc.def.Something; 4 | import abc.def.Another;;; 5 | import abc.def; 6 | import static abc.def; 7 | import static something.Different; 8 | import static java.utils.*;;; 9 | import static abc.def.Something; 10 | import static abc.def.Another;;; 11 | import one.last;;; 12 | 13 | module my.module {} 14 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/moduleWithMixedImports/_output.java: -------------------------------------------------------------------------------- 1 | import static abc.def; 2 | import static abc.def.Another; 3 | import static abc.def.Something; 4 | import static java.utils.*; 5 | import static something.Different; 6 | 7 | import abc.def; 8 | import abc.def.Another; 9 | import abc.def.Something; 10 | import java.utils.*; 11 | import one.last; 12 | import something.Different; 13 | 14 | module my.module {} 15 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/moduleWithNoImports/_input.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | module my.module {} 4 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/moduleWithNoImports/_output.java: -------------------------------------------------------------------------------- 1 | module my.module {} 2 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/moduleWithOnlyNonStaticImports/_input.java: -------------------------------------------------------------------------------- 1 | import something.Different; 2 | import java.utils.*;;; 3 | import abc.def.Something; 4 | import abc.def.Another;;; 5 | import abc.def; 6 | import one.last;;; 7 | 8 | module my.module {} 9 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/moduleWithOnlyNonStaticImports/_output.java: -------------------------------------------------------------------------------- 1 | import abc.def; 2 | import abc.def.Another; 3 | import abc.def.Something; 4 | import java.utils.*; 5 | import one.last; 6 | import something.Different; 7 | 8 | module my.module {} 9 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/moduleWithOnlyStaticImports/_input.java: -------------------------------------------------------------------------------- 1 | 2 | import static abc.def; 3 | import static something.Different; 4 | import static java.utils.*;;; 5 | import static abc.def.Something; 6 | import static abc.def.Another;;; 7 | 8 | module my.module {} 9 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/moduleWithOnlyStaticImports/_output.java: -------------------------------------------------------------------------------- 1 | import static abc.def; 2 | import static abc.def.Another; 3 | import static abc.def.Something; 4 | import static java.utils.*; 5 | import static something.Different; 6 | 7 | module my.module {} 8 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/package_and_imports/package_and_imports-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java", () => { 8 | testSample(path.resolve(__dirname, "./classWithMixedCaseImports")); 9 | testSample(path.resolve(__dirname, "./classWithMixedImports")); 10 | testSample(path.resolve(__dirname, "./classWithNoImports")); 11 | testSample(path.resolve(__dirname, "./classWithOnlyStaticImports")); 12 | testSample(path.resolve(__dirname, "./classWithOnlyNonStaticImports")); 13 | testSample(path.resolve(__dirname, "./moduleWithMixedImports")); 14 | testSample(path.resolve(__dirname, "./moduleWithNoImports")); 15 | testSample(path.resolve(__dirname, "./moduleWithOnlyStaticImports")); 16 | testSample(path.resolve(__dirname, "./moduleWithOnlyNonStaticImports")); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/pattern-matching/pattern-matching-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: pattern matching", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/prettier-ignore/block/_input.java: -------------------------------------------------------------------------------- 1 | package tech.jhipster; 2 | 3 | import java.util.Map; 4 | 5 | public class StrangePrettierIgnore { 6 | 7 | private StrangePrettierIgnore() {} 8 | 9 | public static void drinkBeers() { 10 | // prettier-ignore 11 | Map beers = Map.of( 12 | "beer1", "Gulden Draak", 13 | "beer2", "Piraat", 14 | "beer3", "Kapittel" 15 | ); 16 | 17 | System.out.println(beers); // not well formated here 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/prettier-ignore/block/_output.java: -------------------------------------------------------------------------------- 1 | package tech.jhipster; 2 | 3 | import java.util.Map; 4 | 5 | public class StrangePrettierIgnore { 6 | 7 | private StrangePrettierIgnore() {} 8 | 9 | public static void drinkBeers() { 10 | // prettier-ignore 11 | Map beers = Map.of( 12 | "beer1", "Gulden Draak", 13 | "beer2", "Piraat", 14 | "beer3", "Kapittel" 15 | ); 16 | 17 | System.out.println(beers); // not well formated here 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/prettier-ignore/classDeclaration/_input.java: -------------------------------------------------------------------------------- 1 | // prettier-ignore 2 | public class PrettierIgnoreClass { 3 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 4 | 5 | } 6 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/prettier-ignore/classDeclaration/_output.java: -------------------------------------------------------------------------------- 1 | // prettier-ignore 2 | public class PrettierIgnoreClass { 3 | public void myMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 4 | 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/prettier-ignore/method/_input.java: -------------------------------------------------------------------------------- 1 | public class PrettierIgnoreClass { 2 | int myInteger; 3 | 4 | public void myPrettierIgnoreMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 5 | 6 | 7 | 8 | 9 | 10 | 11 | } 12 | 13 | // prettier-ignore 14 | public void myPrettierIgnoreMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 15 | 16 | 17 | 18 | 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/prettier-ignore/method/_output.java: -------------------------------------------------------------------------------- 1 | public class PrettierIgnoreClass { 2 | 3 | int myInteger; 4 | 5 | public void myPrettierIgnoreMethod( 6 | int param1, 7 | int param2, 8 | int param3, 9 | int param4, 10 | int param5, 11 | int param6, 12 | int param7, 13 | int param8, 14 | int param9, 15 | int param10 16 | ) {} 17 | 18 | // prettier-ignore 19 | public void myPrettierIgnoreMethod(int param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 20 | 21 | 22 | 23 | 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/prettier-ignore/multiple-ignore/_input.java: -------------------------------------------------------------------------------- 1 | public class PrettierIgnoreClass { 2 | int myInteger; 3 | 4 | public void myPrettierIgnoreMethod(int param1, MyClass param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 5 | for (int i = 0; i < param1; i++) { 6 | param2.methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall(); 7 | } 8 | } 9 | 10 | // prettier-ignore 11 | public void myPrettierIgnoreMethod(int param1, MyClass param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 12 | for (int i = 0; i < param1; i++) { 13 | param2.methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall(); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/prettier-ignore/multiple-ignore/_output.java: -------------------------------------------------------------------------------- 1 | public class PrettierIgnoreClass { 2 | 3 | int myInteger; 4 | 5 | public void myPrettierIgnoreMethod( 6 | int param1, 7 | MyClass param2, 8 | int param3, 9 | int param4, 10 | int param5, 11 | int param6, 12 | int param7, 13 | int param8, 14 | int param9, 15 | int param10 16 | ) { 17 | for (int i = 0; i < param1; i++) { 18 | param2 19 | .methodcall() 20 | .methodcall() 21 | .methodcall() 22 | .methodcall() 23 | .methodcall() 24 | .methodcall() 25 | .methodcall() 26 | .methodcall() 27 | .methodcall() 28 | .methodcall() 29 | .methodcall(); 30 | } 31 | } 32 | 33 | // prettier-ignore 34 | public void myPrettierIgnoreMethod(int param1, MyClass param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, int param10) { 35 | for (int i = 0; i < param1; i++) { 36 | param2.methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall().methodcall(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/prettier-ignore/prettier-ignore-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: try catch", () => { 8 | testSample(path.resolve(__dirname, "./block")); 9 | testSample(path.resolve(__dirname, "./classDeclaration")); 10 | testSample(path.resolve(__dirname, "./method")); 11 | testSample(path.resolve(__dirname, "./multiple-ignore")); 12 | }); 13 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/records/records-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: records", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/require-pragma/format-pragma/_input.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | public enum Enum { 5 | 6 | SOME_ENUM, ANOTHER_ENUM, LAST_ENUM; 7 | 8 | } 9 | 10 | public enum Enum { 11 | 12 | THIS_IS_GOOD("abc"), THIS_IS_FINE("abc"); 13 | 14 | public static final String thisWillBeDeleted = "DELETED"; 15 | 16 | private final String value; 17 | 18 | public Enum(String value) { 19 | this.value = value; 20 | } 21 | 22 | public String toString() { 23 | return "STRING"; 24 | } 25 | 26 | } 27 | 28 | class CLassWithEnum { 29 | 30 | public static enum VALID_THINGS { 31 | 32 | FIRST, SECOND 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/require-pragma/format-pragma/_output.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | public enum Enum { 5 | SOME_ENUM, 6 | ANOTHER_ENUM, 7 | LAST_ENUM, 8 | } 9 | 10 | public enum Enum { 11 | THIS_IS_GOOD("abc"), 12 | THIS_IS_FINE("abc"); 13 | 14 | public static final String thisWillBeDeleted = "DELETED"; 15 | 16 | private final String value; 17 | 18 | public Enum(String value) { 19 | this.value = value; 20 | } 21 | 22 | public String toString() { 23 | return "STRING"; 24 | } 25 | } 26 | 27 | class CLassWithEnum { 28 | 29 | public static enum VALID_THINGS { 30 | FIRST, 31 | SECOND, 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/require-pragma/invalid-pragma/_input.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @surely this is invalid 3 | */ 4 | public enum Enum { 5 | 6 | SOME_ENUM, ANOTHER_ENUM, LAST_ENUM; 7 | 8 | } 9 | 10 | public enum Enum { 11 | 12 | THIS_IS_GOOD("abc"), THIS_IS_FINE("abc"); 13 | 14 | public static final String thisWillBeDeleted = "DELETED"; 15 | 16 | private final String value; 17 | 18 | public Enum(String value) { 19 | this.value = value; 20 | } 21 | 22 | public String toString() { 23 | return "STRING"; 24 | } 25 | 26 | } 27 | 28 | class CLassWithEnum { 29 | 30 | public static enum VALID_THINGS { 31 | 32 | FIRST, SECOND 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/require-pragma/invalid-pragma/_output.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @surely this is invalid 3 | */ 4 | public enum Enum { 5 | 6 | SOME_ENUM, ANOTHER_ENUM, LAST_ENUM; 7 | 8 | } 9 | 10 | public enum Enum { 11 | 12 | THIS_IS_GOOD("abc"), THIS_IS_FINE("abc"); 13 | 14 | public static final String thisWillBeDeleted = "DELETED"; 15 | 16 | private final String value; 17 | 18 | public Enum(String value) { 19 | this.value = value; 20 | } 21 | 22 | public String toString() { 23 | return "STRING"; 24 | } 25 | 26 | } 27 | 28 | class CLassWithEnum { 29 | 30 | public static enum VALID_THINGS { 31 | 32 | FIRST, SECOND 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/require-pragma/prettier-pragma/_input.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @prettier 3 | */ 4 | public enum Enum { 5 | 6 | SOME_ENUM, ANOTHER_ENUM, LAST_ENUM; 7 | 8 | } 9 | 10 | public enum Enum { 11 | 12 | THIS_IS_GOOD("abc"), THIS_IS_FINE("abc"); 13 | 14 | public static final String thisWillBeDeleted = "DELETED"; 15 | 16 | private final String value; 17 | 18 | public Enum(String value) { 19 | this.value = value; 20 | } 21 | 22 | public String toString() { 23 | return "STRING"; 24 | } 25 | 26 | } 27 | 28 | class CLassWithEnum { 29 | 30 | public static enum VALID_THINGS { 31 | 32 | FIRST, SECOND 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/require-pragma/prettier-pragma/_output.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @prettier 3 | */ 4 | public enum Enum { 5 | SOME_ENUM, 6 | ANOTHER_ENUM, 7 | LAST_ENUM, 8 | } 9 | 10 | public enum Enum { 11 | THIS_IS_GOOD("abc"), 12 | THIS_IS_FINE("abc"); 13 | 14 | public static final String thisWillBeDeleted = "DELETED"; 15 | 16 | private final String value; 17 | 18 | public Enum(String value) { 19 | this.value = value; 20 | } 21 | 22 | public String toString() { 23 | return "STRING"; 24 | } 25 | } 26 | 27 | class CLassWithEnum { 28 | 29 | public static enum VALID_THINGS { 30 | FIRST, 31 | SECOND, 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/require-pragma/require-pragma-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSampleWithOptions } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: require-pragma option", () => { 8 | [ 9 | path.resolve(__dirname, "./format-pragma"), 10 | path.resolve(__dirname, "./prettier-pragma"), 11 | path.resolve(__dirname, "./invalid-pragma") 12 | ].forEach(testFolder => 13 | testSampleWithOptions({ 14 | testFolder, 15 | prettierOptions: { requirePragma: true } 16 | }) 17 | ); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/return/_input.java: -------------------------------------------------------------------------------- 1 | public abstract class Return { 2 | 3 | Object returnThis() { 4 | return this; 5 | } 6 | 7 | Object returnNull() { 8 | return null; 9 | } 10 | 11 | void exit() { 12 | return; 13 | } 14 | 15 | Object returnCast() { 16 | return (BeanItemContainer) super.getContainerDataSource(); 17 | } 18 | 19 | Object returnSomethingWhichDoNotBreak() { 20 | return oneVariable + secondVariable; 21 | } 22 | 23 | Object returnSomethingWhichBreak() { 24 | return oneVariable + secondVariable + thirdVariable + fourthVariable + fifthVariable + sixthVariable + seventhVariable; 25 | } 26 | 27 | Object returnSomethingWhichBreakAndAlreadyInParenthesis() { 28 | return ( 29 | oneVariable + 30 | secondVariable + 31 | thirdVariable + 32 | fourthVariable + 33 | fifthVariable + 34 | sixthVariable + 35 | seventhVariable 36 | ); 37 | } 38 | 39 | // Bug fix #290 40 | public boolean shouldBreakInOneLine(Example that) { 41 | return oneVeryLongPrimaryExpression && andYetAnotherVeryVeryLongPrimaryExpression; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/return/_output.java: -------------------------------------------------------------------------------- 1 | public abstract class Return { 2 | 3 | Object returnThis() { 4 | return this; 5 | } 6 | 7 | Object returnNull() { 8 | return null; 9 | } 10 | 11 | void exit() { 12 | return; 13 | } 14 | 15 | Object returnCast() { 16 | return (BeanItemContainer) super.getContainerDataSource(); 17 | } 18 | 19 | Object returnSomethingWhichDoNotBreak() { 20 | return oneVariable + secondVariable; 21 | } 22 | 23 | Object returnSomethingWhichBreak() { 24 | return ( 25 | oneVariable + 26 | secondVariable + 27 | thirdVariable + 28 | fourthVariable + 29 | fifthVariable + 30 | sixthVariable + 31 | seventhVariable 32 | ); 33 | } 34 | 35 | Object returnSomethingWhichBreakAndAlreadyInParenthesis() { 36 | return ( 37 | oneVariable + 38 | secondVariable + 39 | thirdVariable + 40 | fourthVariable + 41 | fifthVariable + 42 | sixthVariable + 43 | seventhVariable 44 | ); 45 | } 46 | 47 | // Bug fix #290 48 | public boolean shouldBreakInOneLine(Example that) { 49 | return ( 50 | oneVeryLongPrimaryExpression && andYetAnotherVeryVeryLongPrimaryExpression 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/return/return-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: return", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/sealed/sealed-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: sealed classes", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/snippets/arrays/variable-initializer-list.spec.ts: -------------------------------------------------------------------------------- 1 | import { expectSnippetToBeFormatted } from "../../../test-utils.js"; 2 | 3 | describe("VariableInitializerList", () => { 4 | it("format variableInitializerList with one variableInitializer", () => { 5 | expectSnippetToBeFormatted({ 6 | snippet: "alpha ", 7 | expectedOutput: "alpha", 8 | entryPoint: "variableInitializerList" 9 | }); 10 | }); 11 | 12 | it("format variableInitializerList with multiple variableInitializer", () => { 13 | expectSnippetToBeFormatted({ 14 | snippet: "alpha,beta, gamma", 15 | expectedOutput: "alpha,\nbeta,\ngamma", 16 | entryPoint: "variableInitializerList" 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/snippets/blocks-and-statements/switch.spec.ts: -------------------------------------------------------------------------------- 1 | import { expectSnippetToBeFormatted } from "../../../test-utils.js"; 2 | 3 | describe("Switches", () => { 4 | describe("Switch Statement", () => { 5 | it("should format switch statement", () => { 6 | const snippet = 7 | "switch (answer) {\n" + 8 | " case YES:\n" + 9 | ' return "Yes";\n' + 10 | " default:\n" + 11 | ' return "NO";\n' + 12 | "}"; 13 | 14 | const expectedOutput = 15 | "switch (answer) {\n" + 16 | " case YES:\n" + 17 | ' return "Yes";\n' + 18 | " default:\n" + 19 | ' return "NO";\n' + 20 | "}"; 21 | 22 | expectSnippetToBeFormatted({ 23 | snippet, 24 | expectedOutput, 25 | entryPoint: "switchStatement" 26 | }); 27 | }); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/snippets/names/ambiguousName/test.spec.ts: -------------------------------------------------------------------------------- 1 | import { expectSnippetToBeFormatted } from "../../../../test-utils.js"; 2 | 3 | describe("AmbiguousName", () => { 4 | it("can format a AmbiguousName without dots", () => { 5 | expectSnippetToBeFormatted({ 6 | snippet: "myAmbiguousName", 7 | expectedOutput: "myAmbiguousName", 8 | entryPoint: "ambiguousName" 9 | }); 10 | }); 11 | 12 | it("can format a AmbiguousName with dots", () => { 13 | expectSnippetToBeFormatted({ 14 | snippet: "myAmbiguousName.with.lot.of.dots", 15 | expectedOutput: "myAmbiguousName.with.lot.of.dots", 16 | entryPoint: "ambiguousName" 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/snippets/names/expressionName/test.spec.ts: -------------------------------------------------------------------------------- 1 | import { expectSnippetToBeFormatted } from "../../../../test-utils.js"; 2 | 3 | describe("expressionName", () => { 4 | it("can format a ExpressionName without dots", () => { 5 | expectSnippetToBeFormatted({ 6 | snippet: "myExpression", 7 | expectedOutput: "myExpression", 8 | entryPoint: "expressionName" 9 | }); 10 | }); 11 | 12 | it("can format a ExpressionName with dots", () => { 13 | expectSnippetToBeFormatted({ 14 | snippet: "myExpression.with.lot.of.dots", 15 | expectedOutput: "myExpression.with.lot.of.dots", 16 | entryPoint: "expressionName" 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/snippets/names/methodName/test.spec.ts: -------------------------------------------------------------------------------- 1 | import { expectSnippetToBeFormatted } from "../../../../test-utils.js"; 2 | 3 | describe("MethodName", () => { 4 | it("can format a MethodName", () => { 5 | expectSnippetToBeFormatted({ 6 | snippet: "test", 7 | expectedOutput: "test", 8 | entryPoint: "methodName" 9 | }); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/snippets/names/packageOrTypeName/test.spec.ts: -------------------------------------------------------------------------------- 1 | import { expectSnippetToBeFormatted } from "../../../../test-utils.js"; 2 | 3 | describe("PackageOrTypeName", () => { 4 | it("can format a PackageOrTypeName without dots", () => { 5 | expectSnippetToBeFormatted({ 6 | snippet: "com", 7 | expectedOutput: "com", 8 | entryPoint: "packageOrTypeName" 9 | }); 10 | }); 11 | 12 | it("can format a PackageOrTypeName with dots", () => { 13 | expectSnippetToBeFormatted({ 14 | snippet: "com.iluwatar.abstractdocument", 15 | expectedOutput: "com.iluwatar.abstractdocument", 16 | entryPoint: "packageOrTypeName" 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/snippets/types-values-and-variables/floatingPointType/test.spec.ts: -------------------------------------------------------------------------------- 1 | import { expectSnippetToBeFormatted } from "../../../../test-utils.js"; 2 | 3 | describe("floatingPointType", () => { 4 | it("can format float keyword", () => { 5 | expectSnippetToBeFormatted({ 6 | snippet: "float", 7 | expectedOutput: "float", 8 | entryPoint: "floatingPointType" 9 | }); 10 | }); 11 | 12 | it("can format double keyword", () => { 13 | expectSnippetToBeFormatted({ 14 | snippet: "double", 15 | expectedOutput: "double", 16 | entryPoint: "floatingPointType" 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/snippets/types-values-and-variables/integralType/test.spec.ts: -------------------------------------------------------------------------------- 1 | import { expectSnippetToBeFormatted } from "../../../../test-utils.js"; 2 | 3 | describe("integralType", () => { 4 | it("can format byte keyword", () => { 5 | expectSnippetToBeFormatted({ 6 | snippet: "byte", 7 | expectedOutput: "byte", 8 | entryPoint: "integralType" 9 | }); 10 | }); 11 | 12 | it("can format short keyword", () => { 13 | expectSnippetToBeFormatted({ 14 | snippet: "short", 15 | expectedOutput: "short", 16 | entryPoint: "integralType" 17 | }); 18 | }); 19 | 20 | it("can format int keyword", () => { 21 | expectSnippetToBeFormatted({ 22 | snippet: "int", 23 | expectedOutput: "int", 24 | entryPoint: "integralType" 25 | }); 26 | }); 27 | 28 | it("can format long keyword", () => { 29 | expectSnippetToBeFormatted({ 30 | snippet: "long", 31 | expectedOutput: "long", 32 | entryPoint: "integralType" 33 | }); 34 | }); 35 | 36 | it("can format char keyword", () => { 37 | expectSnippetToBeFormatted({ 38 | snippet: "char", 39 | expectedOutput: "char", 40 | entryPoint: "integralType" 41 | }); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/snippets/types-values-and-variables/numericType/test.spec.ts: -------------------------------------------------------------------------------- 1 | import { BaseCstPrettierPrinter } from "../../../../../src/base-cst-printer.js"; 2 | import { assert, spy } from "sinon"; 3 | import { formatJavaSnippet } from "../../../../test-utils.js"; 4 | 5 | describe("numericType", () => { 6 | let integralTypeSpy: any; 7 | let floatingPointTypeSpy: any; 8 | 9 | // eslint-disable-next-line no-undef 10 | beforeEach(() => { 11 | if (integralTypeSpy !== undefined) { 12 | integralTypeSpy.restore(); 13 | } 14 | if (floatingPointTypeSpy !== undefined) { 15 | floatingPointTypeSpy.restore(); 16 | } 17 | 18 | integralTypeSpy = spy(BaseCstPrettierPrinter.prototype, "integralType"); 19 | floatingPointTypeSpy = spy( 20 | BaseCstPrettierPrinter.prototype, 21 | "floatingPointType" 22 | ); 23 | }); 24 | 25 | it("can format byte keyword", async () => { 26 | const snippet = "byte"; 27 | const entryPoint = "numericType"; 28 | 29 | await formatJavaSnippet({ snippet, entryPoint }); 30 | assert.callCount(integralTypeSpy, 1); 31 | assert.callCount(floatingPointTypeSpy, 0); 32 | }); 33 | 34 | it("can format double keyword", async () => { 35 | const snippet = "double"; 36 | const entryPoint = "numericType"; 37 | 38 | await formatJavaSnippet({ snippet, entryPoint }); 39 | assert.callCount(integralTypeSpy, 0); 40 | assert.callCount(floatingPointTypeSpy, 1); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/snippets/types-values-and-variables/wildcard/test.spec.ts: -------------------------------------------------------------------------------- 1 | import { assert, spy } from "sinon"; 2 | import { BaseCstPrettierPrinter } from "../../../../../src/base-cst-printer.js"; 3 | import { expectSnippetToBeFormatted } from "../../../../test-utils.js"; 4 | 5 | describe("Wildcard", () => { 6 | let wildcardBoundsSpy: any; 7 | 8 | // eslint-disable-next-line no-undef 9 | beforeEach(() => { 10 | if (wildcardBoundsSpy !== undefined) { 11 | wildcardBoundsSpy.restore(); 12 | } 13 | wildcardBoundsSpy = spy(BaseCstPrettierPrinter.prototype, "wildcardBounds"); 14 | }); 15 | 16 | it("can format a wildcard", async () => { 17 | await expectSnippetToBeFormatted({ 18 | snippet: "?", 19 | expectedOutput: "?", 20 | entryPoint: "wildcard" 21 | }); 22 | }); 23 | 24 | it("can format a wildcard with one annotations", async () => { 25 | await expectSnippetToBeFormatted({ 26 | snippet: "@Anno ?", 27 | expectedOutput: "@Anno ?", 28 | entryPoint: "wildcard" 29 | }); 30 | }); 31 | 32 | it("can format a wildcard with annotations that exceed printWidth ", async () => { 33 | const snippet = 34 | "@Annotation1 @Annotation2 @Annotation3 @Annotation4 @Annotation5 @Annotation6 @Annotation7 ?"; 35 | const expectedOutput = 36 | "@Annotation1 @Annotation2 @Annotation3 @Annotation4 @Annotation5 @Annotation6 @Annotation7 ?"; 37 | 38 | await expectSnippetToBeFormatted({ 39 | snippet, 40 | expectedOutput, 41 | entryPoint: "wildcard" 42 | }); 43 | }); 44 | 45 | it("can format a wildcard with wildcardBound", async () => { 46 | await expectSnippetToBeFormatted({ 47 | snippet: "? extends int[]", 48 | expectedOutput: "? extends int[]", 49 | entryPoint: "wildcard" 50 | }); 51 | assert.calledTwice(wildcardBoundsSpy); 52 | }); 53 | }); 54 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/snippets/types-values-and-variables/wildcardBounds/test.spec.ts: -------------------------------------------------------------------------------- 1 | import { assert, spy } from "sinon"; 2 | import { BaseCstPrettierPrinter } from "../../../../../src/base-cst-printer.js"; 3 | import { expectSnippetToBeFormatted } from "../../../../test-utils.js"; 4 | 5 | describe("Wildcard Bounds", () => { 6 | let referenceTypeSpy: any; 7 | 8 | // eslint-disable-next-line no-undef 9 | beforeEach(() => { 10 | if (referenceTypeSpy !== undefined) { 11 | referenceTypeSpy.restore(); 12 | } 13 | referenceTypeSpy = spy(BaseCstPrettierPrinter.prototype, "referenceType"); 14 | }); 15 | 16 | it("can format a wildcardBounds with extends", async () => { 17 | await expectSnippetToBeFormatted({ 18 | snippet: "extends int[]", 19 | expectedOutput: "extends int[]", 20 | entryPoint: "wildcardBounds" 21 | }); 22 | assert.callCount(referenceTypeSpy, 2); 23 | }); 24 | 25 | it("can format a wildcardBounds with super", async () => { 26 | await expectSnippetToBeFormatted({ 27 | snippet: "super int[]", 28 | expectedOutput: "super int[]", 29 | entryPoint: "wildcardBounds" 30 | }); 31 | assert.callCount(referenceTypeSpy, 2); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/switch/switch-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: switch", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/synchronized/_input.java: -------------------------------------------------------------------------------- 1 | class Synchronized { 2 | void doSomething() { 3 | synchronized (this.var) { 4 | doSynchronized(); 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/synchronized/_output.java: -------------------------------------------------------------------------------- 1 | class Synchronized { 2 | 3 | void doSomething() { 4 | synchronized (this.var) { 5 | doSynchronized(); 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/synchronized/synchronized-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: synchronized", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/template-expression/_input.java: -------------------------------------------------------------------------------- 1 | class TemplateExpression { 2 | 3 | String info = STR."My name is \{name}"; 4 | 5 | String s = STR."\{x} + \{y} = \{x + y}"; 6 | 7 | String s = STR."You have a \{getOfferType()} waiting for you!"; 8 | 9 | String msg = STR."The file \{filePath} \{file.exists() ? "does" : "does not"} exist"; 10 | 11 | String time = STR."The time is \{ 12 | // The java.time.format package is very useful 13 | DateTimeFormatter 14 | .ofPattern("HH:mm:ss") 15 | .format(LocalTime.now()) 16 | } right now"; 17 | 18 | String data = STR."\{index++}, \{index++}, \{index++}, \{index++}"; 19 | 20 | String s = STR."\{fruit[0]}, \{STR."\{fruit[1]}, \{fruit[2]}"}"; 21 | 22 | String html = STR.""" 23 | 24 | 25 | \{title} 26 | 27 | 28 |

\{text}

29 | 30 | 31 | """; 32 | 33 | String table = STR.""" 34 | Description Width Height Area 35 | \{zone[0].name} \{zone[0].width} \{zone[0].height} \{zone[0].area()} 36 | \{zone[1].name} \{zone[1].width} \{zone[1].height} \{zone[1].area()} 37 | \{zone[2].name} \{zone[2].width} \{zone[2].height} \{zone[2].area()} 38 | Total \{zone[0].area() + zone[1].area() + zone[2].area()} 39 | """; 40 | 41 | String table = FMT.""" 42 | Description Width Height Area 43 | %-12s\{zone[0].name} %7.2f\{zone[0].width} %7.2f\{zone[0].height} %7.2f\{zone[0].area()} 44 | %-12s\{zone[1].name} %7.2f\{zone[1].width} %7.2f\{zone[1].height} %7.2f\{zone[1].area()} 45 | %-12s\{zone[2].name} %7.2f\{zone[2].width} %7.2f\{zone[2].height} %7.2f\{zone[2].area()} 46 | \{" ".repeat(28)} Total %7.2f\{zone[0].area() + zone[1].area() + zone[2].area()} 47 | """; 48 | 49 | PreparedStatement ps = DB."SELECT * FROM Person p WHERE p.last_name = \{name}"; 50 | } 51 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/template-expression/_output.java: -------------------------------------------------------------------------------- 1 | class TemplateExpression { 2 | 3 | String info = STR."My name is \{name}"; 4 | 5 | String s = STR."\{x} + \{y} = \{x + y}"; 6 | 7 | String s = STR."You have a \{getOfferType()} waiting for you!"; 8 | 9 | String msg = 10 | STR."The file \{filePath} \{file.exists() ? "does" : "does not"} exist"; 11 | 12 | String time = 13 | STR."The time is \{ 14 | // The java.time.format package is very useful 15 | DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalTime.now()) 16 | } right now"; 17 | 18 | String data = STR."\{index++}, \{index++}, \{index++}, \{index++}"; 19 | 20 | String s = STR."\{fruit[0]}, \{STR."\{fruit[1]}, \{fruit[2]}"}"; 21 | 22 | String html = 23 | STR.""" 24 | 25 | 26 | \{title} 27 | 28 | 29 |

\{text}

30 | 31 | 32 | """; 33 | 34 | String table = 35 | STR.""" 36 | Description Width Height Area 37 | \{zone[0].name} \{zone[0].width} \{zone[0].height} \{zone[0].area()} 38 | \{zone[1].name} \{zone[1].width} \{zone[1].height} \{zone[1].area()} 39 | \{zone[2].name} \{zone[2].width} \{zone[2].height} \{zone[2].area()} 40 | Total \{zone[0].area() + zone[1].area() + zone[2].area()} 41 | """; 42 | 43 | String table = 44 | FMT.""" 45 | Description Width Height Area 46 | %-12s\{zone[0].name} %7.2f\{zone[0].width} %7.2f\{ 47 | zone[0].height 48 | } %7.2f\{zone[0].area()} 49 | %-12s\{zone[1].name} %7.2f\{zone[1].width} %7.2f\{ 50 | zone[1].height 51 | } %7.2f\{zone[1].area()} 52 | %-12s\{zone[2].name} %7.2f\{zone[2].width} %7.2f\{ 53 | zone[2].height 54 | } %7.2f\{zone[2].area()} 55 | \{" ".repeat(28)} Total %7.2f\{ 56 | zone[0].area() + zone[1].area() + zone[2].area() 57 | } 58 | """; 59 | 60 | PreparedStatement ps = 61 | DB."SELECT * FROM Person p WHERE p.last_name = \{name}"; 62 | } 63 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/template-expression/template-expression-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: template expression", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/text-blocks/_input.java: -------------------------------------------------------------------------------- 1 | public class TextBlock { 2 | 3 | void method() { 4 | String myTextBlock = """ 5 | my text 6 | 7 | 8 | sentence\""" 9 | 10 | """; 11 | 12 | 13 | String source = """ 14 | public void print(%s object) { 15 | System.out.println(Objects.toString(object)); 16 | } 17 | """.formatted(type); 18 | 19 | 20 | String html = """ 21 | \r 22 | \r 23 |

Hello, world

\r 24 | \r 25 | \r 26 | """; 27 | 28 | System.out.println( 29 | // leading comment 30 | """ 31 | abaoeu 32 | euaoeu 33 | aoeu 34 | 35 | oaeu 36 | abc""" // trailing comment 37 | ); 38 | 39 | System.out.println( 40 | """ 41 | abaoeu 42 | euaoeu 43 | aoeu 44 | 45 | oaeu 46 | abc""" 47 | ); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/text-blocks/_output.java: -------------------------------------------------------------------------------- 1 | public class TextBlock { 2 | 3 | void method() { 4 | String myTextBlock = 5 | """ 6 | my text 7 | 8 | 9 | sentence\""" 10 | 11 | """; 12 | 13 | String source = 14 | """ 15 | public void print(%s object) { 16 | System.out.println(Objects.toString(object)); 17 | } 18 | """.formatted(type); 19 | 20 | String html = 21 | """ 22 | \r 23 | \r 24 |

Hello, world

\r 25 | \r 26 | \r 27 | """; 28 | 29 | System.out.println( 30 | // leading comment 31 | """ 32 | abaoeu 33 | euaoeu 34 | aoeu 35 | 36 | oaeu 37 | abc""" // trailing comment 38 | ); 39 | 40 | System.out.println( 41 | """ 42 | abaoeu 43 | euaoeu 44 | aoeu 45 | 46 | oaeu 47 | abc""" 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/text-blocks/text-block-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: Text Blocks", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/throws/throws-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: throws", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/try_catch/try_catch-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: try catch", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/types/_input.java: -------------------------------------------------------------------------------- 1 | public class Types { 2 | 3 | public void primitiveTypes() { 4 | byte byteVariable; 5 | short shortVariable; 6 | int intVariable; 7 | long longVariable; 8 | float floatVariable; 9 | double doubleVariable; 10 | char charVariable; 11 | boolean booleanVariable; 12 | } 13 | 14 | public void dataTypes() { 15 | Byte byteVariable; 16 | Short shortVariable; 17 | Integer intVariable; 18 | Long longVariable; 19 | Float floatVariable; 20 | Double doubleVariable; 21 | Char charVariable; 22 | Boolean booleanVariable; 23 | String stringVariable; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/types/_output.java: -------------------------------------------------------------------------------- 1 | public class Types { 2 | 3 | public void primitiveTypes() { 4 | byte byteVariable; 5 | short shortVariable; 6 | int intVariable; 7 | long longVariable; 8 | float floatVariable; 9 | double doubleVariable; 10 | char charVariable; 11 | boolean booleanVariable; 12 | } 13 | 14 | public void dataTypes() { 15 | Byte byteVariable; 16 | Short shortVariable; 17 | Integer intVariable; 18 | Long longVariable; 19 | Float floatVariable; 20 | Double doubleVariable; 21 | Char charVariable; 22 | Boolean booleanVariable; 23 | String stringVariable; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/types/types-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: types", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/unnamed-class-compilation-unit/_input.java: -------------------------------------------------------------------------------- 1 | import com.toto.titi.Test; 2 | import com.toto.titi.Toast; 3 | 4 | class TestClass { static String greetings() { return "Hello world!"; } } 5 | interface TestInterface { default String greetings() { return "Hello world!"; } } 6 | 7 | ; 8 | String greeting() { return "Hello, World!"; } 9 | 10 | void main() { 11 | System.out.println(Test.greeting()); 12 | } 13 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/unnamed-class-compilation-unit/_output.java: -------------------------------------------------------------------------------- 1 | import com.toto.titi.Test; 2 | import com.toto.titi.Toast; 3 | 4 | class TestClass { 5 | 6 | static String greetings() { 7 | return "Hello world!"; 8 | } 9 | } 10 | 11 | interface TestInterface { 12 | default String greetings() { 13 | return "Hello world!"; 14 | } 15 | } 16 | 17 | String greeting() { 18 | return "Hello, World!"; 19 | } 20 | 21 | void main() { 22 | System.out.println(Test.greeting()); 23 | } 24 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/unnamed-class-compilation-unit/unnamed-class-compilation-unit-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: Unnamed Class Compilation Unit", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/unnamed-variables-and-patterns/unnamed-variables-and-patterns-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: unnamed variables & patterns", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/variables/variables-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: variables", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/while/_input.java: -------------------------------------------------------------------------------- 1 | public class While { 2 | 3 | public void simpleWhile(boolean one) { 4 | while (one) { 5 | System.out.println("one"); 6 | } 7 | } 8 | 9 | public void doWhile(boolean one) { 10 | do { 11 | System.out.println("one"); 12 | } while (one); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/while/_output.java: -------------------------------------------------------------------------------- 1 | public class While { 2 | 3 | public void simpleWhile(boolean one) { 4 | while (one) { 5 | System.out.println("one"); 6 | } 7 | } 8 | 9 | public void doWhile(boolean one) { 10 | do { 11 | System.out.println("one"); 12 | } while (one); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/while/while-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: while", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/yield-statement/_input.java: -------------------------------------------------------------------------------- 1 | class Test { 2 | enum Day { 3 | MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, 4 | SATURDAY, SUNDAY 5 | } 6 | 7 | public int calculate(Day d) { 8 | switch (d) { 9 | case SATURDAY, SUNDAY -> d.ordinal(); 10 | default -> { 11 | int len = d.toString().length(); 12 | yield len*len; 13 | } 14 | }; 15 | 16 | return; 17 | } 18 | 19 | public int calculate(Day d) { 20 | return switch (d) { 21 | case SATURDAY, SUNDAY -> d.ordinal(); 22 | default -> { 23 | int len = d.toString().length(); 24 | yield len*len; 25 | } 26 | }; 27 | } 28 | 29 | void should_not_throw_on_yield_static_imports() { 30 | Thread.yield (); 31 | yield(); 32 | yield(a); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/yield-statement/_output.java: -------------------------------------------------------------------------------- 1 | class Test { 2 | 3 | enum Day { 4 | MONDAY, 5 | TUESDAY, 6 | WEDNESDAY, 7 | THURSDAY, 8 | FRIDAY, 9 | SATURDAY, 10 | SUNDAY, 11 | } 12 | 13 | public int calculate(Day d) { 14 | switch (d) { 15 | case SATURDAY, SUNDAY -> d.ordinal(); 16 | default -> { 17 | int len = d.toString().length(); 18 | yield len * len; 19 | } 20 | } 21 | return; 22 | } 23 | 24 | public int calculate(Day d) { 25 | return switch (d) { 26 | case SATURDAY, SUNDAY -> d.ordinal(); 27 | default -> { 28 | int len = d.toString().length(); 29 | yield len * len; 30 | } 31 | }; 32 | } 33 | 34 | void should_not_throw_on_yield_static_imports() { 35 | Thread.yield(); 36 | yield(); 37 | yield (a); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/test/unit-test/yield-statement/yield-statement-spec.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import url from "url"; 3 | import { testSample } from "../../test-utils.js"; 4 | 5 | const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 6 | 7 | describe("prettier-java: yield statement", () => { 8 | testSample(__dirname); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/prettier-plugin-java/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES6", 4 | "baseUrl": "src", 5 | "outDir": "dist", 6 | "strict": true, 7 | "allowJs": true, 8 | "esModuleInterop": true, 9 | "noImplicitThis": false, 10 | "module": "ESNext", 11 | "moduleResolution": "Node" 12 | }, 13 | "include": ["src"] 14 | } 15 | -------------------------------------------------------------------------------- /scripts/deploy.sh: -------------------------------------------------------------------------------- 1 | echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc 2 | # lerna would fail if there are uncommited files in the git working tree 3 | # but it won't tell us what are the files, the "git status" command will help 4 | # debug CI failures (e.g in travis) 5 | git status 6 | yarn run lerna:publish 7 | -------------------------------------------------------------------------------- /website/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | -------------------------------------------------------------------------------- /website/README.md: -------------------------------------------------------------------------------- 1 | # Website 2 | 3 | This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator. 4 | 5 | ### Installation 6 | 7 | ``` 8 | $ yarn 9 | ``` 10 | 11 | ### Local Development 12 | 13 | ``` 14 | $ yarn start 15 | ``` 16 | 17 | This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. 18 | 19 | ### Build 20 | 21 | ``` 22 | $ yarn build 23 | ``` 24 | 25 | This command generates static content into the `build` directory and can be served using any static contents hosting service. 26 | 27 | ### Deployment 28 | 29 | Using SSH: 30 | 31 | ``` 32 | $ USE_SSH=true yarn deploy 33 | ``` 34 | 35 | Not using SSH: 36 | 37 | ``` 38 | $ GIT_USER= yarn deploy 39 | ``` 40 | 41 | If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. 42 | -------------------------------------------------------------------------------- /website/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve("@docusaurus/core/lib/babel/preset")] 3 | }; 4 | -------------------------------------------------------------------------------- /website/blog/2023-11-26-2.5.0.md: -------------------------------------------------------------------------------- 1 | --- 2 | author: "Jordan Kiesel (@jtkiesel)" 3 | authorURL: "https://github.com/jtkiesel" 4 | title: "Prettier Java 2.5: Java 21 unnamed patterns and variables preview feature!" 5 | --- 6 | 7 | This release adds support for the Java 21 preview feature: unnamed patterns and variables ([JEP 443](https://openjdk.org/jeps/443))! 8 | 9 | 10 | 11 | ## Highlights 12 | 13 | ### Support Java 21 preview feature: unnamed patterns and variables ([#620](https://github.com/jhipster/prettier-java/pull/620) by [@jtkiesel](https://github.com/jtkiesel)) 14 | 15 | We’ve added support for the Java 21 preview feature "Unnamed Patterns and Variables": 16 | 17 | #### Unnamed pattern variables 18 | 19 | ```java 20 | // Example 21 | r instanceof Point _ 22 | ``` 23 | 24 | #### Unnamed variables 25 | 26 | ```java 27 | // Example 28 | int acc = 0; 29 | for (Order _ : orders) { 30 | if (acc < LIMIT) { 31 | // ... acc++ ... 32 | } 33 | } 34 | ``` 35 | 36 | ## Other Changes 37 | 38 | ### New entrypoint `lexAndParse` to return both tokens and CST ([#625](https://github.com/jhipster/prettier-java/pull/625) by [@max-schaefer](https://github.com/max-schaefer)) 39 | 40 | Provide an entrypoint that exposes both the CST and the underlying token array. 41 | 42 | ### No longer ignore whole block when `prettier-ignore` at start ([#603](https://github.com/jhipster/prettier-java/pull/603) by [@jtkiesel](https://github.com/jtkiesel)) 43 | 44 | When a block begins with `// prettier-ignore`, only the first statement is ignored, rather than the whole block. 45 | 46 | 47 | ```java 48 | // Input 49 | void foo() { 50 | // prettier-ignore 51 | var bar = List.of( 52 | 1 53 | ); 54 | 55 | var baz = 2; 56 | } 57 | 58 | // Prettier Java 2.4 59 | void foo() { 60 | // prettier-ignore 61 | var bar = List.of( 62 | 1 63 | ); 64 | 65 | var baz = 2; 66 | } 67 | 68 | // Prettier Java 2.5 69 | void foo() { 70 | // prettier-ignore 71 | var bar = List.of( 72 | 1 73 | ); 74 | 75 | var baz = 2; 76 | } 77 | ``` 78 | -------------------------------------------------------------------------------- /website/docs/index.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | Prettier Java is an opinionated Java code formatter. 4 | 5 | It removes all original styling and ensures that all outputted code conforms to a consistent style. 6 | 7 | Prettier Java takes your code and reprints it from scratch by taking the line length into account. 8 | 9 | For example, take the following code: 10 | 11 | ```java 12 | foo(arg1, arg2, arg3, arg4); 13 | ``` 14 | 15 | It fits in a single line so it's going to stay as is. However, we've all run into this situation: 16 | 17 | 18 | ```java 19 | foo(reallyLongArg(), omgSoManyParameters(), IShouldRefactorThis(), isThereSeriouslyAnotherOne()); 20 | ``` 21 | 22 | Suddenly our previous format for calling function breaks down because this is too long. Prettier Java is going to do the painstaking work of reprinting it like that for you: 23 | 24 | ```java 25 | foo( 26 | reallyLongArg(), 27 | omgSoManyParameters(), 28 | IShouldRefactorThis(), 29 | isThereSeriouslyAnotherOne() 30 | ); 31 | ``` 32 | 33 | Prettier Java enforces a consistent code **style** (i.e. code formatting that won't affect the AST) across your entire codebase because it disregards the original styling by parsing it away and re-printing the parsed AST with its own rules that take the maximum line length into account, wrapping code when necessary. 34 | -------------------------------------------------------------------------------- /website/docs/installation.mdx: -------------------------------------------------------------------------------- 1 | import TabItem from "@theme/TabItem"; 2 | import Tabs from "@theme/Tabs"; 3 | 4 | # Installation 5 | 6 | ## Requirements 7 | 8 | - [Node.js](https://nodejs.org/en/download/) version 10.0 or above 9 | 10 | ## Install Prettier and the Prettier Java plugin 11 | 12 | 13 | 14 | 15 | ```sh 16 | npm install --save-dev --save-exact prettier prettier-plugin-java 17 | ``` 18 | 19 | 20 | 21 | 22 | ```sh 23 | yarn add --dev --exact prettier prettier-plugin-java 24 | ``` 25 | 26 | 27 | 28 | 29 | ```sh 30 | pnpm add --save-dev --save-exact prettier prettier-plugin-java 31 | ``` 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /website/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "website", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "docusaurus": "docusaurus", 7 | "start": "docusaurus start", 8 | "build": "docusaurus build", 9 | "swizzle": "docusaurus swizzle", 10 | "deploy": "docusaurus deploy", 11 | "clear": "docusaurus clear", 12 | "serve": "docusaurus serve", 13 | "write-translations": "docusaurus write-translations", 14 | "write-heading-ids": "docusaurus write-heading-ids", 15 | "typecheck": "tsc" 16 | }, 17 | "dependencies": { 18 | "@docusaurus/core": "^3", 19 | "@docusaurus/preset-classic": "^3", 20 | "@mdx-js/react": "^3", 21 | "@monaco-editor/react": "^4", 22 | "lz-string": "^1", 23 | "prettier": "^3", 24 | "prettier-plugin-java": "file:./../packages/prettier-plugin-java/dist", 25 | "prism-react-renderer": "^2", 26 | "react": "^19", 27 | "react-dom": "^19" 28 | }, 29 | "devDependencies": { 30 | "@docusaurus/module-type-aliases": "^3", 31 | "@docusaurus/tsconfig": "^3", 32 | "@docusaurus/types": "^3", 33 | "@types/react": "^19", 34 | "typescript": "^5" 35 | }, 36 | "browserslist": { 37 | "production": [ 38 | ">0.5%", 39 | "not dead", 40 | "not op_mini all" 41 | ], 42 | "development": [ 43 | "last 3 chrome version", 44 | "last 3 firefox version", 45 | "last 5 safari version" 46 | ] 47 | }, 48 | "engines": { 49 | "node": ">=18.0" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /website/src/components/CodeEditor/index.module.css: -------------------------------------------------------------------------------- 1 | .editor { 2 | width: calc(50vw - 100px); 3 | height: calc(100vh - 60px); 4 | border-left: 1px solid #ddd; 5 | } 6 | 7 | @media (max-width: 996px) { 8 | .editor { 9 | width: calc(100vw - 200px); 10 | height: calc(50vh - 30px); 11 | border-bottom: 1px solid #ddd; 12 | } 13 | 14 | .editor ~ .editor { 15 | border-bottom: none; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /website/src/components/CodeEditor/index.tsx: -------------------------------------------------------------------------------- 1 | import { useColorMode } from "@docusaurus/theme-common"; 2 | import Editor from "@monaco-editor/react"; 3 | import styles from "./index.module.css"; 4 | 5 | export default function CodeEditor( 6 | props: Readonly<{ 7 | readOnly?: boolean; 8 | rulers?: number[]; 9 | value?: string; 10 | onChange?: (value: string | undefined) => void; 11 | }> 12 | ) { 13 | const { colorMode } = useColorMode(); 14 | 15 | return ( 16 |
17 | 24 |
25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /website/src/css/custom.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --ifm-color-primary: #279af1; 3 | --ifm-color-primary-dark: #0f8ded; 4 | --ifm-color-primary-darker: #0e85e0; 5 | --ifm-color-primary-darkest: #0c6eb8; 6 | --ifm-color-primary-light: #41a6f3; 7 | --ifm-color-primary-lighter: #4eacf4; 8 | --ifm-color-primary-lightest: #76bff6; 9 | --ifm-color-warning: #fbbf47; 10 | --ifm-color-warning-dark: #fab427; 11 | --ifm-color-warning-darker: #faaf18; 12 | --ifm-color-warning-darkest: #dd9505; 13 | --ifm-color-warning-light: #fcca67; 14 | --ifm-color-warning-lighter: #fccf76; 15 | --ifm-color-warning-lightest: #fde0a6; 16 | --ifm-code-font-size: 95%; 17 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1); 18 | } 19 | 20 | [data-theme="dark"] { 21 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3); 22 | } 23 | -------------------------------------------------------------------------------- /website/src/pages/index.module.css: -------------------------------------------------------------------------------- 1 | .heroBanner { 2 | margin: 30px 10px; 3 | text-align: center; 4 | } 5 | 6 | .logoWide { 7 | margin-bottom: 30px; 8 | max-width: 685px; 9 | } 10 | 11 | .buttons { 12 | display: flex; 13 | justify-content: center; 14 | gap: 10px; 15 | } 16 | 17 | .sectionRow { 18 | justify-content: space-evenly; 19 | } 20 | 21 | .sectionCol { 22 | width: fit-content; 23 | flex: initial; 24 | } 25 | -------------------------------------------------------------------------------- /website/src/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import Link from "@docusaurus/Link"; 2 | import Heading from "@theme/Heading"; 3 | import Layout from "@theme/Layout"; 4 | import ThemedImage from "@theme/ThemedImage"; 5 | import styles from "./index.module.css"; 6 | 7 | function HomepageHeader() { 8 | return ( 9 |
10 |
11 | 15 |
16 | 17 | Try It Online 18 | 19 | 23 | Install Prettier Java 24 | 25 |
26 |
27 |
28 | ); 29 | } 30 | 31 | function TldrSection() { 32 | return ( 33 |
34 |
35 |
36 |
37 | # What is Prettier Java? 38 |
    39 |
  • An opinionated Java code formatter
  • 40 |
  • Integrates with most editors
  • 41 |
42 |
43 |
44 | # Why? 45 |
    46 |
  • Your code is formatted on save
  • 47 |
  • No need to discuss style in code review
  • 48 |
  • Saves you time and energy
  • 49 |
50 |
51 |
52 |
53 |
54 | ); 55 | } 56 | 57 | export default function Home(): JSX.Element { 58 | return ( 59 | 60 | 61 |
62 | 63 |
64 |
65 | ); 66 | } 67 | -------------------------------------------------------------------------------- /website/src/pages/playground/index.module.css: -------------------------------------------------------------------------------- 1 | .playground { 2 | display: flex; 3 | } 4 | 5 | .options { 6 | min-width: 200px; 7 | } 8 | 9 | .editors { 10 | display: flex; 11 | } 12 | 13 | @media (max-width: 996px) { 14 | .editors { 15 | flex-direction: column; 16 | } 17 | } 18 | 19 | details { 20 | padding: 15px 10px 10px; 21 | border-bottom: 1px solid #ddd; 22 | } 23 | 24 | label { 25 | display: block; 26 | margin: 10px 0; 27 | font: 28 | 12px Consolas, 29 | Courier New, 30 | Courier, 31 | monospace; 32 | } 33 | 34 | input[type="number"] { 35 | max-width: 48px; 36 | } 37 | -------------------------------------------------------------------------------- /website/static/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhipster/prettier-java/a1b05b474a157165133bff7a86c1d2b88bbfa5b4/website/static/.nojekyll -------------------------------------------------------------------------------- /website/static/img/banner-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhipster/prettier-java/a1b05b474a157165133bff7a86c1d2b88bbfa5b4/website/static/img/banner-dark.png -------------------------------------------------------------------------------- /website/static/img/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jhipster/prettier-java/a1b05b474a157165133bff7a86c1d2b88bbfa5b4/website/static/img/favicon.png -------------------------------------------------------------------------------- /website/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // This file is not used in compilation. It is here just for a nice editor experience. 3 | "extends": "@docusaurus/tsconfig", 4 | "compilerOptions": { 5 | "baseUrl": "." 6 | } 7 | } 8 | --------------------------------------------------------------------------------