diff options
| author | Raksha Vasisht | 2011-10-11 06:30:17 +0000 |
|---|---|---|
| committer | Raksha Vasisht | 2011-10-11 09:01:55 +0000 |
| commit | ee8c2c86df0424451b6b5f4853e0766683239b31 (patch) | |
| tree | 51896451d8b012635b0fefcfa37ea423c3568399 | |
| parent | 8bddf00407bfda5dcb448394c7dfd59664ed5281 (diff) | |
| download | eclipse.jdt.ui-ee8c2c86df0424451b6b5f4853e0766683239b31.tar.gz eclipse.jdt.ui-ee8c2c86df0424451b6b5f4853e0766683239b31.tar.xz eclipse.jdt.ui-ee8c2c86df0424451b6b5f4853e0766683239b31.zip | |
Fixed bug 350347: [reorg] Move text file to "default package"v20111011-0800
folder deletes the file with exception report
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()) |
