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.IJavaElement;
14 import net.sourceforge.phpdt.core.IJavaModelStatus;
15 import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
16 import net.sourceforge.phpdt.core.ISourceReference;
17 import net.sourceforge.phpdt.core.JavaModelException;
20 * This operation renames elements.
23 * <li>Resource rename is not supported - this operation only renames
24 * elements contained in compilation units.
25 * <li>When a main type is renamed, its compilation unit and constructors are renamed.
26 * <li>Constructors cannot be renamed.
29 public class RenameElementsOperation extends MoveElementsOperation {
31 * When executed, this operation will rename the specified elements with the given names in the
32 * corresponding destinations.
34 public RenameElementsOperation(IJavaElement[] elements, IJavaElement[] destinations, String[] newNames, boolean force) {
35 //a rename is a move to the same parent with a new name specified
36 //these elements are from different parents
37 super(elements, destinations, force);
38 setRenamings(newNames);
43 protected String getMainTaskName() {
44 return Util.bind("operation.renameElementProgress"); //$NON-NLS-1$
47 * @see CopyElementsOperation#isRename()
49 protected boolean isRename() {
55 protected IJavaModelStatus verify() {
56 IJavaModelStatus status = super.verify();
59 if (fRenamingsList == null || fRenamingsList.length == 0)
60 return new JavaModelStatus(IJavaModelStatusConstants.NULL_NAME);
61 return JavaModelStatus.VERIFIED_OK;
66 protected void verify(IJavaElement element) throws JavaModelException {
67 int elementType = element.getElementType();
69 if (element == null || !element.exists())
70 error(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
72 if (element.isReadOnly())
73 error(IJavaModelStatusConstants.READ_ONLY, element);
75 if (!(element instanceof ISourceReference))
76 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
78 if (elementType < IJavaElement.TYPE || elementType == IJavaElement.INITIALIZER)
79 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
81 verifyRenaming(element);