Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 330740 - [Organize imports] Adding unnecessary static import
Summary: [Organize imports] Adding unnecessary static import
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-20 11:40 EST by Pascal Filion CLA
Modified: 2020-02-09 17:07 EST (History)
2 users (show)

See Also:


Attachments
Shows the problem described (2.16 KB, application/x-zip-compressed)
2010-11-20 11:41 EST, Pascal Filion CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pascal Filion CLA 2010-11-20 11:40:51 EST
Build Identifier: N20101112-2000

When using static import, a Save Action adds the static import for the interface even though a class implementing it is already declared in the static import list.

Reproducible: Always

Steps to Reproduce:
1. Import the attached zip file.
2. Open Test.java
3. Remove the second static import
4. Save the file

Problem: The static import is re-added and a warning is displayed.
Comment 1 Pascal Filion CLA 2010-11-20 11:41:14 EST
Created attachment 183522 [details]
Shows the problem described
Comment 2 Olivier Thomann CLA 2010-11-21 19:46:23 EST
The second import is reported as unused, because the CONSTANT is resolved through the abstract class.
If you are using a single import and not an import on demand, then it is not tagged as unused.
So we need to detect that the second import is not needed as the first import can be used to resolve the second one.
Markus, I am not sure the current infrastructure let us do this.
I'll investigate.
Comment 3 Olivier Thomann CLA 2010-11-26 11:51:36 EST
Imports are processed in their defined order.
Since the first import can be used to resolve the constant CONSTANT1, the second one is reported as never used.

I would say the fix in this case would be to detect that the second import is not needed inside OrganizeImport when the first import is using an import on demand.
Comment 4 Olivier Thomann CLA 2010-11-26 12:16:58 EST
In this case we have a problem with the staticImportOnDemandThreshold. When the two imports for the static references are added, they are added as single imports.
In this case, both imports are needed.

But when they are converted to on demand import, one of them is not longer needed.

I'll investigate how we can fix this.
Comment 5 Eclipse Genie CLA 2020-02-09 17:07:41 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.