Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent import from being removed if it is shadowing a type in the java.lang package #29

Open
ctubbsii opened this issue May 6, 2020 · 0 comments
Milestone

Comments

@ctubbsii
Copy link
Member

ctubbsii commented May 6, 2020

The treatSamePackageAsUnused feature will remove imports for types in the same package as the compilation unit.

However, it may be necessary to keep some of these import statements, in order for the package-local type to shadow a type of the same simple name in the java.lang package. For example, in JDK14, there may be a class in the same package called Record. Removing the explicit import statement will cause java.lang.Record to be used instead of the package-local type that the explicit import statement intended.

I can think of a few mitigations for this:

  1. Keep the package-local import statement if a type, n, exists as java.lang.n (the problem with this is we can only check the build-time JDK, not the target JDK the code is being compiled for, without a lot of extra configuration and pre-defined JDK target signatures, so it could still be overly aggressive),
  2. Add a plugin configuration option to exclude properties from automatic removal, by name (or pattern), or
  3. Add a comment-parsing option so specific imports can be annotated inline in the code to always keep specific imports.
@ctubbsii ctubbsii added this to the 1.5.0 milestone May 6, 2020
@ctubbsii ctubbsii modified the milestones: 1.5.0, 1.6.0 Jan 28, 2021
@ctubbsii ctubbsii modified the milestones: 1.6.0, 1.7.0 Mar 7, 2021
@ctubbsii ctubbsii modified the milestones: 1.7.0, 1.8.0 May 24, 2022
@ctubbsii ctubbsii modified the milestones: 1.8.0, 1.9.0 Nov 23, 2022
@ctubbsii ctubbsii modified the milestones: 1.9.0, 1.10.0 May 10, 2023
@hazendaz hazendaz modified the milestones: 1.10.0, 1.11.0 May 27, 2024
@hazendaz hazendaz modified the milestones: 1.11.0, 1.12.0 Jun 27, 2024
@hazendaz hazendaz modified the milestones: 1.12.0, 1.13.0 Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants