01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso.refactoring;
05:
06: import org.apache.commons.lang.StringUtils;
07: import org.eclipse.core.resources.IProject;
08: import org.eclipse.core.resources.IWorkspace;
09: import org.eclipse.core.resources.ResourcesPlugin;
10: import org.eclipse.core.runtime.IProgressMonitor;
11: import org.eclipse.core.runtime.OperationCanceledException;
12: import org.eclipse.jdt.core.IJavaElement;
13: import org.eclipse.jdt.core.IMethod;
14: import org.eclipse.ltk.core.refactoring.Change;
15: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
16:
17: import org.terracotta.dso.PatternHelper;
18: import org.terracotta.dso.TcPlugin;
19:
20: public class RenameMethodChange extends Change {
21: private String fOldMethodName;
22: private String fNewMethodName;
23: private String fProjectName;
24:
25: public RenameMethodChange(IMethod method, String newMethodName) {
26: fOldMethodName = PatternHelper.getFullName(method);
27: fNewMethodName = StringUtils.replace(fOldMethodName, method
28: .getElementName(), newMethodName);
29: fProjectName = method.getAncestor(IJavaElement.JAVA_PROJECT)
30: .getElementName();
31: }
32:
33: public RenameMethodChange(String oldMethodName,
34: String newMethodName, String projectName) {
35: fNewMethodName = newMethodName;
36: fOldMethodName = oldMethodName;
37: fProjectName = projectName;
38: }
39:
40: public Object getModifiedElement() {
41: return null;
42: }
43:
44: public String getName() {
45: return "TCRenameMethodConfigUpdate";
46: }
47:
48: public void initializeValidationData(IProgressMonitor pm) {/**/
49: }
50:
51: public RefactoringStatus isValid(IProgressMonitor pm)
52: throws OperationCanceledException {
53: return new RefactoringStatus();
54: }
55:
56: public Change perform(IProgressMonitor pm) {
57: IWorkspace workspace = ResourcesPlugin.getWorkspace();
58: IProject project = workspace.getRoot().getProject(fProjectName);
59:
60: TcPlugin.getDefault().replaceConfigText(project,
61: fOldMethodName, fNewMethodName);
62:
63: // create the undo change
64: return new RenameMethodChange(fNewMethodName, fOldMethodName,
65: fProjectName);
66: }
67: }
|