|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2012 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2014 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 7-12
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Yves Joan <yves.joan@oracle.com> - [reorg] Copy action should NOT add 'copy of' prefix - https://bugs.eclipse.org/bugs/show_bug.cgi?id=151668 |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jdt.ui.tests.refactoring.ccp; |
12 |
package org.eclipse.jdt.ui.tests.refactoring.ccp; |
| 12 |
|
13 |
|
|
Lines 173-184
public class CopyTest extends RefactoringTest {
Link Here
|
| 173 |
private static final String NEW_FILE_NAME= "UnusedName.gif"; |
174 |
private static final String NEW_FILE_NAME= "UnusedName.gif"; |
| 174 |
private static final String NEW_FOLDER_NAME= "UnusedName"; |
175 |
private static final String NEW_FOLDER_NAME= "UnusedName"; |
| 175 |
private static final String NEW_CU_NAME= "UnusedName"; |
176 |
private static final String NEW_CU_NAME= "UnusedName"; |
|
|
177 |
private String fCuInitialSuggestedName= "unset"; |
| 178 |
private String fResourceInitialSuggestedName= "unset"; |
| 176 |
|
179 |
|
| 177 |
public INewNameQuery createNewCompilationUnitNameQuery(ICompilationUnit cu, String s) { |
180 |
public INewNameQuery createNewCompilationUnitNameQuery(ICompilationUnit cu, String s) { |
|
|
181 |
setCuInitialSuggestedName(s); |
| 178 |
return createStaticQuery(NEW_CU_NAME); |
182 |
return createStaticQuery(NEW_CU_NAME); |
| 179 |
} |
183 |
} |
| 180 |
|
184 |
|
| 181 |
public INewNameQuery createNewResourceNameQuery(IResource res, String s) { |
185 |
public INewNameQuery createNewResourceNameQuery(IResource res, String s) { |
|
|
186 |
setResourceInitialSuggestedName(s); |
| 182 |
if (res instanceof IFile) |
187 |
if (res instanceof IFile) |
| 183 |
return createStaticQuery(NEW_FILE_NAME); |
188 |
return createStaticQuery(NEW_FILE_NAME); |
| 184 |
else |
189 |
else |
|
Lines 204-209
public class CopyTest extends RefactoringTest {
Link Here
|
| 204 |
public INewNameQuery createNewPackageFragmentRootNameQuery(IPackageFragmentRoot root, String initialSuggestedName) { |
209 |
public INewNameQuery createNewPackageFragmentRootNameQuery(IPackageFragmentRoot root, String initialSuggestedName) { |
| 205 |
return createStaticQuery(NEW_PACKAGE_FRAGMENT_ROOT_NAME); |
210 |
return createStaticQuery(NEW_PACKAGE_FRAGMENT_ROOT_NAME); |
| 206 |
} |
211 |
} |
|
|
212 |
|
| 213 |
public String getCuInitialSuggestedName() { |
| 214 |
return fCuInitialSuggestedName; |
| 215 |
} |
| 216 |
|
| 217 |
private void setCuInitialSuggestedName(String cuInitialSuggestedName) { |
| 218 |
this.fCuInitialSuggestedName= cuInitialSuggestedName; |
| 219 |
} |
| 220 |
|
| 221 |
public String getResourceInitialSuggestedName() { |
| 222 |
return fResourceInitialSuggestedName; |
| 223 |
} |
| 224 |
|
| 225 |
public void setResourceInitialSuggestedName(String resourceInitialSuggestedName) { |
| 226 |
fResourceInitialSuggestedName= resourceInitialSuggestedName; |
| 227 |
} |
| 207 |
} |
228 |
} |
| 208 |
|
229 |
|
| 209 |
private static class MockCancelNameQueries implements INewNameQueries{ |
230 |
private static class MockCancelNameQueries implements INewNameQueries{ |
|
Lines 1481-1486
public class CopyTest extends RefactoringTest {
Link Here
|
| 1481 |
ParticipantTesting.testCopy(handles, new CopyArguments[] { |
1502 |
ParticipantTesting.testCopy(handles, new CopyArguments[] { |
| 1482 |
new CopyArguments(destination, log) |
1503 |
new CopyArguments(destination, log) |
| 1483 |
}); |
1504 |
}); |
|
|
1505 |
assertEquals("a2.txt", ((MockNewNameQueries)queries).getResourceInitialSuggestedName()); |
| 1484 |
} |
1506 |
} |
| 1485 |
|
1507 |
|
| 1486 |
public void testCopy_File_to_Same_Folder_Cancel() throws Exception { |
1508 |
public void testCopy_File_to_Same_Folder_Cancel() throws Exception { |
|
Lines 1541-1546
public class CopyTest extends RefactoringTest {
Link Here
|
| 1541 |
assertTrue("new file does not exist after copying", newFile.exists()); |
1563 |
assertTrue("new file does not exist after copying", newFile.exists()); |
| 1542 |
} |
1564 |
} |
| 1543 |
|
1565 |
|
|
|
1566 |
public void testCopy_File_to_Itself_2() throws Exception { |
| 1567 |
copy_File_to_Itself_2_impl("A.java", "A2.java", "A3.java"); |
| 1568 |
} |
| 1569 |
|
| 1570 |
public void testCopy_File_to_Itself_3() throws Exception { |
| 1571 |
copy_File_to_Itself_2_impl("A.B8.java", "A.B9.java", "A.B10.java"); |
| 1572 |
} |
| 1573 |
|
| 1574 |
public void testCopy_File_to_Itself_4() throws Exception { |
| 1575 |
copy_File_to_Itself_2_impl("fileNameWithoutAnyDot", "fileNameWithoutAnyDot2", "fileNameWithoutAnyDot3"); |
| 1576 |
} |
| 1577 |
|
| 1578 |
public void testCopy_File_to_Itself_5() throws Exception { |
| 1579 |
copy_File_to_Itself_2_impl(".fileNameStartingWithDot", ".fileNameStartingWithDot2", ".fileNameStartingWithDot3"); |
| 1580 |
} |
| 1581 |
|
| 1582 |
public void testCopy_File_to_Itself_6() throws Exception { |
| 1583 |
copy_File_to_Itself_2_impl("..fileNameStartingWithTwoDots", ".2.fileNameStartingWithTwoDots", ".3.fileNameStartingWithTwoDots"); |
| 1584 |
} |
| 1585 |
|
| 1586 |
public void copy_File_to_Itself_2_impl(String fileName, String conflictingFileName, String initialSuggestedName) throws Exception { |
| 1587 |
IFolder parentFolder= (IFolder)getPackageP().getResource(); |
| 1588 |
IFile file= parentFolder.getFile(fileName); |
| 1589 |
file.create(getStream("123"), true, null); |
| 1590 |
IFile conflictingFile= parentFolder.getFile(conflictingFileName); |
| 1591 |
conflictingFile.create(getStream("456"), true, null); |
| 1592 |
|
| 1593 |
INewNameQueries queries= new MockNewNameQueries(); |
| 1594 |
|
| 1595 |
IJavaElement[] javaElements= {}; |
| 1596 |
IResource[] resources= { file }; |
| 1597 |
JavaCopyProcessor ref= verifyEnabled(resources, javaElements, queries, createReorgQueries()); |
| 1598 |
|
| 1599 |
Object destination= file; |
| 1600 |
verifyValidDestination(ref, destination); |
| 1601 |
|
| 1602 |
assertTrue("source file does not exist before copying", file.exists()); |
| 1603 |
|
| 1604 |
RefactoringStatus status= performRefactoring(ref, false); |
| 1605 |
assertEquals(null, status); |
| 1606 |
|
| 1607 |
assertTrue("source file does not exist after copying", file.exists()); |
| 1608 |
|
| 1609 |
IFile newFile= parentFolder.getFile(MockNewNameQueries.NEW_FILE_NAME); |
| 1610 |
assertTrue("new file does not exist after copying", newFile.exists()); |
| 1611 |
assertEquals(initialSuggestedName, ((MockNewNameQueries)queries).getResourceInitialSuggestedName()); |
| 1612 |
} |
| 1613 |
|
| 1544 |
public void testCopy_File_to_AnotherFile() throws Exception { |
1614 |
public void testCopy_File_to_AnotherFile() throws Exception { |
| 1545 |
IFolder parentFolder= (IFolder) getPackageP().getResource(); |
1615 |
IFolder parentFolder= (IFolder) getPackageP().getResource(); |
| 1546 |
String fileName= "a.txt"; |
1616 |
String fileName= "a.txt"; |
|
Lines 1919-1924
public class CopyTest extends RefactoringTest {
Link Here
|
| 1919 |
|
1989 |
|
| 1920 |
ICompilationUnit newCu= getPackageP().getCompilationUnit(MockNewNameQueries.NEW_CU_NAME + ".java"); |
1990 |
ICompilationUnit newCu= getPackageP().getCompilationUnit(MockNewNameQueries.NEW_CU_NAME + ".java"); |
| 1921 |
assertTrue("new file does not exist after copying", newCu.exists()); |
1991 |
assertTrue("new file does not exist after copying", newCu.exists()); |
|
|
1992 |
assertEquals("A2", ((MockNewNameQueries)queries).getCuInitialSuggestedName()); |
| 1922 |
} |
1993 |
} |
| 1923 |
|
1994 |
|
| 1924 |
public void testCopy_Cu_to_OtherPackage() throws Exception { |
1995 |
public void testCopy_Cu_to_OtherPackage() throws Exception { |
|
Lines 2322-2328
public class CopyTest extends RefactoringTest {
Link Here
|
| 2322 |
folder.create(true, true, null); |
2393 |
folder.create(true, true, null); |
| 2323 |
IJavaElement[] javaElements= {}; |
2394 |
IJavaElement[] javaElements= {}; |
| 2324 |
IResource[] resources= {folder}; |
2395 |
IResource[] resources= {folder}; |
| 2325 |
JavaCopyProcessor ref= verifyEnabled(resources, javaElements, new MockNewNameQueries(), createReorgQueries()); |
2396 |
INewNameQueries queries= new MockNewNameQueries(); |
|
|
2397 |
|
| 2398 |
JavaCopyProcessor ref= verifyEnabled(resources, javaElements, queries, createReorgQueries()); |
| 2399 |
String[] handles= ParticipantTesting.createHandles(folder); |
| 2400 |
|
| 2401 |
Object destination= superFolder; |
| 2402 |
verifyValidDestination(ref, destination); |
| 2403 |
|
| 2404 |
assertTrue("source does not exist before copying", folder.exists()); |
| 2405 |
|
| 2406 |
RefactoringStatus status= performRefactoring(ref, false); |
| 2407 |
assertEquals(null, status); |
| 2408 |
|
| 2409 |
assertTrue("source does not exist after copying", folder.exists()); |
| 2410 |
IFolder newFolder= superFolder.getFolder(MockNewNameQueries.NEW_FOLDER_NAME); |
| 2411 |
assertTrue("copied folder does not exist after copying", newFolder.exists()); |
| 2412 |
ReorgExecutionLog log= new ReorgExecutionLog(); |
| 2413 |
log.markAsProcessed(folder); |
| 2414 |
log.setNewName(folder, MockNewNameQueries.NEW_FOLDER_NAME); |
| 2415 |
ParticipantTesting.testCopy(handles, new CopyArguments[] { |
| 2416 |
new CopyArguments(destination, log) |
| 2417 |
}); |
| 2418 |
assertEquals(folderName + "2", ((MockNewNameQueries)queries).getResourceInitialSuggestedName()); |
| 2419 |
|
| 2420 |
} |
| 2421 |
|
| 2422 |
|
| 2423 |
public void testCopy_folder_to_same_container_2() throws Exception { |
| 2424 |
copy_folder_to_same_container_2_impl("folder.name.with.segments"); |
| 2425 |
} |
| 2426 |
|
| 2427 |
public void testCopy_folder_to_same_container_3() throws Exception { |
| 2428 |
copy_folder_to_same_container_2_impl(".folderNameStartingWithDot"); |
| 2429 |
} |
| 2430 |
|
| 2431 |
public void copy_folder_to_same_container_2_impl(String folderName) throws Exception { |
| 2432 |
ParticipantTesting.reset(); |
| 2433 |
IProject superFolder= RefactoringTestSetup.getProject().getProject(); |
| 2434 |
IFolder folder= superFolder.getFolder(folderName); |
| 2435 |
folder.create(true, true, null); |
| 2436 |
IJavaElement[] javaElements= {}; |
| 2437 |
IResource[] resources= { folder }; |
| 2438 |
INewNameQueries queries= new MockNewNameQueries(); |
| 2439 |
|
| 2440 |
IFolder secondFolder= superFolder.getFolder(folderName + "2"); |
| 2441 |
secondFolder.create(true, true, null); |
| 2442 |
|
| 2443 |
JavaCopyProcessor ref= verifyEnabled(resources, javaElements, queries, createReorgQueries()); |
| 2326 |
String[] handles= ParticipantTesting.createHandles(folder); |
2444 |
String[] handles= ParticipantTesting.createHandles(folder); |
| 2327 |
|
2445 |
|
| 2328 |
Object destination= superFolder; |
2446 |
Object destination= superFolder; |
|
Lines 2342-2347
public class CopyTest extends RefactoringTest {
Link Here
|
| 2342 |
ParticipantTesting.testCopy(handles, new CopyArguments[] { |
2460 |
ParticipantTesting.testCopy(handles, new CopyArguments[] { |
| 2343 |
new CopyArguments(destination, log) |
2461 |
new CopyArguments(destination, log) |
| 2344 |
}); |
2462 |
}); |
|
|
2463 |
assertEquals(folderName + "3", ((MockNewNameQueries)queries).getResourceInitialSuggestedName()); |
| 2345 |
|
2464 |
|
| 2346 |
} |
2465 |
} |
| 2347 |
|
2466 |
|