diff options
author | Thomas Schindl | 2011-03-30 20:56:45 +0000 |
---|---|---|
committer | Thomas Schindl | 2011-03-30 20:56:45 +0000 |
commit | ac3f35c8f140caf1afc28d1cee514300ed5791c2 (patch) | |
tree | 3ea4137528bdd31db35a7b1fda9d6dd84aec608f /bundles | |
parent | 44c11efd69959c116093fa872fe22a15ca17b0ef (diff) | |
download | org.eclipse.e4.tools-ac3f35c8f140caf1afc28d1cee514300ed5791c2.tar.gz org.eclipse.e4.tools-ac3f35c8f140caf1afc28d1cee514300ed5791c2.tar.xz org.eclipse.e4.tools-ac3f35c8f140caf1afc28d1cee514300ed5791c2.zip |
Bug 320380 - [ModelTooling] Integration in Renaming Operations
Diffstat (limited to 'bundles')
4 files changed, 156 insertions, 53 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml b/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml index ac5ff768..f47fd93e 100644 --- a/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml +++ b/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml @@ -41,7 +41,7 @@ <enablement> <with variable="affectedNatures"> <iterate operator="or"> - <equals value="org.eclipse.jdt.core.javanature"/> + <equals value="org.eclipse.pde.PluginNature"/> </iterate> </with> <with variable="element"> @@ -50,5 +50,23 @@ </enablement> </renameParticipant> </extension> + <extension + point="org.eclipse.ltk.core.refactoring.moveParticipants"> + <moveParticipant + class="org.eclipse.e4.tools.emf.editor3x.ClassMoveParticipant" + id="org.eclipse.e4.tools.emf.editor3x.moveParticipant" + name="Workbench Model Contribution Participant"> + <enablement> + <with variable="affectedNatures"> + <iterate operator="or"> + <equals value="org.eclipse.pde.PluginNature"/> + </iterate> + </with> + <with variable="element"> + <instanceof value="org.eclipse.jdt.core.IType"/> + </with> + </enablement> + </moveParticipant> + </extension> </plugin> diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ClassMoveParticipant.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ClassMoveParticipant.java new file mode 100644 index 00000000..0c883aa0 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ClassMoveParticipant.java @@ -0,0 +1,52 @@ +package org.eclipse.e4.tools.emf.editor3x; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.e4.tools.emf.editor3x.extension.Util; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IType; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; + +public class ClassMoveParticipant extends + org.eclipse.ltk.core.refactoring.participants.MoveParticipant { + private IType type; + + @Override + protected boolean initialize(Object element) { + if( element instanceof IType ) { + type = (IType) element; + } else { + type = null; + } + + return type != null; + } + + @Override + public String getName() { + return "Workbench Model Contribution Participant"; + } + + @Override + public RefactoringStatus checkConditions(IProgressMonitor pm, + CheckConditionsContext context) throws OperationCanceledException { + return new RefactoringStatus(); + } + + @Override + public Change createChange(IProgressMonitor pm) throws CoreException, + OperationCanceledException { + String fromBundle = Util.getBundleSymbolicName(type.getJavaProject().getProject()); + String fromClassname = type.getFullyQualifiedName(); + + IPackageFragment fragment = (IPackageFragment) getArguments().getDestination(); + String toBundle = Util.getBundleSymbolicName(fragment.getJavaProject().getProject()); + String toClassName = fragment.getElementName().length() == 0 ? type.getElementName() : fragment.getElementName() + "." + type.getElementName(); + + return RefactorParticipantDelegate.createChange(pm, this, "platform:/plugin/"+fromBundle+"/"+fromClassname, "platform:/plugin/"+toBundle+"/"+toClassName); + } + +} diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ClassRenameParticipant.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ClassRenameParticipant.java index 43275b1d..75471091 100644 --- a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ClassRenameParticipant.java +++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/ClassRenameParticipant.java @@ -10,28 +10,14 @@ ******************************************************************************/ package org.eclipse.e4.tools.emf.editor3x; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Pattern; - -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.e4.tools.emf.editor3x.extension.Util; import org.eclipse.jdt.core.IType; 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.search.core.text.TextSearchEngine; -import org.eclipse.search.core.text.TextSearchMatchAccess; -import org.eclipse.search.core.text.TextSearchRequestor; -import org.eclipse.search.ui.text.FileTextSearchScope; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.text.edits.TextEditGroup; public class ClassRenameParticipant extends org.eclipse.ltk.core.refactoring.participants.RenameParticipant { @@ -62,44 +48,11 @@ public class ClassRenameParticipant extends @Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { - final Map<IFile, TextFileChange> changes= new HashMap<IFile, TextFileChange>(); - final String newName = type.getPackageFragment().getElementName().length() == 0 ? getArguments().getNewName() : type.getPackageFragment().getElementName() + "." + getArguments().getNewName(); - String oldName = type.getFullyQualifiedName().replace(".", "\\."); - - String[] filenames = { "*.e4xmi" }; - FileTextSearchScope scope= FileTextSearchScope.newWorkspaceScope(filenames, false); - Pattern pattern= Pattern.compile(oldName); - - TextSearchRequestor searchRequestor = new TextSearchRequestor() { - public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) throws CoreException { - IFile file = matchAccess.getFile(); - TextFileChange change= (TextFileChange) changes.get(file); - - if (change == null) { - TextChange textChange = getTextChange(file); - if (textChange != null) { - return false; - } - change= new TextFileChange(file.getName(), file); - change.setEdit(new MultiTextEdit()); - changes.put(file, change); - } - ReplaceEdit edit= new ReplaceEdit(matchAccess.getMatchOffset(), matchAccess.getMatchLength(), newName); - change.addEdit(edit); - change.addTextEditGroup(new TextEditGroup("Update contribution reference", edit)); //$NON-NLS-1$ - return true; - } - }; - TextSearchEngine.create().search(scope, searchRequestor, pattern, pm); + String bundle = Util.getBundleSymbolicName(type.getJavaProject().getProject()); - if (changes.isEmpty()) - return null; - - CompositeChange result= new CompositeChange("Update contribution reference"); //$NON-NLS-1$ - for (TextFileChange c : changes.values()) { - result.add(c); - } - return result; + final String newUrl = "platform:/plugin/" + bundle + "/" + (type.getPackageFragment().getElementName().length() == 0 ? getArguments().getNewName() : type.getPackageFragment().getElementName() + "." + getArguments().getNewName()); + String oldUrl = "platform:/plugin/" + bundle + "/" + type.getFullyQualifiedName().replace(".", "\\."); + return RefactorParticipantDelegate.createChange(pm, this, oldUrl, newUrl); } } diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/RefactorParticipantDelegate.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/RefactorParticipantDelegate.java new file mode 100644 index 00000000..0ba52ad1 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/RefactorParticipantDelegate.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2011 BestSolution.at 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: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.tools.emf.editor3x; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + +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.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.CompositeChange; +import org.eclipse.ltk.core.refactoring.TextChange; +import org.eclipse.ltk.core.refactoring.TextFileChange; +import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant; +import org.eclipse.search.core.text.TextSearchEngine; +import org.eclipse.search.core.text.TextSearchMatchAccess; +import org.eclipse.search.core.text.TextSearchRequestor; +import org.eclipse.search.ui.text.FileTextSearchScope; +import org.eclipse.text.edits.MultiTextEdit; +import org.eclipse.text.edits.ReplaceEdit; +import org.eclipse.text.edits.TextEditGroup; + +class RefactorParticipantDelegate { + public static Change createChange(IProgressMonitor pm, + final RefactoringParticipant p, String oldUrl, final String newUrl) + throws CoreException, OperationCanceledException { + String[] filenames = { "*.e4xmi" }; + FileTextSearchScope scope = FileTextSearchScope.newWorkspaceScope( + filenames, false); + Pattern pattern = Pattern.compile(oldUrl); + + final Map<IFile, TextFileChange> changes = new HashMap<IFile, TextFileChange>(); + TextSearchRequestor searchRequestor = new TextSearchRequestor() { + public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) + throws CoreException { + IFile file = matchAccess.getFile(); + TextFileChange change = (TextFileChange) changes.get(file); + + if (change == null) { + TextChange textChange = p.getTextChange(file); + if (textChange != null) { + return false; + } + change = new TextFileChange(file.getName(), file); + change.setEdit(new MultiTextEdit()); + changes.put(file, change); + } + ReplaceEdit edit = new ReplaceEdit( + matchAccess.getMatchOffset(), + matchAccess.getMatchLength(), newUrl); + change.addEdit(edit); + change.addTextEditGroup(new TextEditGroup( + "Update contribution reference", edit)); //$NON-NLS-1$ + return true; + } + }; + TextSearchEngine.create().search(scope, searchRequestor, pattern, pm); + + if (changes.isEmpty()) + return null; + + CompositeChange result = new CompositeChange( + "Update contribution reference"); //$NON-NLS-1$ + for (TextFileChange c : changes.values()) { + result.add(c); + } + return result; + } +} |