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 50015 Details for
Bug 67326
[refactoring] Rename related classes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch for renaming similar types
rename_similar_types.patch.txt (text/plain), 26.58 KB, created by
Gunnar Wagenknecht
on 2006-09-13 05:04:26 EDT
(
hide
)
Description:
patch for renaming similar types
Filename:
MIME Type:
Creator:
Gunnar Wagenknecht
Created:
2006-09-13 05:04:26 EDT
Size:
26.58 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringMessages.java,v >retrieving revision 1.41 >diff -u -r1.41 RefactoringMessages.java >--- ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringMessages.java 15 Jun 2006 11:23:09 -0000 1.41 >+++ ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringMessages.java 13 Sep 2006 09:04:42 -0000 >@@ -815,6 +815,8 @@ > public static String RenameTypeWizardSimilarElementsPage_name_empty; > > public static String RenameTypeWizardSimilarElementsPage_name_should_start_lowercase; >+ >+ public static String RenameTypeWizardSimilarElementsPage_name_should_start_uppercase; > > public static String RenameTypeWizardSimilarElementsPage_rename_to; > >Index: ui refactoring/org/eclipse/jdt/internal/ui/refactoring/refactoringui.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/refactoringui.properties,v >retrieving revision 1.244 >diff -u -r1.244 refactoringui.properties >--- ui refactoring/org/eclipse/jdt/internal/ui/refactoring/refactoringui.properties 15 Jun 2006 11:23:03 -0000 1.244 >+++ ui refactoring/org/eclipse/jdt/internal/ui/refactoring/refactoringui.properties 13 Sep 2006 09:04:43 -0000 >@@ -482,7 +482,7 @@ > RenameTypeWizard_unexpected_exception=An unexpected exception occurred. See the error log for more details > > RenameTypeWizardInputPage_description=Enter the new name for this type. >-RenameTypeWizardInputPage_update_similar_elements=Update &similarly named variables and methods >+RenameTypeWizardInputPage_update_similar_elements=Update &similarly named variables, methods and types > RenameTypeWizardInputPage_update_similar_elements_configure=<a>&Configure...</a> > RenameTypeWizardSimilarElementsPage_name_empty=Please enter a name. > RenameTypeWizardSimilarElementsPage_rename_to=Rename ''{0}'' to ''{1}'' >@@ -493,7 +493,8 @@ > RenameTypeWizardSimilarElementsPage_restore_defaults=Restore &Defaults > RenameTypeWizardSimilarElementsPage_change_name=&Change Name... > RenameTypeWizardSimilarElementsPage_name_should_start_lowercase=Element names should start with a lowercase character. >-RenameTypeWizardSimilarElementsPage_review_similar_elements=&Similarly named variables and methods to be renamed >+RenameTypeWizardSimilarElementsPage_name_should_start_uppercase=Element names should start with an uppercase character. >+RenameTypeWizardSimilarElementsPage_review_similar_elements=&Similarly named variables, methods and types to be renamed > RenameTypeWizardSimilarElementsPage_select_element_to_view_source=Select an element > > RenameTypeWizardSimilarElementsOptionsDialog_title=Similar Names Configuration >Index: core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameTypeProcessor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameTypeProcessor.java,v >retrieving revision 1.111 >diff -u -r1.111 RenameTypeProcessor.java >--- core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameTypeProcessor.java 17 Jul 2006 14:56:23 -0000 1.111 >+++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameTypeProcessor.java 13 Sep 2006 09:04:41 -0000 >@@ -83,6 +83,7 @@ > import org.eclipse.jdt.core.search.IJavaSearchScope; > import org.eclipse.jdt.core.search.SearchMatch; > import org.eclipse.jdt.core.search.SearchPattern; >+import org.eclipse.jdt.core.search.TypeDeclarationMatch; > import org.eclipse.jdt.core.search.TypeReferenceMatch; > > import org.eclipse.jdt.internal.corext.refactoring.Checks; >@@ -138,6 +139,9 @@ > private SearchResultGroup[] fReferences; > private TextChangeManager fChangeManager; > private QualifiedNameSearchResult fQualifiedNameSearchResult; >+ private SearchResultGroup[] fSimilarTypesSearchResults; >+ private Set/*<IType>*/ fSimilarTypes; >+ private Set/*<RenameTypeProcessor>*/ fSimilarTypesRenameProcessores; > > private boolean fUpdateReferences; > >@@ -154,6 +158,9 @@ > private Map/* <IJavaElement, String> */fFinalSimilarElementToName= null; > private int fRenamingStrategy; > >+ private boolean fIsComposite; >+ private GroupCategorySet fCategorySet; >+ > // Preloaded information for the UI. > private LinkedHashMap/* <IJavaElement, String> */fPreloadedElementToName= null; > private Map/* <IJavaElement, Boolean> */fPreloadedElementToSelection= null; >@@ -195,15 +202,37 @@ > * @param type the type, or <code>null</code> if invoked by scripting > */ > public RenameTypeProcessor(IType type) { >+ this(type, new TextChangeManager(true), null); >+ fIsComposite= false; >+ } >+ >+ /** >+ * Creates a new rename type processor. >+ * <p> >+ * This constructor is only used by <code>RenameTypeProcessor</code>. >+ * </p> >+ * @param type the field >+ * @param manager the change manager >+ * @param categorySet the group category set >+ */ >+ RenameTypeProcessor(IType type, TextChangeManager manager, GroupCategorySet categorySet) { >+ initialize(type); >+ fChangeManager= manager; >+ fCategorySet= categorySet; >+ fIsComposite= true; >+ } >+ >+ private void initialize(IType type) { > fType= type; > if (type != null) > setNewElementName(type.getElementName()); >+ > fUpdateReferences= true; //default is yes > fUpdateTextualMatches= false; > fUpdateSimilarElements= false; // default is no > fRenamingStrategy= RenamingNameSuggestor.STRATEGY_EXACT; > } >- >+ > public IType getType() { > return fType; > } >@@ -237,8 +266,32 @@ > String newCUName= getNewCompilationUnit().getElementName(); > result.rename(cu, new RenameArguments(newCUName, getUpdateReferences())); > } >+ >+ if(fUpdateSimilarElements) >+ computeSimilarTypeRenameModifications(result); >+ > return result; > } >+ >+ private void computeSimilarTypeRenameModifications(RenameModifications result) { >+ if(null == fSimilarTypes) >+ return; >+ >+ for (Iterator stream = fSimilarTypes.iterator(); stream.hasNext();) { >+ final IType similarType = (IType) stream.next(); >+ final String newTypeName= (String) fFinalSimilarElementToName.get(similarType); >+ >+ if(null != newTypeName) { >+ result.rename(similarType, new RenameTypeArguments(newTypeName, getUpdateReferences(), >+ getUpdateSimilarDeclarations(), getSimilarElements()), createParticipantDescriptorFilter()); >+ if (isPrimaryType(similarType)) { >+ ICompilationUnit cu= similarType.getCompilationUnit(); >+ String newCUName= getNewCompilationUnit(similarType).getElementName(); >+ result.rename(cu, new RenameArguments(newCUName, getUpdateReferences())); >+ } >+ } >+ } >+ } > > /* > * Note: this is a handle-only method! >@@ -249,6 +302,15 @@ > return Checks.isTopLevel(fType) && JavaCore.removeJavaLikeExtension(cuName).equals(typeName); > } > >+ /* >+ * Note: this is a handle-only method! >+ */ >+ private boolean isPrimaryType(IType someType) { >+ String cuName= someType.getCompilationUnit().getElementName(); >+ String typeName= someType.getElementName(); >+ return Checks.isTopLevel(someType) && JavaCore.removeJavaLikeExtension(cuName).equals(typeName); >+ } >+ > //---- IRenameProcessor ---------------------------------------------- > > public String getCurrentElementName(){ >@@ -268,24 +330,36 @@ > } > > public Object getNewElement() { >- if (Checks.isTopLevel(fType)) { >- return getNewCompilationUnit().getType(getNewElementName()); >+ return getNewType(fType); >+ } >+ >+ private IType getNewType(IType someType) { >+ final String newName = someType.equals(fType) ? getNewElementName() : (null != fFinalSimilarElementToName ? (String) fFinalSimilarElementToName.get(someType) : null); >+ if(null == newName) >+ return someType; //XXX should we return null instead? >+ >+ if (Checks.isTopLevel(someType)) { >+ return getNewCompilationUnit(someType).getType(newName); > } else { >- return fType.getDeclaringType().getType(getNewElementName()); >+ return someType.getDeclaringType().getType(newName); > } > } > > private ICompilationUnit getNewCompilationUnit() { >- ICompilationUnit cu= fType.getCompilationUnit(); >- if (isPrimaryType()) { >- IPackageFragment parent= fType.getPackageFragment(); >+ return getNewCompilationUnit(fType); >+ } >+ >+ private ICompilationUnit getNewCompilationUnit(IType someType) { >+ ICompilationUnit cu= someType.getCompilationUnit(); >+ if (isPrimaryType(someType)) { >+ IPackageFragment parent= someType.getPackageFragment(); > String renamedCUName= JavaModelUtil.getRenamedCUName(cu, getNewElementName()); > return parent.getCompilationUnit(renamedCUName); > } else { > return cu; > } > } >- >+ > //---- JavaRenameProcessor ------------------------------------------- > > protected RenameArguments createRenameArguments() { >@@ -409,6 +483,14 @@ > if (element instanceof IFile) { > if (Checks.isTopLevel(fType) && element.equals(fType.getResource())) > return getNewCompilationUnit().getResource(); >+ if (null != fSimilarTypes) { >+ for (Iterator stream = fSimilarTypes.iterator(); stream >+ .hasNext();) { >+ IType similarType = (IType) stream.next(); >+ if (Checks.isTopLevel(similarType) && element.equals(similarType.getResource())) >+ return getNewCompilationUnit(similarType).getResource(); >+ } >+ } > } > return element; > } >@@ -419,8 +501,23 @@ > public IJavaElement getRefactoredJavaElement(IJavaElement element) { > if (element instanceof ICompilationUnit) { > if (Checks.isTopLevel(fType) && element.equals(fType.getCompilationUnit())) >- return getNewCompilationUnit(); >- } else if (element instanceof IMember) { >+ return getNewCompilationUnit(); >+ if (null != fSimilarTypes) { >+ for (Iterator stream = fSimilarTypes.iterator(); stream.hasNext();) { >+ IType similarType = (IType) stream.next(); >+ if (Checks.isTopLevel(similarType) && element.equals(similarType.getCompilationUnit())) >+ return getNewCompilationUnit(similarType); >+ } >+ } >+ } >+ if (element instanceof IType) { >+ if(element.equals(fType)) >+ return (IJavaElement) getNewElement(); >+ else if (null != fSimilarTypes && fSimilarTypes.contains(element)) { >+ return getNewType((IType) element); >+ } >+ } >+ if (element instanceof IMember) { > final IType newType= (IType) getNewElement(); > final RefactoringHandleTransplanter transplanter= new RefactoringHandleTransplanter(fType, newType, fFinalSimilarElementToName); > return transplanter.transplantHandle((IMember) element); >@@ -453,7 +550,8 @@ > pm.beginTask("", 12 + referenceSearchTicks + affectedCusTicks + similarElementTicks + createChangeTicks + qualifiedNamesTicks); //$NON-NLS-1$ > pm.setTaskName(RefactoringCoreMessages.RenameTypeRefactoring_checking); > >- fChangeManager= new TextChangeManager(true); >+ //XXX: Any side effects if the text change manager is now managed in the constructor? >+ //fChangeManager= new TextChangeManager(true); > > result.merge(checkNewElementName(getNewElementName())); > if (result.hasFatalError()) >@@ -564,7 +662,7 @@ > // Search depends on the type, the new name, the similarly named elements, and > // the strategy > >- if (fReferences != null && (getNewElementName().equals(fCachedNewName)) && (fCachedRenameSimilarElements == getUpdateSimilarDeclarations()) && (fCachedRenamingStrategy == fRenamingStrategy)) >+ if (fReferences != null && fSimilarTypesSearchResults != null && fSimilarTypes != null && (getNewElementName().equals(fCachedNewName)) && (fCachedRenameSimilarElements == getUpdateSimilarDeclarations()) && (fCachedRenamingStrategy == fRenamingStrategy)) > return fCachedRefactoringStatus; > > fCachedNewName= getNewElementName(); >@@ -580,15 +678,19 @@ > > fPreloadedElementToName= new LinkedHashMap(); > fPreloadedElementToSelection= new HashMap(); >+ fSimilarTypes= new HashSet(); >+ >+ final RenamingNameSuggestor sugg= new RenamingNameSuggestor(fRenamingStrategy); > > final String unQualifiedTypeName= fType.getElementName(); > >+ final String unQualifiedSimilarTypeString= sugg.isInterfaceName(unQualifiedTypeName) ? sugg.getInterfaceName(unQualifiedTypeName) : unQualifiedTypeName; >+ fSimilarTypesSearchResults = RefactoringSearchEngine.search(SearchPattern.createPattern("*" + unQualifiedSimilarTypeString + "*", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH), RefactoringScopeFactory.create(fType), monitor, fCachedRefactoringStatus); //$NON-NLS-1$ //$NON-NLS-2$ >+ > monitor.beginTask("", fReferences.length); //$NON-NLS-1$ > > if (getUpdateSimilarDeclarations()) { > >- RenamingNameSuggestor sugg= new RenamingNameSuggestor(fRenamingStrategy); >- > for (int i= 0; i < fReferences.length; i++) { > final ICompilationUnit cu= fReferences[i].getCompilationUnit(); > if (cu == null) >@@ -657,6 +759,31 @@ > if (monitor.isCanceled()) > throw new OperationCanceledException(); > } >+ >+ // similar types to rename >+ for (int i = 0; i < fSimilarTypesSearchResults.length; i++) { >+ final ICompilationUnit cu= fSimilarTypesSearchResults[i].getCompilationUnit(); >+ if (cu == null) >+ continue; >+ >+ final SearchMatch[] results= fSimilarTypesSearchResults[i].getSearchResults(); >+ >+ for (int j= 0; j < results.length; j++) { >+ >+ if (! (results[j] instanceof TypeDeclarationMatch)) >+ continue; >+ >+ final TypeDeclarationMatch match= (TypeDeclarationMatch) results[j]; >+ final IJavaElement element= (IJavaElement) match.getElement(); >+ >+ if(element instanceof IType) { >+ final IType currentType = (IType) element; >+ addSimilarTypeRename(unQualifiedTypeName, sugg, currentType); >+ } >+ } >+ if (monitor.isCanceled()) >+ throw new OperationCanceledException(); >+ } > } > > for (Iterator iter= fPreloadedElementToName.keySet().iterator(); iter.hasNext();) { >@@ -667,6 +794,7 @@ > > } catch (OperationCanceledException e) { > fReferences= null; >+ fSimilarTypes = null; > fPreloadedElementToName= null; > throw new OperationCanceledException(); > } >@@ -722,6 +850,18 @@ > } > } > >+ private void addSimilarTypeRename(String unQualifiedTypeName, RenamingNameSuggestor sugg, IType similarType) { >+ if(fType.equals(similarType)) >+ return; >+ >+ final String newTypeName= sugg.suggestNewTypeName(similarType.getElementName(), unQualifiedTypeName, getNewElementName()); >+ >+ if (newTypeName != null) { >+ fPreloadedElementToName.put(similarType, newTypeName); >+ fSimilarTypes.add(similarType); >+ } >+ } >+ > private RefactoringStatus checkNewPathValidity() { > IContainer c= fType.getCompilationUnit().getResource().getParent(); > >@@ -937,7 +1077,9 @@ > RefactoringStatus result= new RefactoringStatus(); > > result.merge(Checks.checkCompileErrorsInAffectedFiles(fReferences, fType.getResource())); >+ result.merge(Checks.checkCompileErrorsInAffectedFiles(fSimilarTypesSearchResults)); > >+ // XXX: why is beginTask called here? > pm.beginTask("", fReferences.length); //$NON-NLS-1$ > result.merge(checkConflictingTypes(pm)); > return result; >@@ -990,7 +1132,7 @@ > > public Change createChange(IProgressMonitor monitor) throws CoreException { > try { >- monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 4); >+ monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 5); > String project= null; > IJavaProject javaProject= fType.getJavaProject(); > if (javaProject != null) >@@ -1022,7 +1164,8 @@ > descriptor.setUpdateSimilarDeclarations(fUpdateSimilarElements); > descriptor.setMatchStrategy(fRenamingStrategy); > final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeProcessor_change_name); >- result.addAll(fChangeManager.getAllChanges()); >+ if(!fIsComposite) >+ result.addAll(fChangeManager.getAllChanges()); > if (willRenameCU()) { > IResource resource= fType.getCompilationUnit().getResource(); > if (resource != null && resource.isLinked()) { >@@ -1039,12 +1182,44 @@ > } > } > monitor.worked(1); >+ if(fUpdateSimilarElements) { >+ Change[] similarTypesChanges= createSimilarTypesRenameChanges(new SubProgressMonitor(monitor, 1)); >+ if(null != similarTypesChanges) >+ result.addAll(similarTypesChanges); >+ } >+ else >+ monitor.worked(1); > return result; > } finally { >- fChangeManager= null; >+ // XXX: why was it nulled here? are there leaks? >+ //fChangeManager= null; > } > } > >+ private Change[] createSimilarTypesRenameChanges(IProgressMonitor monitor) throws CoreException { >+ try { >+ if(null == fSimilarTypesRenameProcessores || fSimilarTypesRenameProcessores.isEmpty()) >+ return null; >+ >+ // XXX does this work? >+ >+ >+ // TODO: task name? >+ monitor.beginTask("", fSimilarTypesRenameProcessores.size()); >+ List result = new ArrayList(fSimilarTypesRenameProcessores.size()); >+ for (Iterator stream = fSimilarTypesRenameProcessores.iterator(); stream.hasNext();) { >+ RenameTypeProcessor processor = (RenameTypeProcessor) stream.next(); >+ Change change = processor.createChange(new SubProgressMonitor(monitor, 1)); >+ if(null != change) >+ result.add(change); >+ } >+ >+ return (Change[]) result.toArray(new Change[result.size()]); >+ } finally { >+ monitor.done(); >+ } >+ } >+ > public Change postCreateChange(Change[] participantChanges, IProgressMonitor pm) throws CoreException { > if (fQualifiedNameSearchResult != null) { > try { >@@ -1144,7 +1319,10 @@ > SearchMatch match= results[j]; > String oldName= fType.getElementName(); > int offset= match.getOffset() + match.getLength() - oldName.length(); // reference may be qualified >- TextChangeCompatibility.addTextEdit(manager.get(cu), name, new ReplaceEdit(offset, oldName.length(), getNewElementName()), CATEGORY_TYPE_RENAME); >+ if(fIsComposite) >+ TextChangeCompatibility.addTextEdit(manager.get(cu), name, new ReplaceEdit(offset, oldName.length(), getNewElementName()), fCategorySet); >+ else >+ TextChangeCompatibility.addTextEdit(manager.get(cu), name, new ReplaceEdit(offset, oldName.length(), getNewElementName()), CATEGORY_TYPE_RENAME); > } > pm.worked(1); > } >@@ -1228,6 +1406,7 @@ > final Set warnings= new HashSet(); > final List processors= new ArrayList(); > fFinalSimilarElementToName= new HashMap(); >+ fSimilarTypesRenameProcessores= new HashSet(); > > CompilationUnit currentResolvedCU= null; > ICompilationUnit currentCU= null; >@@ -1335,7 +1514,20 @@ > processor= createNonVirtualMethodRenameProcessor(currentMethod, newName); > } > } >- >+ if (element instanceof IType) { >+ final IType currentType= (IType) element; >+ >+ if(!currentType.equals(fType)) { >+ processor= createTypeRenameProcessor(currentType, newName); >+ fSimilarTypesRenameProcessores.add(processor); >+ >+ status.merge(checkForConflictingRename(currentType, newName)); >+ if (status.hasFatalError()) >+ return status; >+ fFinalSimilarElementToName.put(currentType, newName); >+ } >+ } >+ > progressMonitor.subTask(Messages.format(RefactoringCoreMessages.RenameTypeProcessor_progress_current_total, new Object[] { String.valueOf(current), String.valueOf(max)})); > > status.merge(processor.checkInitialConditions(new NoOverrideProgressMonitor(progressMonitor, 1))); >@@ -1485,6 +1677,12 @@ > return status; > } > >+ private RefactoringStatus checkForConflictingRename(IType currentField, String newName) { >+ RefactoringStatus status= new RefactoringStatus(); >+ // XXX check for already existing types necessary here? >+ return status; >+ } >+ > private RefactoringStatus addWarnings(final Set warnings) { > RefactoringStatus status= new RefactoringStatus(); > >@@ -1602,6 +1800,14 @@ > return processor; > } > >+ private RenameTypeProcessor createTypeRenameProcessor(final IType type, final String newName) { >+ final RenameTypeProcessor processor= new RenameTypeProcessor(type, fChangeManager, CATEGORY_TYPE_RENAME); >+ processor.setNewElementName(newName); >+ processor.setUpdateReferences(getUpdateReferences()); >+ processor.setUpdateTextualMatches(false); >+ return processor; >+ } >+ > // ----------- Edit creation ----------- > > >Index: core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenamingNameSuggestor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenamingNameSuggestor.java,v >retrieving revision 1.8 >diff -u -r1.8 RenamingNameSuggestor.java >--- core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenamingNameSuggestor.java 7 Apr 2006 16:51:43 -0000 1.8 >+++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenamingNameSuggestor.java 13 Sep 2006 09:04:42 -0000 >@@ -208,6 +208,25 @@ > return match(oldTypeName, newTypeName, oldMethodName); > } > >+ public String suggestNewTypeName(String typeNameToSuggestNewNameFor, String oldTypeName, String newTypeName) { >+ >+ Assert.isNotNull(typeNameToSuggestNewNameFor); >+ Assert.isNotNull(oldTypeName); >+ Assert.isNotNull(newTypeName); >+ Assert.isTrue(typeNameToSuggestNewNameFor.length() > 0); >+ Assert.isTrue(oldTypeName.length() > 0); >+ Assert.isTrue(newTypeName.length() > 0); >+ >+ resetPrefixes(); >+ >+ if(isInterfaceName(oldTypeName)) >+ oldTypeName = getInterfaceName(oldTypeName); >+ if(isInterfaceName(newTypeName)) >+ newTypeName = getInterfaceName(newTypeName); >+ >+ return matchDirect(oldTypeName, newTypeName, typeNameToSuggestNewNameFor); >+ } >+ > public String suggestNewVariableName(String[] prefixes, String[] suffixes, String oldVariableName, String oldTypeName, String newTypeName) { > > Assert.isNotNull(prefixes); >@@ -489,11 +508,11 @@ > return name.toLowerCase(); > } > >- private boolean isInterfaceName(String typeName) { >+ /*package*/ boolean isInterfaceName(String typeName) { > return ( (typeName.length() >= 2) && typeName.charAt(0) == 'I' && Character.isUpperCase(typeName.charAt(1))); > } > >- private String getInterfaceName(String typeName) { >+ /*package*/ String getInterfaceName(String typeName) { > return typeName.substring(1); > } > >Index: ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameTypeWizardSimilarElementsPage.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameTypeWizardSimilarElementsPage.java,v >retrieving revision 1.6 >diff -u -r1.6 RenameTypeWizardSimilarElementsPage.java >--- ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameTypeWizardSimilarElementsPage.java 7 Apr 2006 16:52:34 -0000 1.6 >+++ ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameTypeWizardSimilarElementsPage.java 13 Sep 2006 09:04:44 -0000 >@@ -168,27 +168,41 @@ > if (name.length() == 0) { > return new StatusInfo(IStatus.ERROR, RefactoringMessages.RenameTypeWizardSimilarElementsPage_name_empty); > } >- IStatus status= JavaConventions.validateIdentifier(name); >- if (status.matches(IStatus.ERROR)) >- return status; >- if (!Checks.startsWithLowerCase(name)) >- return new StatusInfo(IStatus.WARNING, RefactoringMessages.RenameTypeWizardSimilarElementsPage_name_should_start_lowercase); >- >- if (fElementToEdit instanceof IMember && ((IMember) fElementToEdit).getDeclaringType() != null) { >- IType type= ((IMember) fElementToEdit).getDeclaringType(); >- if (fElementToEdit instanceof IField) { >- final IField f= type.getField(name); >- if (f.exists()) >- return new StatusInfo(IStatus.ERROR, RefactoringMessages.RenameTypeWizardSimilarElementsPage_field_exists); >- } >- if (fElementToEdit instanceof IMethod) { >- final IMethod m= type.getMethod(name, ((IMethod) fElementToEdit).getParameterTypes()); >- if (m.exists()) >- return new StatusInfo(IStatus.ERROR, RefactoringMessages.RenameTypeWizardSimilarElementsPage_method_exists); >+ >+ if(fElementToEdit.getElementType() == IJavaElement.TYPE) { >+ >+ // type >+ IStatus status= JavaConventions.validateJavaTypeName(name); >+ if (status.matches(IStatus.ERROR)) >+ return status; >+ if (!Checks.startsWithUpperCase(name)) >+ return new StatusInfo(IStatus.WARNING, RefactoringMessages.RenameTypeWizardSimilarElementsPage_name_should_start_uppercase); >+ >+ } else { >+ >+ // methods, fields, local variables >+ IStatus status= JavaConventions.validateIdentifier(name); >+ if (status.matches(IStatus.ERROR)) >+ return status; >+ if (!Checks.startsWithLowerCase(name)) >+ return new StatusInfo(IStatus.WARNING, RefactoringMessages.RenameTypeWizardSimilarElementsPage_name_should_start_lowercase); >+ >+ if (fElementToEdit instanceof IMember && ((IMember) fElementToEdit).getDeclaringType() != null) { >+ IType type= ((IMember) fElementToEdit).getDeclaringType(); >+ if (fElementToEdit instanceof IField) { >+ final IField f= type.getField(name); >+ if (f.exists()) >+ return new StatusInfo(IStatus.ERROR, RefactoringMessages.RenameTypeWizardSimilarElementsPage_field_exists); >+ } >+ if (fElementToEdit instanceof IMethod) { >+ final IMethod m= type.getMethod(name, ((IMethod) fElementToEdit).getParameterTypes()); >+ if (m.exists()) >+ return new StatusInfo(IStatus.ERROR, RefactoringMessages.RenameTypeWizardSimilarElementsPage_method_exists); >+ } > } >+ >+ // cannot check local variables; no .getLocalVariable(String) in IMember > } >- >- // cannot check local variables; no .getLocalVariable(String) in IMember > > return StatusInfo.OK_STATUS; > } >@@ -264,7 +278,9 @@ > fTopLevelElements= new HashSet(); > for (int i= 0; i < similarElements.length; i++) { > final IType declaring= (IType) similarElements[i].getAncestor(IJavaElement.TYPE); >- if (similarElements[i] instanceof IMember) { >+ if(similarElements[i] instanceof IType && similarElements[i].equals(declaring)) { >+ // top-level type will be handled by handleDeclaring >+ } else if (similarElements[i] instanceof IMember) { > // methods, fields, initializers, inner types > addToMap(declaring, similarElements[i]); > } else {
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 67326
: 50015