Skip to content

Add checks for OpenJDK Style - Wildcard Imports #19734

@Anushreebasics

Description

@Anushreebasics

Description

Add Checkstyle checks for all rules under §3.3.1 - Wildcard Imports of the OpenJDK Java Style Guidelines v6.

https://checkstyle.org/styleguides/openjdk-java-style-v6/openjdk-styleguide.html#s3.3.1-wildcard-imports

Parent issue: #19604
Image

Rules covered

Wildcard imports should in general not be used.
When importing a large number of closely-related classes (such as implementing a visitor over a tree with dozens of distinct “node” classes), a wildcard import may be used.
In any case, no more than one wildcard import per file should be used.

Motivation
Wildcard imports makes it unclear what actually needs to be imported.
Having more than one wildcard import makes the code fragile since adding a new class in one of the imported packages can introduce a name clash.
An unused import gives a false impression of a dependency. Also, many IDEs list such import statements as warnings which clutters the list of problems.

Checks to add to openjdk_checks.xml

TreeWalker-level:

<module name="AvoidStarImport"/>

Files to update in PR(s)

  1. openjdk_checks.xml
  2. openjdk_style.xml (replace the relevant ??? entry for §3.3.1)
  3. Integration tests under the OpenJDK style chapter/rule folder structure

Progress tracker

Check Rule Status
AvoidStarImport No wildcard imports
AvoidStarImport No static wildcard imports

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