1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
13 import net.sourceforge.phpdt.core.ICompilationUnit;
14 import net.sourceforge.phpdt.core.IJavaElement;
15 import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
16 import net.sourceforge.phpdt.core.JavaModelException;
19 * This operation renames resources (Package fragments and compilation units).
22 * <li>When a compilation unit is renamed, its main type and the constructors of the
23 * main type are renamed.
26 public class RenameResourceElementsOperation extends MoveResourceElementsOperation {
28 * When executed, this operation will rename the specified elements with the given names in the
29 * corresponding destinations.
31 public RenameResourceElementsOperation(IJavaElement[] elements, IJavaElement[] destinations, String[] newNames, boolean force) {
32 //a rename is a move to the same parent with a new name specified
33 //these elements are from different parents
34 super(elements, destinations, force);
35 setRenamings(newNames);
40 protected String getMainTaskName() {
41 return Util.bind("operation.renameResourceProgress"); //$NON-NLS-1$
44 * @see CopyResourceElementsOperation#isRename()
46 protected boolean isRename() {
52 protected void verify(IJavaElement element) throws JavaModelException {
53 super.verify(element);
55 int elementType = element.getElementType();
57 if (!(elementType == IJavaElement.COMPILATION_UNIT || elementType == IJavaElement.PACKAGE_FRAGMENT)) {
58 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
60 if (elementType == IJavaElement.COMPILATION_UNIT) {
61 if (((ICompilationUnit) element).isWorkingCopy()) {
62 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
65 verifyRenaming(element);