Bug 541630 - Quick assist for static import removes non static import statements when it should not
Summary: Quick assist for static import removes non static import statements when it s...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.10   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 4.10 RC2   Edit
Assignee: Fabian Pfaff CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 197850 542653
  Show dependency tree
 
Reported: 2018-11-28 05:26 EST by Sarika Sinha CLA
Modified: 2019-02-13 03:57 EST (History)
1 user (show)

See Also:
sarika.sinha: review+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sarika Sinha CLA 2018-11-28 05:26:21 EST
package bug;

import bug.a.A;

public class B {
	public B() {
		A.bbb(); // invokde quick assist
		A.bbb();
		new A().bbb();
                new A().ccc(); // ccc is a non static method

	}
}

Using the quick assist to replace all static import occurrences removes the non static import import bug.a.A; which leads to compilation error for 2 lines.
new A().bbb();
new A().ccc();
Comment 1 Eclipse Genie CLA 2018-11-28 20:25:49 EST
New Gerrit change created: https://git.eclipse.org/r/133226
Comment 2 Sarika Sinha CLA 2018-11-30 03:06:19 EST
Looks good for RC2.
Comment 4 Noopur Gupta CLA 2018-12-06 05:41:24 EST
The actual issue is still not fixed. If you have the following code:

package p2;

import pkg.A;

public class B {
	public B() {
		A.bbb();
		System.out.println(A.class);
	}
}

and invoke quick assist on #bbb, it still removes the import for A causing compile error.

You can check the ImportRewrite APIs which automatically detect if an import is still being referenced in the file as the expression could be anything and present anywhere in the file. For example, consider a single file having:

package p2;

import pkg.A;

public class B {
	public B() {
		A.bbb();
	}
}

class C {
	{
		System.out.println(A.class);
	}
}

Fabian, please open a new bug for 4.11 to fix this.
Comment 5 Noopur Gupta CLA 2018-12-11 02:55:25 EST
(In reply to Noopur Gupta from comment #4)
> The actual issue is still not fixed. If you have the following code:
> 
> package p2;
> 
> import pkg.A;
> 
> public class B {
> 	public B() {
> 		A.bbb();
> 		System.out.println(A.class);
> 	}
> }
> 
> and invoke quick assist on #bbb, it still removes the import for A causing
> compile error.
> 
> You can check the ImportRewrite APIs which automatically detect if an import
> is still being referenced in the file as the expression could be anything
> and present anywhere in the file. For example, consider a single file having:
> 
> package p2;
> 
> import pkg.A;
> 
> public class B {
> 	public B() {
> 		A.bbb();
> 	}
> }
> 
> class C {
> 	{
> 		System.out.println(A.class);
> 	}
> }
> 
> Fabian, please open a new bug for 4.11 to fix this.

Created bug 542653.