Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 359724

Summary: [organize imports] nested type imports not collapsed to wildcards ('*')
Product: [Eclipse Project] JDT Reporter: Dmitri Bichko <dbichko>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, eclipse, samrat.dhillon, stephan.herrmann
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug
Attachments:
Description Flags
Proposed fix for this bug
none
Path for this bug using egit
none
Fix for this bug none

Description Dmitri Bichko CLA 2011-10-03 11:38:29 EDT
Build Identifier: 20110916-0149

With "number of imports needed for .*" set appropriately low, individual nested type imports are not replaced with wildcards, eg:

import java.lang.Character.Subset;
import java.lang.Character.UnicodeBlock;

additionally, wildcard imports are expanded:

import java.lang.Character.*;

is replaced by two imports (as above; assuming both types are used)

Reproducible: Always

Steps to Reproduce:
1. set "number of imports needed for .*" to 1
2. import a nested type as wildcard:

  import java.lang.Character.*;
  Subset cs;

3. run "organize imports"
Comment 1 Ayushman Jain CLA 2011-10-04 04:39:01 EDT
I couldn't reproduce with I20110911-2000. Will update to a newer build and check. I tried with the following test:
import java.util.Collection;
import java.util.ArrayList;

class X {
	int foo(Collection bar) { return 0; }
//	double foo(Collection<String> bar) {return 0; }
	ArrayList<String> list;
}

Can you provide a testcase that can help me reproduce? Maybe it only happens in a specific scenario. Thanks!
Comment 2 Stephan Herrmann CLA 2011-10-04 06:26:22 EDT
(In reply to comment #1)
> I couldn't reproduce with I20110911-2000. Will update to a newer build and
> check. I tried with the following test:
> import java.util.Collection;
> import java.util.ArrayList;
> 
> class X {
>     int foo(Collection bar) { return 0; }
> //    double foo(Collection<String> bar) {return 0; }
>     ArrayList<String> list;
> }
> 
> Can you provide a testcase that can help me reproduce? Maybe it only happens in
> a specific scenario. Thanks!

I think you missed by part about "nested types".
Here's a funny example:

import java.lang.Character.*;
import java.util.Collection;
import java.util.ArrayList;

public class Bug359724 {
	Collection<Subset> c;
	ArrayList<UnicodeBlock> al;
}

try organize imports in this file after setting 
"number of imports needed for .*" to 1, here's what I see afterwards:

import java.lang.Character.Subset;
import java.lang.Character.UnicodeBlock;
import java.util.*;

public class Bug359724 {
	Collection<Subset> c;
	ArrayList<UnicodeBlock> al;
}
Comment 3 Ayushman Jain CLA 2011-10-04 07:50:47 EDT
(In reply to comment #2)
> I think you missed by part about "nested types".
Oops, yes. :)
Comment 4 Samrat Dhillon CLA 2012-02-25 19:24:14 EST
Created attachment 211628 [details]
Proposed fix for this bug

Patch for ImportRewriteAnalyzer. I did not run the tests to see if it broke anything else.
Comment 5 Ayushman Jain CLA 2012-02-26 10:51:44 EST
(In reply to comment #4)
> Created attachment 211628 [details]
> Proposed fix for this bug
Thanks for the patch Samrat. unfortunately this is built out of old code which you found in the CVS repository. We've moved to Git and so it'll be great if you could clone the jdt.core git repo and provide a patch based on the latest version of the code. The git details can be found at http://wiki.eclipse.org/Platform-releng/Git_Workflows
Thanks for contributing! let me know if you need any help.
Comment 6 Samrat Dhillon CLA 2012-02-26 11:20:42 EST
(In reply to comment #5)
> (In reply to comment #4)
> > Created attachment 211628 [details]
> > Proposed fix for this bug
> Thanks for the patch Samrat. unfortunately this is built out of old code which
> you found in the CVS repository. We've moved to Git and so it'll be great if
> you could clone the jdt.core git repo and provide a patch based on the latest
> version of the code. The git details can be found at
> http://wiki.eclipse.org/Platform-releng/Git_Workflows
> Thanks for contributing! let me know if you need any help.

Should I clone from master or REL 3_7
Comment 7 Ayushman Jain CLA 2012-02-26 11:49:55 EST
(In reply to comment #6)
> Should I clone from master or REL 3_7

Yes, master is the latest. Its history should look like this: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/log/
Comment 8 Samrat Dhillon CLA 2012-02-26 13:54:48 EST
Created attachment 211642 [details]
Path for this bug using egit

Please let me know if this is the correct format the patch.
Comment 9 Stephan Herrmann CLA 2012-02-26 14:08:49 EST
(In reply to comment #8)
> Created attachment 211642 [details]
> Path for this bug using egit
> 
> Please let me know if this is the correct format the patch.

The format looks OK but now it contains lots of changes that are actual commits in the JDT git repo, not specific to your patch, like you created the diff between the old CVS and the current HEAD in git?
Comment 10 Samrat Dhillon CLA 2012-02-26 14:23:07 EST
Created attachment 211643 [details]
Fix for this bug

Please check. Thanks for your patience :)
Comment 11 Ayushman Jain CLA 2012-02-28 12:41:21 EST
(In reply to comment #10)
> Created attachment 211643 [details]
> Fix for this bug
> 
> Please check. Thanks for your patience :)
Thanks Samrat, this patch applies cleanly. We will review the patch as soon as we can and get back with questions/comments.
Comment 12 Samrat Dhillon CLA 2012-08-20 15:03:28 EDT
(In reply to comment #11)
> (In reply to comment #10)
> > Created attachment 211643 [details]
> > Fix for this bug
> > 
> > Please check. Thanks for your patience :)
> Thanks Samrat, this patch applies cleanly. We will review the patch as soon
> as we can and get back with questions/comments.

Hi Ayush, just wanted to send you a gentle reminder that this patch needs a review.
Comment 13 John Glassmyer CLA 2014-06-06 05:34:46 EDT
I believe this is a dupe of bug 318437.

(In any event, I am nearly finished rewriting ImportRewriteAnalyzer in a way that fixes this issue and several others.)
Comment 14 Eclipse Genie CLA 2020-02-14 11:24:38 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.