|
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 |
IFolder parentFolder= (IFolder)getPackageP().getResource(); |
| 1568 |
String fileName= "A.java"; |
| 1569 |
IFile file= parentFolder.getFile(fileName); |
| 1570 |
file.create(getStream("123"), true, null); |
| 1571 |
String conflictingFileName= "A2.java"; |
| 1572 |
IFile conflictingFile= parentFolder.getFile(conflictingFileName); |
| 1573 |
conflictingFile.create(getStream("456"), true, null); |
| 1574 |
|
| 1575 |
INewNameQueries queries= new MockNewNameQueries(); |
| 1576 |
|
| 1577 |
IJavaElement[] javaElements= {}; |
| 1578 |
IResource[] resources= { file }; |
| 1579 |
JavaCopyProcessor ref= verifyEnabled(resources, javaElements, queries, createReorgQueries()); |
| 1580 |
|
| 1581 |
Object destination= file; |
| 1582 |
verifyValidDestination(ref, destination); |
| 1583 |
|
| 1584 |
assertTrue("source file does not exist before copying", file.exists()); |
| 1585 |
|
| 1586 |
RefactoringStatus status= performRefactoring(ref, false); |
| 1587 |
assertEquals(null, status); |
| 1588 |
|
| 1589 |
assertTrue("source file does not exist after copying", file.exists()); |
| 1590 |
|
| 1591 |
IFile newFile= parentFolder.getFile(MockNewNameQueries.NEW_FILE_NAME); |
| 1592 |
assertTrue("new file does not exist after copying", newFile.exists()); |
| 1593 |
assertEquals("A3.java", ((MockNewNameQueries)queries).getResourceInitialSuggestedName()); |
| 1594 |
} |
| 1595 |
|
| 1544 |
public void testCopy_File_to_AnotherFile() throws Exception { |
1596 |
public void testCopy_File_to_AnotherFile() throws Exception { |
| 1545 |
IFolder parentFolder= (IFolder) getPackageP().getResource(); |
1597 |
IFolder parentFolder= (IFolder) getPackageP().getResource(); |
| 1546 |
String fileName= "a.txt"; |
1598 |
String fileName= "a.txt"; |
|
Lines 1919-1924
public class CopyTest extends RefactoringTest {
Link Here
|
| 1919 |
|
1971 |
|
| 1920 |
ICompilationUnit newCu= getPackageP().getCompilationUnit(MockNewNameQueries.NEW_CU_NAME + ".java"); |
1972 |
ICompilationUnit newCu= getPackageP().getCompilationUnit(MockNewNameQueries.NEW_CU_NAME + ".java"); |
| 1921 |
assertTrue("new file does not exist after copying", newCu.exists()); |
1973 |
assertTrue("new file does not exist after copying", newCu.exists()); |
|
|
1974 |
assertEquals("A2", ((MockNewNameQueries)queries).getCuInitialSuggestedName()); |
| 1922 |
} |
1975 |
} |
| 1923 |
|
1976 |
|
| 1924 |
public void testCopy_Cu_to_OtherPackage() throws Exception { |
1977 |
public void testCopy_Cu_to_OtherPackage() throws Exception { |
|
Lines 2322-2328
public class CopyTest extends RefactoringTest {
Link Here
|
| 2322 |
folder.create(true, true, null); |
2375 |
folder.create(true, true, null); |
| 2323 |
IJavaElement[] javaElements= {}; |
2376 |
IJavaElement[] javaElements= {}; |
| 2324 |
IResource[] resources= {folder}; |
2377 |
IResource[] resources= {folder}; |
| 2325 |
JavaCopyProcessor ref= verifyEnabled(resources, javaElements, new MockNewNameQueries(), createReorgQueries()); |
2378 |
INewNameQueries queries= new MockNewNameQueries(); |
|
|
2379 |
|
| 2380 |
JavaCopyProcessor ref= verifyEnabled(resources, javaElements, queries, createReorgQueries()); |
| 2381 |
String[] handles= ParticipantTesting.createHandles(folder); |
| 2382 |
|
| 2383 |
Object destination= superFolder; |
| 2384 |
verifyValidDestination(ref, destination); |
| 2385 |
|
| 2386 |
assertTrue("source does not exist before copying", folder.exists()); |
| 2387 |
|
| 2388 |
RefactoringStatus status= performRefactoring(ref, false); |
| 2389 |
assertEquals(null, status); |
| 2390 |
|
| 2391 |
assertTrue("source does not exist after copying", folder.exists()); |
| 2392 |
IFolder newFolder= superFolder.getFolder(MockNewNameQueries.NEW_FOLDER_NAME); |
| 2393 |
assertTrue("copied folder does not exist after copying", newFolder.exists()); |
| 2394 |
ReorgExecutionLog log= new ReorgExecutionLog(); |
| 2395 |
log.markAsProcessed(folder); |
| 2396 |
log.setNewName(folder, MockNewNameQueries.NEW_FOLDER_NAME); |
| 2397 |
ParticipantTesting.testCopy(handles, new CopyArguments[] { |
| 2398 |
new CopyArguments(destination, log) |
| 2399 |
}); |
| 2400 |
assertEquals(folderName + "2", ((MockNewNameQueries)queries).getResourceInitialSuggestedName()); |
| 2401 |
|
| 2402 |
} |
| 2403 |
|
| 2404 |
public void testCopy_folder_to_same_container_2() throws Exception { |
| 2405 |
ParticipantTesting.reset(); |
| 2406 |
IProject superFolder= RefactoringTestSetup.getProject().getProject(); |
| 2407 |
String folderName= "folder.name.with.segments"; |
| 2408 |
IFolder folder= superFolder.getFolder(folderName); |
| 2409 |
folder.create(true, true, null); |
| 2410 |
IJavaElement[] javaElements= {}; |
| 2411 |
IResource[] resources= { folder }; |
| 2412 |
INewNameQueries queries= new MockNewNameQueries(); |
| 2413 |
|
| 2414 |
String secondFolderName= "folder.name.with.segments2"; |
| 2415 |
IFolder secondFolder= superFolder.getFolder(secondFolderName); |
| 2416 |
secondFolder.create(true, true, null); |
| 2417 |
|
| 2418 |
JavaCopyProcessor ref= verifyEnabled(resources, javaElements, queries, createReorgQueries()); |
| 2326 |
String[] handles= ParticipantTesting.createHandles(folder); |
2419 |
String[] handles= ParticipantTesting.createHandles(folder); |
| 2327 |
|
2420 |
|
| 2328 |
Object destination= superFolder; |
2421 |
Object destination= superFolder; |
|
Lines 2342-2347
public class CopyTest extends RefactoringTest {
Link Here
|
| 2342 |
ParticipantTesting.testCopy(handles, new CopyArguments[] { |
2435 |
ParticipantTesting.testCopy(handles, new CopyArguments[] { |
| 2343 |
new CopyArguments(destination, log) |
2436 |
new CopyArguments(destination, log) |
| 2344 |
}); |
2437 |
}); |
|
|
2438 |
assertEquals(folderName + "3", ((MockNewNameQueries)queries).getResourceInitialSuggestedName()); |
| 2345 |
|
2439 |
|
| 2346 |
} |
2440 |
} |
| 2347 |
|
2441 |
|