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;
18 import net.sourceforge.phpdt.internal.core.util.Util;
21 * This operation renames elements.
26 * <li>Resource rename is not supported - this operation only renames elements
27 * contained in compilation units.
28 * <li>When a main type is renamed, its compilation unit and constructors are
30 * <li>Constructors cannot be renamed.
33 public class RenameElementsOperation extends MoveElementsOperation {
35 * When executed, this operation will rename the specified elements with the
36 * given names in the corresponding destinations.
38 public RenameElementsOperation(IJavaElement[] elements,
39 IJavaElement[] destinations, String[] newNames, boolean force) {
40 // a rename is a move to the same parent with a new name specified
41 // these elements are from different parents
42 super(elements, destinations, force);
43 setRenamings(newNames);
49 protected String getMainTaskName() {
50 return Util.bind("operation.renameElementProgress"); //$NON-NLS-1$
54 * @see CopyElementsOperation#isRename()
56 protected boolean isRename() {
63 protected IJavaModelStatus verify() {
64 IJavaModelStatus status = super.verify();
67 if (fRenamingsList == null || fRenamingsList.length == 0)
68 return new JavaModelStatus(IJavaModelStatusConstants.NULL_NAME);
69 return JavaModelStatus.VERIFIED_OK;
75 protected void verify(IJavaElement element) throws JavaModelException {
76 int elementType = element.getElementType();
78 if (element == null || !element.exists())
79 error(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
81 if (element.isReadOnly())
82 error(IJavaModelStatusConstants.READ_ONLY, element);
84 if (!(element instanceof ISourceReference))
85 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
87 if (elementType < IJavaElement.TYPE
88 || elementType == IJavaElement.INITIALIZER)
89 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
91 verifyRenaming(element);