Community
Participate
Working Groups
In RC2. Given code: import java.util.EnumMap; public class Exposer { public enum Category { GROCERIES, MORTGAGE } public class Account { class CategorySpending extends EnumMap<Category, Integer> { private static final long serialVersionUID = 1L; private CategorySpending() { super(Category.class); } int spendingIn(Category category) { if (!containsKey(category)) return 0; return get(category); } } private final CategorySpending _spent = new CategorySpending(); public void spend(Category category, int amount) { _spent.put(category, _spent.spendingIn(category) + amount); } } } Trying to invoke "Move member type to new file" on Account results in the error trace below. A very similar error occurs if you try to move instance method spend to class CategorySpending: Java Model Exception: Java Model Status [spendingIn(Exposer.Category) {key=Lnet/saff/Exposer$Account$CategorySpending;.spendingIn(Lnet/saff/Exposer$Category;)I} [in CategorySpending [in Account [in Exposer [in [Working copy] Exposer.java [in net.saff [in <project root> [in dupfinder]]]]]]] does not exist] at org.eclipse.jdt.internal.core.JavaElement.newNotPresentException(JavaElement.java:468) at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:499) at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:232) at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:218) at org.eclipse.jdt.internal.core.Member.getFlags(Member.java:147) at org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.adjustOutgoingVisibility(MemberVisibilityAdjustor.java:671) at org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.adjustOutgoingVisibility(MemberVisibilityAdjustor.java:690) at org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.adjustOutgoingVisibility(MemberVisibilityAdjustor.java:722) at org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.adjustVisibility(MemberVisibilityAdjustor.java:763) at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring.createChangeManager(MoveInnerToTopRefactoring.java:815) at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring.checkFinalConditions(MoveInnerToTopRefactoring.java:742) at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:84) at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:114) at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:189) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1719) at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:86) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)
Tobias, can you please investigate.
The member visibility adjustor calls IMember#getFlags on the ResolvedSourceMethod for spendingIn, which has been obtained from the search engine. The toString() output looks like this: spendingIn(Exposer.Category) (not open) {key=LSub~Exposer$Account$CategorySpending;.spendingIn(LExposer$Category;)I} [in CategorySpending [in Account [in Exposer [in [Working copy] Sub.java [in <default> [in <project root> [in Test]]]]]]] Moving to JDT Core for comments
Created attachment 23071 [details] Patch to fix this issue
philippe, may be a candidate for RC3?
+1 for RC3 Dirk - pls cast your vote.
+1 for RC3.
Fixed and released in HEAD. A smaller test case is: public class Test { public class C1 {} public class C2 { class C3 { int foo(C1 c) { return 0; } } public void foo(C1 c, int i) { new C3().foo(c); } } } Then invoke "Move member type to new file" on C2... [jdt-core internal] Test case added in JavaSearchBugsTests
The exception is gone and the refactoring Opened a new bug to track errors in the generated code: https://bugs.eclipse.org/bugs/show_bug.cgi?id=100413. Verified using build N20050616-0010 + JDT Core HEAD.