]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/JavaRenameProcessor.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / core refactoring / org / eclipse / jdt / internal / corext / refactoring / rename / JavaRenameProcessor.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 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.INameUpdating;
30
31 import org.eclipse.jdt.ui.refactoring.RefactoringSaveHelper;
32
33
34 public abstract class JavaRenameProcessor extends RenameProcessor implements INameUpdating {
35
36         private String fNewElementName;
37         private RenameModifications fRenameModifications;
38
39         @Override
40         public final RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants shared) throws CoreException {
41                 return fRenameModifications.loadParticipants(status, this, getAffectedProjectNatures(), shared);
42         }
43
44         @Override
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                 fRenameModifications= computeRenameModifications();
56                 fRenameModifications.buildDelta(deltaFactory);
57                 fRenameModifications.buildValidateEdits((ValidateEditChecker)context.getChecker(ValidateEditChecker.class));
58                 return result;
59         }
60
61         protected abstract RenameModifications computeRenameModifications() throws CoreException;
62
63         protected abstract RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException, OperationCanceledException;
64
65         protected abstract IFile[] getChangedFiles() throws CoreException;
66
67         protected abstract String[] getAffectedProjectNatures() throws CoreException;
68
69         public void setNewElementName(String newName) {
70                 Assert.isNotNull(newName);
71                 fNewElementName= newName;
72         }
73
74         public String getNewElementName() {
75                 return fNewElementName;
76         }
77
78         /**
79          * @return a save mode from {@link RefactoringSaveHelper}
80          *
81          * @see RefactoringSaveHelper
82          */
83         public abstract int getSaveMode();
84
85 }