diff options
author | nitind | 2007-02-12 21:29:55 +0000 |
---|---|---|
committer | nitind | 2007-02-12 21:29:55 +0000 |
commit | fd1ce52dd8422a3e966d89a33b6227fe7d204b98 (patch) | |
tree | be6c879170256f7c3c6bff6fc8ed7a75cccbd35e /bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename | |
parent | d4ad58329a5584f84e8b8de5995a37da8d3eb3ed (diff) | |
download | webtools.sourceediting-200702122131.tar.gz webtools.sourceediting-200702122131.tar.xz webtools.sourceediting-200702122131.zip |
This commit was manufactured by cvs2svn to create tag 'v200702122131'.v200702122131
Diffstat (limited to 'bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename')
9 files changed, 0 insertions, 1818 deletions
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ComponentRenameArguments.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ComponentRenameArguments.java deleted file mode 100644 index ebdf3d03ec..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ComponentRenameArguments.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.Map; -import org.eclipse.ltk.core.refactoring.participants.RenameArguments; -import org.eclipse.wst.xsd.ui.internal.refactor.TextChangeManager; - -public class ComponentRenameArguments extends RenameArguments { - - TextChangeManager changeManager; - Map matches; - String qualifier; - - public ComponentRenameArguments(String newName, boolean updateReferences) { - super(newName, updateReferences); - } - - public TextChangeManager getChangeManager() { - return changeManager; - } - - public void setChangeManager(TextChangeManager changeManager) { - this.changeManager = changeManager; - } - - public Map getMatches() { - return matches; - } - - public void setMatches(Map matches) { - this.matches = matches; - } - - public String getQualifier() { - return qualifier; - } - - public void setQualifier(String qualifier) { - this.qualifier = qualifier; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameComponentProcessor.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameComponentProcessor.java deleted file mode 100644 index 651082c51b..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameComponentProcessor.java +++ /dev/null @@ -1,501 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -//import com.ibm.icu.text.Collator; -import java.util.ArrayList; -import java.util.Arrays; -//import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.TextChange; -//import org.eclipse.ltk.core.refactoring.TextFileChange; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.ParticipantManager; -import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant; -import org.eclipse.ltk.core.refactoring.participants.RenameArguments; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; -import org.eclipse.ltk.core.refactoring.participants.RenameProcessor; -import org.eclipse.ltk.core.refactoring.participants.SharableParticipants; -import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.wst.common.core.search.SearchEngine; -import org.eclipse.wst.common.core.search.SearchMatch; -import org.eclipse.wst.common.core.search.pattern.QualifiedName; -import org.eclipse.wst.common.core.search.pattern.SearchPattern; -import org.eclipse.wst.common.core.search.scope.SearchScope; -import org.eclipse.wst.common.core.search.scope.SelectionSearchScope; -import org.eclipse.wst.common.core.search.scope.WorkspaceSearchScope; -import org.eclipse.wst.common.core.search.util.CollectingSearchRequestor; -import org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern; -import org.eclipse.wst.xml.core.internal.search.XMLComponentReferencePattern; -import org.eclipse.wst.xsd.ui.internal.refactor.Checks; -import org.eclipse.wst.xsd.ui.internal.refactor.INameUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.IReferenceUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.TextChangeManager; -import org.eclipse.wst.xsd.ui.internal.refactor.util.TextChangeCompatibility; - - - -public class RenameComponentProcessor extends RenameProcessor implements INameUpdating, IReferenceUpdating { - public static final String IDENTIFIER = "org.eclipse.wst.xml.refactor.renameComponentProcessor"; //$NON-NLS-1$ - private boolean singleFileOnly = false; - - public static String quoteString(String value) { - value = value == null ? "" : value; - - StringBuffer sb = new StringBuffer(); - if (!value.startsWith("\"")) { - sb.append("\""); - } - sb.append(value); - if (!value.endsWith("\"")) { - sb.append("\""); - } - return sb.toString(); - } - - private TextChangeManager changeManager; - - private String newName; - - private RefactoringComponent selectedComponent; - - private boolean updateReferences = true; - - private Map references = new HashMap(); - - public RenameComponentProcessor(RefactoringComponent selectedComponent) { - this.selectedComponent = selectedComponent; - } - - public RenameComponentProcessor(RefactoringComponent selectedComponent, String newName) { - this(selectedComponent, newName, false); - } - - public RenameComponentProcessor(RefactoringComponent selectedComponent, String newName, boolean singleFileOnly) { - this.newName = newName; - this.selectedComponent = selectedComponent; - this.singleFileOnly = singleFileOnly; - } - - private void addDeclarationUpdate(TextChangeManager manager) throws CoreException { - String fileStr = selectedComponent.getElement().getModel().getBaseLocation(); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileStr)); - addDeclarationUpdate(manager, file); - } - - final void addDeclarationUpdate(TextChangeManager manager, IFile file) throws CoreException { - - String componentName = selectedComponent.getName(); - String componentNamespace = selectedComponent.getNamespaceURI(); - QualifiedName elementQName = new QualifiedName(componentNamespace, componentName); - QualifiedName typeQName = selectedComponent.getTypeQName(); - - - - SearchScope scope = new WorkspaceSearchScope(); - if (file != null) { - scope = new SelectionSearchScope(new IResource[]{file}); - } - CollectingSearchRequestor requestor = new CollectingSearchRequestor(); - SearchPattern pattern = new XMLComponentDeclarationPattern(file, elementQName, typeQName); - SearchEngine searchEngine = new SearchEngine(); - HashMap map = new HashMap(); - if (singleFileOnly) - { - map.put("searchDirtyContent", Boolean.TRUE); - } - searchEngine.search(pattern, requestor, scope, map, new NullProgressMonitor()); - List results = requestor.getResults(); - for (Iterator iter = results.iterator(); iter.hasNext();) { - SearchMatch match = (SearchMatch) iter.next(); - if (match != null) { - TextChange textChange = manager.get(match.getFile()); - String newName = getNewElementName(); - newName = quoteString(newName); - - ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), match.getLength(), newName); - String editName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_declatation"); - TextChangeCompatibility.addTextEdit(textChange, editName, replaceEdit); - } - } - } - - void addOccurrences(TextChangeManager manager, IProgressMonitor pm, RefactoringStatus status) throws CoreException { - - String fileStr = selectedComponent.getElement().getModel().getBaseLocation(); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileStr)); - - String componentName = selectedComponent.getName(); - String componentNamespace = selectedComponent.getNamespaceURI(); - QualifiedName elementQName = new QualifiedName(componentNamespace, componentName); - QualifiedName typeQName = selectedComponent.getTypeQName(); - - SearchEngine searchEngine = new SearchEngine(); - SearchScope scope = null; - HashMap map = new HashMap(); - if (singleFileOnly) - { - map.put("searchDirtyContent", Boolean.TRUE); - scope = new SelectionSearchScope(new IResource[]{file}); - } - else - { - scope = new WorkspaceSearchScope(); - } - SortingSearchRequestor requestor = new SortingSearchRequestor(); - SearchPattern pattern = new XMLComponentReferencePattern(file, elementQName, typeQName); - - searchEngine.search(pattern, requestor, scope, map, new NullProgressMonitor()); - references = requestor.getResults(); - // for (Iterator iter = references.iterator(); iter.hasNext();) { - // SearchMatch match = (SearchMatch) iter.next(); - - // TextChange textChange = manager.get(match.getFile()); - // String newName = getNewElementName(); - // if(match.getObject() instanceof Node){ - // Node node = (Node)match.getObject(); - // if(node instanceof IDOMAttr){ - // IDOMAttr attr = (IDOMAttr)node; - // IDOMElement element = (IDOMElement)attr.getOwnerElement() ; - // newName = getNewQName(element, componentNamespace, newName); - // } - // newName = quoteString(newName); - // } - // - // ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), - // match.getLength(), newName ); - // String editName = - // RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_reference"); - // TextChangeCompatibility.addTextEdit(textChange, editName, - // replaceEdit); - - // } - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating#canEnableTextUpdating() - */ - public boolean canEnableTextUpdating() { - return true; - } - - public boolean canEnableUpdateReferences() { - return true; - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, - * org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) - */ - public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context) throws CoreException, OperationCanceledException { - Assert.isNotNull(monitor); - Assert.isNotNull(context); - final RefactoringStatus status = new RefactoringStatus(); - try { - monitor.beginTask("", 2); //$NON-NLS-1$ - monitor.setTaskName("RefactoringMessages.RenameComponentRefactoring_checking"); - status.merge(checkNewElementName(getNewElementName())); - monitor.worked(1); - monitor.setTaskName("RefactoringMessages.RenameComponentRefactoring_searching"); - status.merge(createRenameChanges(new SubProgressMonitor(monitor, 1))); - } - finally { - monitor.done(); - } - return status; - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor) - */ - public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { - // TODO add code to check initial conditions for component rename - Assert.isNotNull(pm); - try { - return new RefactoringStatus(); - } - finally { - pm.done(); - } - - } - - public final RefactoringStatus checkNewElementName(final String name) { - Assert.isNotNull(name); - final RefactoringStatus result = Checks.checkName(name); - result.merge(Checks.checkComponentName(name)); - if (Checks.isAlreadyNamed(selectedComponent, name)) - result.addFatalError("RefactoringMessages.RenameComponentRefactoring_another_name"); - return result; - } - - private Object[] computeDerivedElements() { - - Object[] elements = getElements(); - // Object[] results = new Object[elements.length]; - // for(int i=0; i< elements.length; i++){ - // RefactoringComponent component = (RefactoringComponent)elements[i]; - // results[i] = component.getAdaptee(); - // - // } - return elements; - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor) - */ - public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { - // don't create any change now, all the changes are in changeManger - // variable and will be combined in postCreateChange method - return null; - } - - private TextChangeManager updateChangeManager(IProgressMonitor pm, RefactoringStatus status) throws CoreException { - TextChangeManager manager = getChangeManager(); - // only one declaration gets updated - addDeclarationUpdate(manager); - if (getUpdateReferences()) { - addOccurrences(manager, pm, status); - } - return manager; - } - - private RefactoringStatus createRenameChanges(final IProgressMonitor monitor) throws CoreException { - Assert.isNotNull(monitor); - final RefactoringStatus status = new RefactoringStatus(); - try { - monitor.beginTask("RefactoringMessages.RenameComponentRefactoring_searching", 1); - updateChangeManager(new SubProgressMonitor(monitor, 1), status); - } - finally { - monitor.done(); - } - return status; - } - - public TextChangeManager getChangeManager() { - - if (changeManager == null) { - changeManager = new TextChangeManager(false); - } - return changeManager; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xsd.internal.refactoring.rename.XSDRenameProcessor#getAffectedProjectNatures() - */ - protected String[] getAffectedProjectNatures() throws CoreException { - // TODO: find project natures of the files that are going to be - // refactored - return new String[]{"org.eclipse.jdt.core.javanature"}; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating#getCurrentElementName() - */ - public String getCurrentElementName() { - // - return selectedComponent.getName(); - } - - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements() - */ - public Object[] getElements() { - Object model = selectedComponent.getModelObject(); - if (model != null) { - return new Object[]{model}; - } - return new Object[0]; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getIdentifier() - */ - public String getIdentifier() { - return IDENTIFIER; - } - - public String getNewElementName() { - return newName; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getProcessorName() - */ - public String getProcessorName() { - return RefactoringMessages.getFormattedString("RenameComponentRefactoring.name", //$NON-NLS-1$ - new String[]{selectedComponent.getNamespaceURI() + ":" + selectedComponent.getName(), newName}); - - } - - - public boolean getUpdateReferences() { - return updateReferences; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#isApplicable() - */ - public boolean isApplicable() throws CoreException { - if (selectedComponent == null) - return false; - // TODO implement isApplicable logic for the named component, - // verify how it is different from other condition checks - // if (fNamedComponent.isAnonymous()) - // return false; - // if (! Checks.isAvailable(fType)) - // return false; - // if (isSpecialCase(fType)) - // return false; - return true; - } - - protected void loadDerivedParticipants(RefactoringStatus status, List result, Object[] derivedElements, ComponentRenameArguments arguments, String[] natures, SharableParticipants shared) throws CoreException { - if (derivedElements != null) { - for (int i = 0; i < derivedElements.length; i++) { - RenameParticipant[] participants = ParticipantManager.loadRenameParticipants(status, this, derivedElements[i], arguments, natures, shared); - result.addAll(Arrays.asList(participants)); - } - } - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xsd.internal.refactoring.rename.XSDRenameProcessor#loadDerivedParticipants(org.eclipse.ltk.core.refactoring.RefactoringStatus, - * java.util.List, java.lang.String[], - * org.eclipse.ltk.core.refactoring.participants.SharableParticipants) - */ - protected void loadDerivedParticipants(RefactoringStatus status, List result, String[] natures, SharableParticipants shared) throws CoreException { - ComponentRenameArguments arguments = new ComponentRenameArguments(getNewElementName(), getUpdateReferences()); - arguments.setMatches(references); - arguments.setQualifier(selectedComponent.getNamespaceURI()); - // pass in changeManger to the participants so that it can collect all - // changes/per files - arguments.setChangeManager(getChangeManager()); - loadDerivedParticipants(status, result, computeDerivedElements(), arguments, natures, shared); - } - - protected void loadElementParticipants(RefactoringStatus status, List result, RenameArguments arguments, String[] natures, SharableParticipants shared) throws CoreException { - Object[] elements = new Object[0];// getElements(); - for (int i = 0; i < elements.length; i++) { - result.addAll(Arrays.asList(ParticipantManager.loadRenameParticipants(status, this, elements[i], arguments, natures, shared))); - } - } - - - public final RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants sharedParticipants) throws CoreException { - RenameArguments arguments = new RenameArguments(getNewElementName(), getUpdateReferences()); - String[] natures = getAffectedProjectNatures(); - List result = new ArrayList(); - loadElementParticipants(status, result, arguments, natures, sharedParticipants); - loadDerivedParticipants(status, result, natures, sharedParticipants); - for (Iterator i = result.iterator(); i.hasNext();) { - Object o = i.next(); - if (o instanceof XMLComponentRenameParticipant) { - XMLComponentRenameParticipant p = (XMLComponentRenameParticipant) o; - // getChangeManager() - p.setChangeManager(getChangeManager()); - } - } - - return (RefactoringParticipant[]) result.toArray(new RefactoringParticipant[result.size()]); - } - - public void setNewElementName(String newName) { - Assert.isNotNull(newName); - this.newName = newName; - } - - public void setUpdateReferences(boolean update) { - updateReferences = update; - - } - - public Change postCreateChange(Change[] participantChanges, IProgressMonitor pm) throws CoreException, OperationCanceledException { - Assert.isNotNull(pm); - try { - String changeName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_updates"); - TextChange[] changes = changeManager.getAllChanges(); -// Comparator c = new Comparator() { -// public int compare(Object o1, Object o2) { -// TextFileChange c1 = (TextFileChange) o1; -// TextFileChange c2 = (TextFileChange) o2; -// return Collator.getInstance().compare(c1.getFile().getFullPath(), c2.getFile().getFullPath()); -// } -// }; - if (changes.length > 0) { - // Arrays.sort(changes, c); - CompositeChange compositeChange = new CompositeChange("!" + changeName, changes); - compositeChange.markAsSynthetic(); - return compositeChange; - } - else { - return null; - } - - } - finally { - pm.done(); - } - } - - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameResourceProcessor.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameResourceProcessor.java deleted file mode 100644 index 15f0f257b2..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameResourceProcessor.java +++ /dev/null @@ -1,174 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.ParticipantManager; -import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant; -import org.eclipse.ltk.core.refactoring.participants.RenameArguments; -import org.eclipse.ltk.core.refactoring.participants.RenameProcessor; -import org.eclipse.ltk.core.refactoring.participants.SharableParticipants; -import org.eclipse.wst.xsd.ui.internal.refactor.INameUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; - -public class RenameResourceProcessor extends RenameProcessor implements INameUpdating { - - private IResource fResource; - private String fNewElementName; - - public static final String IDENTIFIER= "org.eclipse.wst.ui.xsd.renameResourceProcessor"; //$NON-NLS-1$ - - public RenameResourceProcessor(IResource resource) { - fResource= resource; - if (fResource != null) { - setNewElementName(fResource.getName()); - } - } - - //---- INameUpdating --------------------------------------------------- - - public void setNewElementName(String newName) { - Assert.isNotNull(newName); - fNewElementName= newName; - } - - public String getNewElementName() { - return fNewElementName; - } - - //---- IRenameProcessor methods --------------------------------------- - - public String getIdentifier() { - return IDENTIFIER; - } - - public boolean isApplicable() { - if (fResource == null) - return false; - if (! fResource.exists()) - return false; - if (! fResource.isAccessible()) - return false; - return true; - } - - public String getProcessorName() { - String message= RefactoringMessages.getFormattedString("RenameResourceProcessor.name", //$NON-NLS-1$ - new String[]{getCurrentElementName(), getNewElementName()}); - return message; - } - - public Object[] getElements() { - return new Object[] {fResource}; - } - - public String getCurrentElementName() { - return fResource.getName(); - } - - public String[] getAffectedProjectNatures() throws CoreException { - return new String[0]; - } - - public Object getNewElement() { - - - return ResourcesPlugin.getWorkspace().getRoot().findMember(createNewPath(getNewElementName())); - } - - public boolean getUpdateReferences() { - return true; - } - - public RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants shared) throws CoreException { - Object[] elements= getElements(); - String[] natures= getAffectedProjectNatures(); - List result= new ArrayList(); - RenameArguments arguments= new RenameArguments(getNewElementName(), getUpdateReferences()); - for (int i= 0; i < elements.length; i++) { - result.addAll(Arrays.asList(ParticipantManager.loadRenameParticipants(status, - this, elements[i], - arguments, natures, shared))); - } - return (RefactoringParticipant[])result.toArray(new RefactoringParticipant[result.size()]); - } - - //--- Condition checking -------------------------------------------- - - public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { - return new RefactoringStatus(); - } - - /* non java-doc - * @see IRenameRefactoring#checkNewName() - */ - public RefactoringStatus checkNewElementName(String newName) { - Assert.isNotNull(newName, "new name"); //$NON-NLS-1$ - IContainer c= fResource.getParent(); - if (c == null) - return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.getString("RenameResourceRefactoring.Internal_Error")); //$NON-NLS-1$ - - if (c.findMember(newName) != null) - return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.getString("RenameResourceRefactoring.alread_exists")); //$NON-NLS-1$ - - if (!c.getFullPath().isValidSegment(newName)) - return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.getString("RenameResourceRefactoring.invalidName")); //$NON-NLS-1$ - - RefactoringStatus result= RefactoringStatus.create(c.getWorkspace().validateName(newName, fResource.getType())); - if (! result.hasFatalError()) - result.merge(RefactoringStatus.create(c.getWorkspace().validatePath(createNewPath(newName), fResource.getType()))); - return result; - } - - /* non java-doc - * @see Refactoring#checkInput(IProgressMonitor) - */ - public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) { - pm.beginTask("", 1); //$NON-NLS-1$ - try{ - return new RefactoringStatus(); - } finally{ - pm.done(); - } - } - - private String createNewPath(String newName){ - return fResource.getFullPath().removeLastSegments(1).append(newName).toString(); - } - - //--- changes - - /* non java-doc - * @see IRefactoring#createChange(IProgressMonitor) - */ - public Change createChange(IProgressMonitor pm) { - pm.beginTask("", 1); //$NON-NLS-1$ - try{ - return new ResourceRenameChange(fResource, getNewElementName()); - } finally{ - pm.done(); - } - } -} - diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameTargetNamespaceProcessor.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameTargetNamespaceProcessor.java deleted file mode 100644 index 3d4fa5ce39..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/RenameTargetNamespaceProcessor.java +++ /dev/null @@ -1,419 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.emf.common.util.URI; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.TextChange; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.ParticipantManager; -import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant; -import org.eclipse.ltk.core.refactoring.participants.RenameArguments; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; -import org.eclipse.ltk.core.refactoring.participants.RenameProcessor; -import org.eclipse.ltk.core.refactoring.participants.SharableParticipants; -import org.eclipse.wst.xsd.ui.internal.refactor.INameUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.IReferenceUpdating; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.TextChangeManager; -import org.eclipse.xsd.XSDSchema; - - -public class RenameTargetNamespaceProcessor extends RenameProcessor implements INameUpdating, IReferenceUpdating -{ - private String newNamespace; - private boolean updateReferences = true; - private TextChangeManager changeManager; - private XSDSchema model; - - - public static final String IDENTIFIER = "org.eclipse.wst.ui.xsd.renameComponentProcessor"; //$NON-NLS-1$ - - public RenameTargetNamespaceProcessor(XSDSchema model, String newName) - { - this.model = model; - this.newNamespace = newName; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating#canEnableTextUpdating() - */ - public boolean canEnableTextUpdating() - { - return true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating#getCurrentElementName() - */ - public String getCurrentElementName() - { - // - return model.getTargetNamespace(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xsd.internal.refactoring.rename.XSDRenameProcessor#getAffectedProjectNatures() - */ - protected String[] getAffectedProjectNatures() throws CoreException - { - // TODO: find project natures of the files that are going to be - // refactored - return new String[]{"org.eclipse.jdt.core.javanature"}; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.xsd.internal.refactoring.rename.XSDRenameProcessor#loadDerivedParticipants(org.eclipse.ltk.core.refactoring.RefactoringStatus, - * java.util.List, java.lang.String[], - * org.eclipse.ltk.core.refactoring.participants.SharableParticipants) - */ - protected void loadDerivedParticipants(RefactoringStatus status, - List result, String[] natures, SharableParticipants shared) - throws CoreException - { - String newCUName= getNewElementName(); //$NON-NLS-1$ - RenameArguments arguments= new RenameArguments(newCUName, getUpdateReferences()); - loadDerivedParticipants(status, result, - computeDerivedElements(), arguments, - natures, shared); - } - - protected void loadDerivedParticipants(RefactoringStatus status, List result, Object[] derivedElements, - RenameArguments arguments, String[] natures, SharableParticipants shared) throws CoreException { - if (derivedElements != null) { - for (int i= 0; i < derivedElements.length; i++) { - RenameParticipant[] participants= ParticipantManager.loadRenameParticipants(status, - this, derivedElements[i], - arguments, natures, shared); - result.addAll(Arrays.asList(participants)); - } - } - - } - - private Object[] computeDerivedElements() { - - Object[] elements = getElements(); - Object[] results = new Object[elements.length]; - for(int i=0; i< elements.length; i++){ - RefactoringComponent component = (RefactoringComponent)elements[i]; - results[i] = component.getModelObject(); - - } - return results; - - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, - * org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) - */ - public RefactoringStatus checkFinalConditions(IProgressMonitor pm, - CheckConditionsContext context) throws CoreException, - OperationCanceledException - { - try - { - RefactoringStatus result = new RefactoringStatus(); - pm.beginTask("", 9); //$NON-NLS-1$ - changeManager = createChangeManager(new SubProgressMonitor(pm, 1), - result); - return result; - } finally - { - pm.done(); - } - - - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor) - */ - public RefactoringStatus checkInitialConditions(IProgressMonitor pm) - throws CoreException, OperationCanceledException - { - // TODO add code to check initial conditions for component rename - return new RefactoringStatus(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor) - */ - public Change createChange(IProgressMonitor pm) throws CoreException, - OperationCanceledException - { - try - { - String changeName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_updates"); - return new CompositeChange(changeName, changeManager.getAllChanges()); - } finally - { - pm.done(); - } - - // Change[] changes = ComponentRenameChange.createChangesFor( - // this.fNamedComponent, getNewElementName()); - // - // if (changes.length > 0) - // { - // CompositeChange multiChange = null; - // multiChange = new CompositeChange( - // "XSD component rename participant changes", changes); //$NON-NLS-1$ - // TODO: externalize string - // return multiChange; - // } else - // { - // - // return new ComponentRenameChange( - // fNamedComponent, - // fNamedComponent.getName(), - // getNewElementName(), - // fNamedComponent.getSchema()); - // } - - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements() - */ - public Object[] getElements() - { - return new Object[] { model }; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getIdentifier() - */ - public String getIdentifier() - { - return IDENTIFIER; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getProcessorName() - */ - public String getProcessorName() - { - return RefactoringMessages.getFormattedString( - "RenameComponentRefactoring.name", //$NON-NLS-1$ - new String[] - { - getCurrentElementName(), - getNewElementName() }); - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#isApplicable() - */ - public boolean isApplicable() throws CoreException - { - if (getModel() == null) - return false; - // TODO implement isApplicable logic for the named component, - // verify how it is different from other condition checks - // if (fNamedComponent.isAnonymous()) - // return false; - // if (! Checks.isAvailable(fType)) - // return false; - // if (isSpecialCase(fType)) - // return false; - return true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating#checkNewElementName(java.lang.String) - */ - public RefactoringStatus checkNewElementName(String newName) - { - Assert.isNotNull(newName, "new name"); //$NON-NLS-1$ - // TODO: implement new name checking - // RefactoringStatus result = Checks.checkTypeName(newName); - // if (Checks.isAlreadyNamed(fType, newName)) - // result.addFatalError(RefactoringCoreMessages.getString("RenameTypeRefactoring.choose_another_name")); - // //$NON-NLS-1$ - return new RefactoringStatus(); - } - - public final RefactoringParticipant[] loadParticipants( - RefactoringStatus status, SharableParticipants sharedParticipants) - throws CoreException - { - RenameArguments arguments = new RenameArguments(getNewElementName(), - true); - String[] natures = getAffectedProjectNatures(); - List result = new ArrayList(); - loadElementParticipants(status, result, arguments, natures, - sharedParticipants); - loadDerivedParticipants(status, result, natures, sharedParticipants); - return (RefactoringParticipant[]) result - .toArray(new RefactoringParticipant[result.size()]); - } - - protected void loadElementParticipants(RefactoringStatus status, - List result, RenameArguments arguments, String[] natures, - SharableParticipants shared) throws CoreException - { - Object[] elements = getElements(); - for (int i = 0; i < elements.length; i++) - { - result.addAll(Arrays.asList(ParticipantManager - .loadRenameParticipants(status, this, elements[i], - arguments, natures, shared))); - } - } - - private TextChangeManager createChangeManager(IProgressMonitor pm, - RefactoringStatus status) throws CoreException - { - TextChangeManager manager = new TextChangeManager(false); - // only one declaration gets updated - addDeclarationUpdate(manager); - return manager; - } - - private void addDeclarationUpdate(TextChangeManager manager) - - { - String fileStr = getModel().getSchemaLocation(); - URI uri = URI.createPlatformResourceURI(fileStr); - try - { - URL url = new URL(uri.toString()); - url = Platform.resolve(url); - if(url != null){ - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IFile file = root.getFileForLocation(new Path(url.getFile())); - if(file != null ){ - TextChange change = manager.get(file); - addDeclarationUpdate(change); - } - } - } catch (MalformedURLException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - - } - - - - final void addDeclarationUpdate(TextChange change) - { -// String editName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_declatation");; -// -// NamedComponentRenamer renamer = new NamedComponentRenamer( -// selectedComponent.getElement(), newNamespace); -// renamer.renameComponent(); -// List textEdits = renamer.getTextEdits(); -// for (int j = 0; j < textEdits.size(); j++) -// { -// ReplaceEdit replaceEdit = (ReplaceEdit) textEdits -// .get(j); -// TextChangeCompatibility.addTextEdit(change, -// editName, replaceEdit); -// } - } - - public void setNewElementName(String newName) - { - this.newNamespace = newName; - } - - public String getNewElementName() - { - return newNamespace; - } - - - - public boolean canEnableUpdateReferences() - { - return true; - } - - public boolean getUpdateReferences() - { - return updateReferences; - } - - public void setUpdateReferences(boolean update) - { - updateReferences = update; - - } - - public final TextChangeManager getChangeManager() - { - return changeManager; - } - - public final XSDSchema getModel() - { - return model; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameChange.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameChange.java deleted file mode 100644 index a0e528fb99..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameChange.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; - -/** - * Represents a change that renames a given resource - */ -public class ResourceRenameChange extends Change { - - /* - * we cannot use handles because they became invalid when you rename the resource. - * paths do not. - */ - private IPath fResourcePath; - - private String fNewName; - - /** - * @param newName includes the extension - */ - public ResourceRenameChange(IResource resource, String newName) { - this(resource.getFullPath(), newName); - } - - private ResourceRenameChange(IPath resourcePath, String newName) { - fResourcePath= resourcePath; - fNewName= newName; - } - - private IResource getResource() { - return ResourcesPlugin.getWorkspace().getRoot().findMember(fResourcePath); - } - - public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { - - // TODO: implement file validation, see JDTChange - return new RefactoringStatus(); - } - - /* - * to avoid the exception senders should check if a resource with the new name - * already exists - */ - public Change perform(IProgressMonitor pm) throws CoreException { - try { - if (false) - throw new NullPointerException(); - pm.beginTask(RefactoringMessages.getString("XSDRenameResourceChange.rename_resource"), 1); //$NON-NLS-1$ - - getResource().move(renamedResourcePath(fResourcePath, fNewName), getCoreRenameFlags(), pm); - - String oldName= fResourcePath.lastSegment(); - IPath newPath= renamedResourcePath(fResourcePath, fNewName); - return new ResourceRenameChange(newPath, oldName); - } finally { - pm.done(); - } - } - - private int getCoreRenameFlags() { - if (getResource().isLinked()) - return IResource.SHALLOW; - else - return IResource.NONE; - } - - /* - * changes resource names /s/p/A.java renamed to B.java becomes /s/p/B.java - */ - public static IPath renamedResourcePath(IPath path, String newName) { - return path.removeLastSegments(1).append(newName); - } - - public String getName() { - return RefactoringMessages.getFormattedString( - "XSDRenameResourceChange.name", new String[]{fResourcePath.toString(), //$NON-NLS-1$ - renamedResourcePath(fResourcePath, fNewName).toString()}); - } - - public Object getModifiedElement() { - return getResource(); - } - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.eclipse.core.runtime.IProgressMonitor) - */ - public void initializeValidationData(IProgressMonitor pm) { - // TODO Auto-generated method stub - - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameParticipant.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameParticipant.java deleted file mode 100644 index af6077dd6e..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/ResourceRenameParticipant.java +++ /dev/null @@ -1,296 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.core.runtime.content.IContentDescription; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.TextChange; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.TextChangeManager; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDSchema; - -/** - * This rename participant creates text changes for the references of the XSD and WSDL files - */ -public class ResourceRenameParticipant extends RenameParticipant { - -// private IFile file = null; - private TextChangeManager changeManager; - - - private static String XSD_CONTENT_TYPE_ID = "org.eclipse.wst.xsd.core.xsdsource"; - private static String WSDL_CONTENT_TYPE_ID = "org.eclipse.wst.wsdl.wsdlsource"; - - - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object) - */ - protected boolean initialize(Object element) { - if(element instanceof IFile) { - // check if file has XSD or WSDL content - IFile aFile = (IFile) element; - try { - IContentDescription description = aFile.getContentDescription(); - if ( description == null ) - return false; - IContentType contentType = description.getContentType(); - if(contentType != null){ - if(XSD_CONTENT_TYPE_ID.equals(contentType.getId()) || - WSDL_CONTENT_TYPE_ID.equals(contentType.getId())){ -// file = aFile; - return true; - } - } - } catch (CoreException e) { - return false; - } - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName() - */ - public String getName() { - return RefactoringMessages.getString("ResourceRenameParticipant.compositeChangeName"); - } - -// private IPath getNewFilePath() { -// -// IPath oldPath = file.getRawLocation(); -// IPath newPath = oldPath.removeLastSegments(1).append(getArguments().getNewName()); -// return newPath; -// } - - public RefactoringStatus checkConditions(IProgressMonitor pm, - CheckConditionsContext context) throws OperationCanceledException - { - RefactoringStatus result = new RefactoringStatus(); - try - { - pm.beginTask("", 9); //$NON-NLS-1$ - changeManager = createChangeManager(new SubProgressMonitor(pm, 1), - result); - - } catch(CoreException e){ - result.addFatalError(e.toString()); - } - finally - { - pm.done(); - } - return result; - - } - - - - public Change createChange(IProgressMonitor pm) throws CoreException, - OperationCanceledException - { - try - { - String changeName = RefactoringMessages.getString("RenameResourceChange.rename_resource_reference_change"); - TextChange[] changes = changeManager.getAllChanges(); - if(changes.length > 0){ - return new CompositeChange(changeName, changes); - } - else{ - return null; - } - - } finally - { - pm.done(); - } - - } - - - private TextChangeManager createChangeManager(IProgressMonitor pm, - RefactoringStatus status) throws CoreException - { - TextChangeManager manager = new TextChangeManager(false); - // only one declaration gets updated - //addDeclarationUpdate(manager); - if (getArguments().getUpdateReferences()) - addOccurrences(manager, pm, status); - return manager; - } - - - - void addOccurrences(TextChangeManager manager, IProgressMonitor pm, - RefactoringStatus status) throws CoreException - { -// -// Object[] occurrences = SearchTools.getFileDependencies(file); -// pm.beginTask("", occurrences.length); //$NON-NLS-1$ -// -// for (int i = 0; i < occurrences.length; i++) -// { -// Object object = occurrences[i]; -// -// if (object instanceof SearchResultGroup) -// { -// SearchResultGroup searchResult = (SearchResultGroup) object; -// if (searchResult == null) -// continue; -// -// IFile referencingFile = (IFile)searchResult.getResource(); -// -// resourceSet = new ResourceSetImpl(); -// // for each result file create XSD model and get component from that model -// resourceSet.getAdapterFactories().add( -// new XSDSchemaLocationResolverAdapterFactory()); -// URI uri = URI.createFileURI(referencingFile.getLocation().toPortableString()); -// try -// { -// XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema(); -// IStructuredModel structuredModel = StructuredModelManager.getModelManager().getModelForRead(referencingFile); -// IDOMModel domModel = (IDOMModel) structuredModel; -// Resource resource = new XSDResourceImpl(); -// resource.setURI(uri); -// schema = XSDFactory.eINSTANCE.createXSDSchema(); -// resource.getContents().add(schema); -// resourceSet.getResources().add(resource); -// schema.setElement(domModel.getDocument().getDocumentElement()); -// // get target namespace -// String stringPath = file.getLocation().toString(); -// String targetNamespace = XMLQuickScan.getTargetNamespace(stringPath); -// targetNamespace = targetNamespace == null ? "" : targetNamespace; -// -// List textEdits = new ArrayList(); -// SearchMatch[] matches = searchResult.getSearchResults(); -// -// for (int j = 0; j < matches.length; j++) { -// SearchMatch match = matches[j]; -// -// FileReferenceRenamer renamer = new FileReferenceRenamer( -// match.getAttrValue(), targetNamespace, getNewFilePath().toString(), schema); -// renamer.visitSchema(schema); -// textEdits.addAll(renamer.getTextEdits()); -// } -// -// -// if(!textEdits.isEmpty()){ -// TextChange textChange = manager.get(referencingFile); -// for (int j = 0; j < textEdits.size(); j++) -// { -// ReplaceEdit replaceEdit = (ReplaceEdit) textEdits -// .get(j); -// String editName = RefactoringMessages.getString("ResourceRenameParticipant.File_Rename_update_reference"); -// TextChangeCompatibility.addTextEdit(textChange, -// editName, replaceEdit); -// } -// } -// -// } catch (Exception e) -// { -// e.printStackTrace(); -// } finally -// { -// -// } -// } -// } - } - - - public class ReferenceLocationFinder - { - protected XSDNamedComponent component; - protected String name; - protected XSDSchema referencingSchema; - protected List results = new ArrayList(); - - public ReferenceLocationFinder(XSDNamedComponent component, - String name, XSDSchema referencingSchema) - { - this.component = component; - this.name = name; - this.referencingSchema = referencingSchema; - } - - public void run() - { - - //XSDSwitch xsdSwitch = new XSDSwitch() -// { -// public Object caseXSDTypeDefinition(XSDTypeDefinition object) -// { -// GlobalTypeReferenceRenamer renamer = new GlobalTypeReferenceRenamer( -// object.getName(), object.getTargetNamespace(), name, referencingSchema); -// renamer.visitSchema(referencingSchema); -// results.addAll(renamer.getTextEdits()); -// return null; -// } -// -// public Object caseXSDElementDeclaration( -// XSDElementDeclaration object) -// { -// if (object.isGlobal()) -// { -// GlobalElementRenamer renamer = new GlobalElementRenamer( -// object.getName(), object.getTargetNamespace(), name, referencingSchema); -// renamer.visitSchema(referencingSchema); -// results.addAll(renamer.getTextEdits()); -// } -// return null; -// } -// -// public Object caseXSDModelGroupDefinition( -// XSDModelGroupDefinition object) -// { -// GlobalGroupRenamer renamer = new GlobalGroupRenamer( -// object.getName(), object.getTargetNamespace(), name, referencingSchema); -// renamer.visitSchema(referencingSchema); -// return null; -// } -// }; - //xsdSwitch.doSwitch(component); -// component.setName(name); -// try -// { -// referencingSchema.eResource().save(new HashMap()); -// } catch (IOException e) -// { -// e.printStackTrace(); -// } - - } - - public final List getResults() - { - return results; - } - } - - - - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/SortingSearchRequestor.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/SortingSearchRequestor.java deleted file mode 100644 index d140a8c9e5..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/SortingSearchRequestor.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.wst.common.core.search.SearchMatch; -import org.eclipse.wst.common.core.search.SearchRequestor; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class SortingSearchRequestor extends SearchRequestor { - - public static String NONAMESPACE = "nonamespace"; - - - private Map fFound; - - public SortingSearchRequestor() { - fFound= new HashMap(); - } - - - - /** - * @return a List of {@link SearchMatch}es (sorted by namespace) - */ - public Map/* namespace - <SearchMatch>*/ getResults() { - return fFound; - } - - - - /* (non-Javadoc) - * @see org.eclipse.wst.common.core.search.internal.provisional.SearchRequestor#acceptSearchMatch(org.eclipse.wst.common.search.internal.provisional.SearchMatch) - */ - public void acceptSearchMatch(SearchMatch match) throws CoreException { - - - if(match != null && match.getObject() instanceof Node){ - Node node = (Node)match.getObject(); - Element domElement = null; - switch (node.getNodeType()) { - case Node.ATTRIBUTE_NODE: - domElement = ((Attr)node).getOwnerElement(); - break; - case Node.ELEMENT_NODE: - domElement = ((Element)node); - break; - default: - break; - } - String namespace = domElement.getNamespaceURI(); - if(namespace == null || namespace.equals("")){ - namespace = NONAMESPACE; - } - List matches = getMatches(namespace); - matches.add(match); - } - - } - - private List getMatches(String namespace){ - Object matches = fFound.get(namespace); - if(!(matches instanceof List)){ - matches = new ArrayList(); - fFound.put(namespace, matches); - } - return (List)matches; - - } - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XMLComponentRenameParticipant.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XMLComponentRenameParticipant.java deleted file mode 100644 index 4aba3206ff..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XMLComponentRenameParticipant.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.Iterator; -import java.util.List; - -//import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -//import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.TextChange; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; -import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.wst.common.core.search.SearchMatch; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages; -import org.eclipse.wst.xsd.ui.internal.refactor.TextChangeManager; -import org.eclipse.wst.xsd.ui.internal.refactor.util.TextChangeCompatibility; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Node; - -public class XMLComponentRenameParticipant extends RenameParticipant { - - protected SearchMatch match; - - protected TextChangeManager changeManager; - protected List matches; - - - - protected boolean initialize(Object element) { - - if(getArguments() instanceof ComponentRenameArguments){ - // changeManger is passed in from the RenameComponentProcessor to collect all the changes - changeManager = ((ComponentRenameArguments)getArguments()).getChangeManager(); - } - - return false; - } - - public String getName() { - return "XML Component Rename Participant"; - } - - public RefactoringStatus checkConditions(IProgressMonitor monitor, - CheckConditionsContext context) throws OperationCanceledException { - return null; - } - - public TextChangeManager getChangeManager(){ - - if(changeManager == null){ - changeManager = new TextChangeManager(false); - } - return changeManager; - - } - -// private RefactoringStatus createRenameChanges(final IProgressMonitor monitor) throws CoreException { -// Assert.isNotNull(monitor); -// final RefactoringStatus status= new RefactoringStatus(); -// try { -// monitor.beginTask("RefactoringMessages.RenameComponentRefactoring_searching", 1); -// createRenameChanges(new SubProgressMonitor(monitor, 1)); -// //updateChangeManager(new SubProgressMonitor(monitor, 1), status); -// } finally { -// monitor.done(); -// } -// return status; -// } - - public Change createChange(IProgressMonitor pm) throws CoreException, - OperationCanceledException { - for (Iterator iter = matches.iterator(); iter.hasNext();) { - SearchMatch match = (SearchMatch) iter.next(); - TextChange textChange = getChangeManager().get(match.getFile()); - String newName = getArguments().getNewName(); - String qualifier = ""; - if(getArguments() instanceof ComponentRenameArguments){ - qualifier = ((ComponentRenameArguments)getArguments()).getQualifier(); - } - if(match.getObject() instanceof Node){ - Node node = (Node)match.getObject(); - if(node instanceof IDOMAttr){ - IDOMAttr attr = (IDOMAttr)node; - IDOMElement element = (IDOMElement)attr.getOwnerElement() ; - newName = getNewQName(element, qualifier, newName); - } - newName = RenameComponentProcessor.quoteString(newName); - } - - ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), match.getLength(), newName ); - String editName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_reference"); - TextChangeCompatibility.addTextEdit(textChange, editName, replaceEdit); - } - // don't create any change now, all the changes are in changeManger variable and will be combined in RenameComponentProcessor.postCreateChange method - return null; - } - - private static String getNewQName(Node node, String targetNamespace, String newName) { - StringBuffer sb = new StringBuffer(); - if (newName != null) { - String prefix = XSDConstants.lookupQualifier(node, targetNamespace); - if (prefix != null && prefix.length() > 0) { - sb.append(prefix); - sb.append(":"); - sb.append(newName); - } else { - sb.append(newName); - } - } else { - sb.append(newName); - } - - return sb.toString(); - } - - public void setChangeManager(TextChangeManager changeManager) - { - this.changeManager = changeManager; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XSDComponentRenameParticipant.java b/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XSDComponentRenameParticipant.java deleted file mode 100644 index 3d169fdd79..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-refactor/org/eclipse/wst/xsd/ui/internal/refactor/rename/XSDComponentRenameParticipant.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.refactor.rename; - -import java.util.List; -import org.eclipse.wst.xsd.ui.internal.search.IXSDSearchConstants; -import org.eclipse.xsd.XSDNamedComponent; - -/** - * This participant takes case of renaming matches that are XSD components - */ -public class XSDComponentRenameParticipant extends XMLComponentRenameParticipant { - -protected boolean initialize(Object element) { - super.initialize(element); - if(element instanceof XSDNamedComponent){ - if(getArguments() instanceof ComponentRenameArguments){ - matches = (List)((ComponentRenameArguments)getArguments()).getMatches().get(IXSDSearchConstants.XMLSCHEMA_NAMESPACE); - } - if(matches != null){ - return true; - } - } - return false; - } - - public String getName() { - - return "XSD component rename participant"; - } - - - -} |