3m9 compatible;
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / RenameElementsOperation.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
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;
19
20 /**
21  * This operation renames elements.
22  *
23  * <p>Notes:<ul>
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.
28  * </ul>
29  */
30 public class RenameElementsOperation extends MoveElementsOperation {
31 /**
32  * When executed, this operation will rename the specified elements with the given names in the
33  * corresponding destinations.
34  */
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);
40 }
41 /**
42  * @see MultiOperation
43  */
44 protected String getMainTaskName() {
45         return Util.bind("operation.renameElementProgress"); //$NON-NLS-1$
46 }
47 /**
48  * @see CopyElementsOperation#isRename()
49  */
50 protected boolean isRename() {
51         return true;
52 }
53 /**
54  * @see MultiOperation
55  */
56 protected IJavaModelStatus verify() {
57         IJavaModelStatus status = super.verify();
58         if (! status.isOK())
59                 return status;
60         if (fRenamingsList == null || fRenamingsList.length == 0)
61                 return new JavaModelStatus(IJavaModelStatusConstants.NULL_NAME);
62         return JavaModelStatus.VERIFIED_OK;
63 }
64 /**
65  * @see MultiOperation
66  */
67 protected void verify(IJavaElement element) throws JavaModelException {
68         int elementType = element.getElementType();
69         
70         if (element == null || !element.exists())
71                 error(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
72                 
73         if (element.isReadOnly())
74                 error(IJavaModelStatusConstants.READ_ONLY, element);
75                 
76         if (!(element instanceof ISourceReference))
77                 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
78                 
79         if (elementType < IJavaElement.TYPE || elementType == IJavaElement.INITIALIZER)
80                 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
81                 
82         verifyRenaming(element);
83 }
84 }