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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.corext.refactoring.rename;
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;
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
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;
29 import org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating;
31 import org.eclipse.jdt.ui.refactoring.RefactoringSaveHelper;
34 public abstract class JavaRenameProcessor extends RenameProcessor implements INameUpdating {
36 private String fNewElementName;
37 private RenameModifications fRenameModifications;
40 public final RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants shared) throws CoreException {
41 return fRenameModifications.loadParticipants(status, this, getAffectedProjectNatures(), shared);
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())
51 IFile[] changed= getChangedFiles();
52 for (int i= 0; i < changed.length; i++) {
53 deltaFactory.change(changed[i]);
55 fRenameModifications= computeRenameModifications();
56 fRenameModifications.buildDelta(deltaFactory);
57 fRenameModifications.buildValidateEdits((ValidateEditChecker)context.getChecker(ValidateEditChecker.class));
61 protected abstract RenameModifications computeRenameModifications() throws CoreException;
63 protected abstract RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException, OperationCanceledException;
65 protected abstract IFile[] getChangedFiles() throws CoreException;
67 protected abstract String[] getAffectedProjectNatures() throws CoreException;
69 public void setNewElementName(String newName) {
70 Assert.isNotNull(newName);
71 fNewElementName= newName;
74 public String getNewElementName() {
75 return fNewElementName;
79 * @return a save mode from {@link RefactoringSaveHelper}
81 * @see RefactoringSaveHelper
83 public abstract int getSaveMode();