Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350205 - [reorg] Move Compilation unit with reference to inner type causes invalid imports
Summary: [reorg] Move Compilation unit with reference to inner type causes invalid imp...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-23 19:33 EDT by Andrew Eisenberg CLA
Modified: 2019-07-27 04:54 EDT (History)
2 users (show)

See Also:


Attachments
Project referred to in description (1.05 KB, application/octet-stream)
2011-06-23 19:34 EDT, Andrew Eisenberg CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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.