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.
24 * <li>Resource rename is not supported - this operation only renames
25 * elements contained in compilation units.
26 * <li>When a main type is renamed, its compilation unit and constructors are renamed.
27 * <li>Constructors cannot be renamed.
30 public class RenameElementsOperation extends MoveElementsOperation {
32 * When executed, this operation will rename the specified elements with the given names in the
33 * corresponding destinations.
35 public RenameElementsOperation(IJavaElement[] elements, IJavaElement[] destinations, String[] newNames, boolean force) {
36 //a rename is a move to the same parent with a new name specified
37 //these elements are from different parents
38 super(elements, destinations, force);
39 setRenamings(newNames);
44 protected String getMainTaskName() {
45 return Util.bind("operation.renameElementProgress"); //$NON-NLS-1$
48 * @see CopyElementsOperation#isRename()
50 protected boolean isRename() {
56 protected IJavaModelStatus verify() {
57 IJavaModelStatus status = super.verify();
60 if (fRenamingsList == null || fRenamingsList.length == 0)
61 return new JavaModelStatus(IJavaModelStatusConstants.NULL_NAME);
62 return JavaModelStatus.VERIFIED_OK;
67 protected void verify(IJavaElement element) throws JavaModelException {
68 int elementType = element.getElementType();
70 if (element == null || !element.exists())
71 error(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
73 if (element.isReadOnly())
74 error(IJavaModelStatusConstants.READ_ONLY, element);
76 if (!(element instanceof ISourceReference))
77 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
79 if (elementType < IJavaElement.TYPE || elementType == IJavaElement.INITIALIZER)
80 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
82 verifyRenaming(element);