Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 393932 - [refactoring] pull-up with "use the destination type where possible" creates bogus import of nested type
Summary: [refactoring] pull-up with "use the destination type where possible" creates ...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.3 M4   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-08 17:14 EST by Stephan Herrmann CLA
Modified: 2012-11-10 06:31 EST (History)
1 user (show)

See Also:


Attachments
proposed patch (2.69 KB, patch)
2012-11-08 17:16 EST, Stephan Herrmann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2012-11-08 17:14:05 EST
Given this class:

package p;

public class C {
	protected class I1 {
		
	}
	protected class I2 extends I1 {
		protected void foo() {
			
		}
	}
	void test(I2 i) {
		i.foo();
	}
}

When pulling up foo() to I1 and enabling "use the destination type where possible" the change in test(..) creates a bogus import of the inner class I1.

Result is:

package p;

import p.C.I1; // BUG

public class C {
	protected class I1 {

		protected void foo() {
			
		}
		
	}
	protected class I2 extends I1 {
	}
	void test(I1 i) {
		i.foo();
	}
}

The bug seems to originate from the fact that SuperTypeRefactoringProcessor.createCorrespondingNode(CompilationUnitRewrite, TType) calls ImportRewrite.addImportFromSignature(String,AST) with no proper ImportRewriteContext.
Comment 1 Stephan Herrmann CLA 2012-11-08 17:16:45 EST
Created attachment 223371 [details]
proposed patch

could it be as simple as this?

The patch fixes the immediate issue, not sure if more needs to be done for a full solution?
Comment 2 Markus Keller CLA 2012-11-09 09:22:05 EST
Yes, it's really as simple as that, thanks for the patch.

Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=686e984f6a987f453770fc1ff7ed856e27238d93
Comment 3 Stephan Herrmann CLA 2012-11-10 06:31:44 EST
(In reply to comment #2)
> Fixed with
> http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/
> ?id=686e984f6a987f453770fc1ff7ed856e27238d93

Thanks