Skip to content

Add checks for OpenJDK Style §3.3 - Import statements #19623

@aclfe

Description

@aclfe

Parent issue: #19604

Description

Add Checkstyle checks for all rules under §3.3 - Import statements of the OpenJDK Java Style Guidelines v6.

Image

Rules covered

From §3.3 - Import statements:

  1. Import statements should be sorted primarily by non-static / static with non-static imports first, secondarily by package origin (java → javax → external → internal), and tertiary by package and class identifier in lexicographical order. - ImportOrder Check
  2. Import statements should not be line wrapped, regardless of whether it exceeds the recommended maximum length of a line. - NoLineWrap Check
  3. No unused imports should be present. - UnusedImports Check

Checks to add to openjdk_checks.xml

TreeWalker-level:

<module name="ImportOrder">
  <property name="groups" value="java,javax,org,com"/>
  <property name="ordered" value="true"/>
  <property name="separated" value="true"/>
  <property name="option" value="bottom"/>
  <property name="sortStaticImportsAlphabetically" value="true"/>
</module>

<module name="NoLineWrap">
  <property name="tokens" value="IMPORT, STATIC_IMPORT"/>
</module>

<module name="UnusedImports"/>

Progress Tracker

Check Rule PR
ImportOrder Import statements should be sorted (non-static first, by package origin, lexicographically) #19628
NoLineWrap Import statements should not be line wrapped
UnusedImports No unused imports should be present

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions