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

Bug 459320

Summary: [ImportRewrite] adds import for declared package when pasting to CU outside of classpath
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Markus Keller <markus.kell.r>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipse, markus.kell.r
Version: 4.5   
Target Milestone: 4.5 M6   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on: 430303    
Bug Blocks:    
Attachments:
Description Flags
Fix in old ImportRewriteAnalyzer none

Description Markus Keller CLA 2015-02-06 09:40:34 EST
Created attachment 250583 [details]
Fix in old ImportRewriteAnalyzer

Follow-up to bug 454914 comment 3.

ImportRewrite adds an unused import for the declared package when pasting into a compilation unit that is outside of the project's classpath.

Steps:
- check out SWT from Git and set the project up for your platform (copy .classpath file)
- open MenuItem#setToolTipText(String) from the classpath
- copy doc line to clipboard:
 * {@link Shell#setMenuBar(Menu) shell menubar} on Windows, Mac, and Ubuntu Unity desktop.
- Open Resource..., open a MenuItem.java that is not on classpath
- set caret to first line of class Javadoc
- Paste

=> bad import added:
import org.eclipse.swt.widgets.*;

The attached fix is for the old ImportRewriteAnalyzer (before bug 430303). I still had this in my workspace and need to save it somewhere. Didn't release since it would conflict with bug 430303, and I guess it's better to get that one done first.
Comment 1 John Glassmyer CLA 2015-02-06 10:29:25 EST
Similar code can be added to JAVA_LANG_AND_CU_PACKAGE.determineImplicitImportContainers in the new ImportRewriteAnalyzer.
Comment 3 Sasikanth Bharadwaj CLA 2015-03-18 04:31:49 EDT
Verified for 4.5 M6 using I20150316-2000 build