Skip to content

Wildcard import not format #956

Closed
Closed

Description

@ehsanazali

Intelij: IntelliJ IDEA 2023.1.2 (Ultimate Edition)
google-java-format: 1.16.0.2
Mac M1
in Doc we read:

3.3.1 No wildcard imports
Wildcard imports, static or otherwise, are not used.

I see wildcard imports in my classes, try to correct them with Recormat Code and Reformat File but seems to me google format can not identify them. when I turn them off. intrlij can concert it to single class import. . when I turn google format back on. it can not correct the wildcard import.
Unfortunately, the Google format does not correct the usage of wildcard imports in my classes. From what I've found on the internet, this seems to be a bug. Is there any way to fix it locally? for example somehow override google format with intelij config?

Activity

  1. changed the title [-]No wildcard not formatedt[/-] [+]Wildcard import not format[/+] on Aug 9, 2023
  2. cushon commented on Aug 11, 2023

    @cushon
    Collaborator

    In general google-java-format only tries to fix style issues that can be resolved by changing whitespace, it doesn't generally add or remove non-whitespace parts of the program, like replacing a wildcard import with single-type imports.

    This isn't a problem the formatter can solve. One technical reason for that is that it is just looking at the syntax of one file at a time, it would need to compile the file (and have access to a classpath dependencies) to be able to figure out which imports a wildcard import corresponds to.

  3. tbroyer commented on Aug 11, 2023

    @tbroyer
    Contributor

    I believe the IntelliJ IDEA plugin could though. WDYT?

  4. poliveira-fuze commented on Sep 2, 2024

    @poliveira-fuze

    @ehsanazali were you able to fix it, through maven?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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