Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/MoveTest.java61
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/reorg/ReorgPolicyFactory.java7
2 files changed, 65 insertions, 3 deletions
diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/MoveTest.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/MoveTest.java
index 5cef40f5ab..35685698e8 100644
--- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/MoveTest.java
+++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/MoveTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -567,6 +567,65 @@ public class MoveTest extends RefactoringTest {
}
}
+ public void testDestination_no_fileToParentDefaultPackage() throws Exception {
+ IPackageFragment defaultPackage= getRoot().getPackageFragment("");
+ assertTrue(defaultPackage.exists());
+ IFolder superFolder= (IFolder)defaultPackage.getResource();
+ IFile file= superFolder.getFile("a.txt");
+ file.create(getStream("123"), true, null);
+
+ try {
+ IJavaElement[] javaElements= {};
+ IResource[] resources= { file };
+ JavaMoveProcessor ref= verifyEnabled(resources, javaElements, createReorgQueries());
+ Object destination= defaultPackage;
+ verifyInvalidDestination(ref, destination);
+ } finally {
+ performDummySearch();
+ file.delete(true, false, null);
+ }
+ }
+
+ public void testDestination_no_fileToParentDefaultPackage2() throws Exception {
+ IPackageFragment defaultPackage= getRoot().getPackageFragment("");
+ assertTrue(defaultPackage.exists());
+ ICompilationUnit cu= defaultPackage.createCompilationUnit("A.java", "class A{}", false, new NullProgressMonitor());
+ IFolder superFolder= (IFolder)defaultPackage.getResource();
+ IFile file= superFolder.getFile("a.txt");
+ file.create(getStream("123"), true, null);
+
+ try {
+ IJavaElement[] javaElements= {};
+ IResource[] resources= { file };
+ JavaMoveProcessor ref= verifyEnabled(resources, javaElements, createReorgQueries());
+ Object destination= cu;
+ verifyInvalidDestination(ref, destination);
+ } finally {
+ performDummySearch();
+ file.delete(true, false, null);
+ safeDelete(cu);
+ }
+ }
+
+ public void testDestination_no_fileToParentSourceFolder2() throws Exception {
+ IPackageFragmentRoot root= getRoot();
+ assertTrue(root.exists());
+ IFolder superFolder= (IFolder)root.getPackageFragment("").getResource();
+ IFile file= superFolder.getFile("a.txt");
+ file.create(getStream("123"), true, null);
+
+ try {
+ IJavaElement[] javaElements= {};
+ IResource[] resources= { file };
+ JavaMoveProcessor ref= verifyEnabled(resources, javaElements, createReorgQueries());
+ Object destination= root;
+ verifyInvalidDestination(ref, destination);
+ } finally {
+ performDummySearch();
+ file.delete(true, false, null);
+ }
+ }
+
public void testDestination_no_folderToParentFolder() throws Exception {
IProject superFolder= RefactoringTestSetup.getProject().getProject();
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/reorg/ReorgPolicyFactory.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/reorg/ReorgPolicyFactory.java
index 84607253a6..46589013de 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/reorg/ReorgPolicyFactory.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/reorg/ReorgPolicyFactory.java
@@ -1648,10 +1648,13 @@ public final class ReorgPolicyFactory {
if (destination.equals(commonParent))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
IContainer destinationAsContainer= getDestinationAsContainer();
- if (destinationAsContainer != null && destinationAsContainer.equals(commonParent))
+ if (destinationAsContainer != null && (destinationAsContainer.equals(commonParent) || commonParent instanceof IPackageFragmentRoot
+ && destinationAsContainer.equals(((IPackageFragmentRoot) commonParent).getResource())))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
IPackageFragment destinationAsPackage= getDestinationAsPackageFragment();
- if (destinationAsPackage != null && destinationAsPackage.equals(commonParent))
+
+ if (destinationAsPackage != null && (destinationAsPackage.equals(commonParent) || commonParent instanceof IPackageFragment
+ && (destinationAsPackage.equals(((IPackageFragment) commonParent).getResource()))))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
if (cannotUpdateReferencesForDestination())

Back to the top