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

Bug 350205

Summary: [reorg] Move Compilation unit with reference to inner type causes invalid imports
Product: [Eclipse Project] JDT Reporter: Andrew Eisenberg <andrew.eisenberg>
Component: CoreAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r, satyam.kandula
Version: 3.7   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard: stalebug
Attachments:
Description Flags
Project referred to in description none

Description Andrew Eisenberg CLA 2011-06-23 19:33:42 EDT
In the attached project, move the compilation unit other/ToMove.java to the foo package.  The result is that the import statement is removed.  The import statement refers to an inner type in the foo.Outer class.

Next, fix the import statements in foo.ToMove, and then move it back to the other package.  Now, the import statements include foo.Outer when they don't need to.
Comment 1 Andrew Eisenberg CLA 2011-06-23 19:34:22 EDT
Created attachment 198505 [details]
Project referred to in description
Comment 2 Andrew Eisenberg CLA 2011-06-23 19:41:18 EDT
It looks like one problem is that the method org.eclipse.jdt.internal.corext.refactoring.reorg.MoveCuUpdateCreator.getDestinationPackageTypes() calls getAllTypes instead of getTypes.  Simply changing the method call would likely solve the first problem described in the description (ie- the erroneous removal of the inner class import).

The second problem (the erroneous addition of the outer import) is likely caused by the method org.eclipse.jdt.internal.corext.refactoring.structure.ReferenceFinderUtil.getTypeReferencesIn(IJavaElement, WorkingCopyOwner, IProgressMonitor) erroneously including outer types as a reference.

The fix for this is a little more nuanced.  Let me check if I can see something easily.
Comment 3 Andrew Eisenberg CLA 2011-06-23 19:49:05 EDT
It looks like org.eclipse.jdt.internal.core.search.matching.TypeReferenceLocator.reportDeclaration(ReferenceBinding, int, MatchLocator, SimpleSet) is reporting a match for a particular type, and then also reporting a match for all of its enclosing types.

In this particular situation, this is the wrong behavior.  Perhaps there can be a flag passed into TypeReferenceLocator that can toggle implicitly matching on enclosing types.
Comment 4 Satyam Kandula CLA 2011-06-24 02:16:09 EDT
Moving to JDT/UI as this should be better handled there
Comment 5 Eclipse Genie CLA 2019-07-27 04:54:53 EDT
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.

If you have further information on the current state of the bug, please add it. 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.