Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 243164 Details for
Bug 151668
[reorg] Copy action should NOT add 'copy of' prefix
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix proposal
bug151668.patch.diff (text/plain), 10.97 KB, created by
Yves Joan
on 2014-05-16 05:59:59 EDT
(
hide
)
Description:
Fix proposal
Filename:
MIME Type:
Creator:
Yves Joan
Created:
2014-05-16 05:59:59 EDT
Size:
10.97 KB
patch
obsolete
>From e9b0adee6962c577cdffec7b53ca98cbfd308204 Mon Sep 17 00:00:00 2001 >From: Yves Joan <yves.joan@oracle.com> >Date: Thu, 10 Apr 2014 10:04:51 +0200 >Subject: [PATCH] Bug 151668 - [reorg] Copy action should NOT add 'copy of' > prefix > >modified: org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyTest.java >modified: org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java >modified: org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties >modified: org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/reorg/ReorgPolicyFactory.java > >Signed-off-by: Yves Joan <yves.joan@oracle.com> >--- > .../jdt/ui/tests/refactoring/ccp/CopyTest.java | 52 ++++++++++++++++++++++ > .../refactoring/RefactoringCoreMessages.java | 8 ---- > .../corext/refactoring/refactoring.properties | 4 -- > .../refactoring/reorg/ReorgPolicyFactory.java | 46 +++++++++++++------ > 4 files changed, 84 insertions(+), 26 deletions(-) > >diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyTest.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyTest.java >index 43d2548..06bff20 100644 >--- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyTest.java >+++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyTest.java >@@ -173,12 +173,16 @@ public class CopyTest extends RefactoringTest { > private static final String NEW_FILE_NAME= "UnusedName.gif"; > private static final String NEW_FOLDER_NAME= "UnusedName"; > private static final String NEW_CU_NAME= "UnusedName"; >+ private String fCuInitialSuggestedName= "unset"; >+ private String fResourceInitialSuggestedName= "unset"; > > public INewNameQuery createNewCompilationUnitNameQuery(ICompilationUnit cu, String s) { >+ setCuInitialSuggestedName(s); > return createStaticQuery(NEW_CU_NAME); > } > > public INewNameQuery createNewResourceNameQuery(IResource res, String s) { >+ setResourceInitialSuggestedName(s); > if (res instanceof IFile) > return createStaticQuery(NEW_FILE_NAME); > else >@@ -204,6 +208,22 @@ public class CopyTest extends RefactoringTest { > public INewNameQuery createNewPackageFragmentRootNameQuery(IPackageFragmentRoot root, String initialSuggestedName) { > return createStaticQuery(NEW_PACKAGE_FRAGMENT_ROOT_NAME); > } >+ >+ public String getCuInitialSuggestedName() { >+ return fCuInitialSuggestedName; >+ } >+ >+ private void setCuInitialSuggestedName(String cuInitialSuggestedName) { >+ this.fCuInitialSuggestedName= cuInitialSuggestedName; >+ } >+ >+ public String getResourceInitialSuggestedName() { >+ return fResourceInitialSuggestedName; >+ } >+ >+ public void setResourceInitialSuggestedName(String resourceInitialSuggestedName) { >+ fResourceInitialSuggestedName= resourceInitialSuggestedName; >+ } > } > > private static class MockCancelNameQueries implements INewNameQueries{ >@@ -1481,6 +1501,7 @@ public class CopyTest extends RefactoringTest { > ParticipantTesting.testCopy(handles, new CopyArguments[] { > new CopyArguments(destination, log) > }); >+ assertEquals("a2.txt", ((MockNewNameQueries)queries).getResourceInitialSuggestedName()); > } > > public void testCopy_File_to_Same_Folder_Cancel() throws Exception { >@@ -1541,6 +1562,36 @@ public class CopyTest extends RefactoringTest { > assertTrue("new file does not exist after copying", newFile.exists()); > } > >+ public void testCopy_File_to_Itself_Conflict() throws Exception { >+ IFolder parentFolder= (IFolder) getPackageP().getResource(); >+ String fileName= "A.java"; >+ IFile file= parentFolder.getFile(fileName); >+ file.create(getStream("123"), true, null); >+ String conflictingFileName= "A2.java"; >+ IFile conflictingFile= parentFolder.getFile(conflictingFileName); >+ conflictingFile.create(getStream("456"), true, null); >+ >+ INewNameQueries queries= new MockNewNameQueries(); >+ >+ IJavaElement[] javaElements= {}; >+ IResource[] resources= { file }; >+ JavaCopyProcessor ref= verifyEnabled(resources, javaElements, queries, createReorgQueries()); >+ >+ Object destination= file; >+ verifyValidDestination(ref, destination); >+ >+ assertTrue("source file does not exist before copying", file.exists()); >+ >+ RefactoringStatus status= performRefactoring(ref, false); >+ assertEquals(null, status); >+ >+ assertTrue("source file does not exist after copying", file.exists()); >+ >+ IFile newFile= parentFolder.getFile(MockNewNameQueries.NEW_FILE_NAME); >+ assertTrue("new file does not exist after copying", newFile.exists()); >+ assertEquals("A3.java", ((MockNewNameQueries)queries).getResourceInitialSuggestedName()); >+ } >+ > public void testCopy_File_to_AnotherFile() throws Exception { > IFolder parentFolder= (IFolder) getPackageP().getResource(); > String fileName= "a.txt"; >@@ -1919,6 +1970,7 @@ public class CopyTest extends RefactoringTest { > > ICompilationUnit newCu= getPackageP().getCompilationUnit(MockNewNameQueries.NEW_CU_NAME + ".java"); > assertTrue("new file does not exist after copying", newCu.exists()); >+ assertEquals("A2", ((MockNewNameQueries)queries).getCuInitialSuggestedName()); > } > > public void testCopy_Cu_to_OtherPackage() throws Exception { >diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java >index 0627e01..72a7462 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java >@@ -276,18 +276,10 @@ public final class RefactoringCoreMessages extends NLS { > > public static String CopyPackageFragmentRootChange_copy; > >- public static String CopyRefactoring_cu_copyOf1; >- >- public static String CopyRefactoring_cu_copyOfMore; >- > public static String CopyRefactoring_package_copyOf1; > > public static String CopyRefactoring_package_copyOfMore; > >- public static String CopyRefactoring_resource_copyOf1; >- >- public static String CopyRefactoring_resource_copyOfMore; >- > public static String CopyRefactoring_update_ref; > > public static String CopyResourceString_copy; >diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties >index aea9fa3..4220880 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties >@@ -579,10 +579,6 @@ MoveCuUpdateCreator_update_imports=Update imports > MoveCuUpdateCreator_searching=Searching for references to types in ''{0}'' > MoveCuUpdateCreator_update_references=Update references > >-CopyRefactoring_cu_copyOf1=CopyOf{0} >-CopyRefactoring_cu_copyOfMore=Copy_{0}_of_{1} >-CopyRefactoring_resource_copyOf1=Copy of {0} >-CopyRefactoring_resource_copyOfMore=Copy ({0}) of {1} > CopyRefactoring_package_copyOf1={0}.copy > CopyRefactoring_package_copyOfMore={1}.copy{0} > >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 618686b..2daa9fe 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 >@@ -22,6 +22,8 @@ import java.util.List; > import java.util.Map; > import java.util.Set; > import java.util.StringTokenizer; >+import java.util.regex.Matcher; >+import java.util.regex.Pattern; > > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.CoreException; >@@ -2557,23 +2559,41 @@ public final class ReorgPolicyFactory { > > private final Set<String> fAutoGeneratedNewNames= new HashSet<String>(2); > >+ private String computeNewName(String str) { >+ final int lastIndexOfDot= str.lastIndexOf('.'); >+ String fileExtension= ""; //$NON-NLS-1$ >+ String fileNameNoExtension= str; >+ if (lastIndexOfDot != -1) { >+ fileExtension= str.substring(lastIndexOfDot); >+ fileNameNoExtension= str.substring(0, lastIndexOfDot); >+ } >+ final Pattern p= Pattern.compile("[0-9]+$"); //$NON-NLS-1$ >+ final Matcher m= p.matcher(fileNameNoExtension); >+ if (m.find()) { >+ // String ends with a number: increment it by 1 >+ final Integer newNumber= new Integer(Integer.parseInt(m.group()) + 1); >+ final String numberStr= m.replaceFirst(newNumber.toString()); >+ return numberStr + fileExtension; >+ } else { >+ return fileNameNoExtension + "2" + fileExtension; //$NON-NLS-1$ >+ } >+ } >+ > public String createNewName(ICompilationUnit cu, IPackageFragment destination) { > if (isNewNameOk(destination, cu.getElementName())) > return null; > if (!ReorgUtils.isParentInWorkspaceOrOnDisk(cu, destination)) > return null; >- int i= 1; >+ >+ String newName= computeNewName(cu.getElementName()); >+ > while (true) { >- String newName; >- if (i == 1) >- newName= Messages.format(RefactoringCoreMessages.CopyRefactoring_cu_copyOf1, cu.getElementName()); // Don't use BasicElementLabels! No RTL! >- else >- newName= Messages.format(RefactoringCoreMessages.CopyRefactoring_cu_copyOfMore, new String[] { String.valueOf(i), cu.getElementName()}); // Don't use BasicElementLabels! No RTL! > if (isNewNameOk(destination, newName) && !fAutoGeneratedNewNames.contains(newName)) { > fAutoGeneratedNewNames.add(newName); > return JavaCore.removeJavaLikeExtension(newName); >+ } else { >+ newName= computeNewName(newName); > } >- i++; > } > } > >@@ -2602,18 +2622,16 @@ public final class ReorgPolicyFactory { > return null; > if (!ReorgUtils.isParentInWorkspaceOrOnDisk(res, destination)) > return null; >- int i= 1; >+ >+ String newName= computeNewName(res.getName()); >+ > while (true) { >- String newName; >- if (i == 1) >- newName= Messages.format(RefactoringCoreMessages.CopyRefactoring_resource_copyOf1, res.getName()); // Don't use BasicElementLabels! No RTL! >- else >- newName= Messages.format(RefactoringCoreMessages.CopyRefactoring_resource_copyOfMore, new String[] { String.valueOf(i), res.getName()}); // Don't use BasicElementLabels! No RTL! > if (isNewNameOk(destination, newName) && !fAutoGeneratedNewNames.contains(newName)) { > fAutoGeneratedNewNames.add(newName); > return newName; >+ } else { >+ newName= computeNewName(newName); > } >- i++; > } > } > } >-- >1.8.4.2 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 151668
:
243164
|
243874
|
244110