Skip to content

Formatting Java Source Code #31

@wfouche

Description

@wfouche

Use a Java source formatting tool so that code formatting is standarised.

Option 1: use Google Java Format. We have no control over how the code is formatted, the Google Standards are strictly enforced including comments which are reflowed across lines and using a 100 character line length.

Experimented with formatting the Jython source tree (src folder) using Windows Powershell command:

Get-ChildItem -Path src -Include *.java -File -Recurse | ForEach-Object { jbang run com.google.googlejavaformat:google-java-format:1.29.0 --aosp -r $_.FullName }

Option 2: Use the Eclipse Java Formatter. It does not reformat Java comments

jbang-fmt makes it easy to run the Eclipse Java Formatter.

jbang-catalog.json

{
  "aliases": {
    "jbang-fmt": {
      "script-ref": "jbang-fmt@jbangdev/jbang-fmt",
      "description": "A script that formats Jython's Java Source Code",
      "arguments": [
        "--line-length",
        "90",
        "--java",
        "8",
        "--indent-with",
        "space",
        "--indent-size",
        "4",
        "src"
      ]
    }
  }
}

Applied jbang jbang-fmt to the Jython source tree:

Processed 896 files (758 changed, 138 clean, 0 skipped) in 2,1s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions