KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > rename > JavaRenameProcessor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.refactoring.rename;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.OperationCanceledException;
17
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
20
21 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
22 import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
23 import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
24 import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
25 import org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker;
26 import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
27 import org.eclipse.ltk.core.refactoring.participants.ValidateEditChecker;
28
29 import org.eclipse.jdt.internal.corext.refactoring.tagging.ICommentProvider;
30 import org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating;
31 import org.eclipse.jdt.internal.corext.refactoring.tagging.IScriptableRefactoring;
32
33 import org.eclipse.jdt.internal.ui.refactoring.RefactoringSaveHelper;
34
35 public abstract class JavaRenameProcessor extends RenameProcessor implements IScriptableRefactoring, INameUpdating, ICommentProvider {
36     
37     private String JavaDoc fNewElementName;
38     private String JavaDoc fComment;
39     private RenameModifications fRenameModifications;
40     
41     public final RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants shared) throws CoreException {
42         return getRenameModifications().loadParticipants(status, this, getAffectedProjectNatures(), shared);
43     }
44     
45     public final RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException, OperationCanceledException {
46         ResourceChangeChecker checker= (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
47         IResourceChangeDescriptionFactory deltaFactory= checker.getDeltaFactory();
48         RefactoringStatus result= doCheckFinalConditions(pm, context);
49         if (result.hasFatalError())
50             return result;
51         IFile[] changed= getChangedFiles();
52         for (int i= 0; i < changed.length; i++) {
53             deltaFactory.change(changed[i]);
54         }
55         RenameModifications renameModifications= getRenameModifications();
56         renameModifications.buildDelta(deltaFactory);
57         renameModifications.buildValidateEdits((ValidateEditChecker)context.getChecker(ValidateEditChecker.class));
58         return result;
59     }
60     
61     private RenameModifications getRenameModifications() throws CoreException {
62         if (fRenameModifications == null)
63             fRenameModifications= computeRenameModifications();
64         return fRenameModifications;
65     }
66     
67     protected abstract RenameModifications computeRenameModifications() throws CoreException;
68     
69     protected abstract RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException, OperationCanceledException;
70     
71     protected abstract IFile[] getChangedFiles() throws CoreException;
72
73     protected abstract String JavaDoc[] getAffectedProjectNatures() throws CoreException;
74
75     public void setNewElementName(String JavaDoc newName) {
76         Assert.isNotNull(newName);
77         fNewElementName= newName;
78     }
79
80     public String JavaDoc getNewElementName() {
81         return fNewElementName;
82     }
83     
84     /**
85      * @return a save mode from {@link RefactoringSaveHelper}
86      *
87      * @see RefactoringSaveHelper
88      */

89     public abstract int getSaveMode();
90
91     public final boolean canEnableComment() {
92         return true;
93     }
94
95     public final String JavaDoc getComment() {
96         return fComment;
97     }
98
99     public final void setComment(String JavaDoc comment) {
100         fComment= comment;
101     }
102 }
103
Popular Tags