A massive organize imports and formatting of the sources using default Eclipse code...
[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>
24  * Notes:
25  * <ul>
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
29  * renamed.
30  * <li>Constructors cannot be renamed.
31  * </ul>
32  */
33 public class RenameElementsOperation extends MoveElementsOperation {
34         /**
35          * When executed, this operation will rename the specified elements with the
36          * given names in the corresponding destinations.
37          */
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);
44         }
45
46         /**
47          * @see MultiOperation
48          */
49         protected String getMainTaskName() {
50                 return Util.bind("operation.renameElementProgress"); //$NON-NLS-1$
51         }
52
53         /**
54          * @see CopyElementsOperation#isRename()
55          */
56         protected boolean isRename() {
57                 return true;
58         }
59
60         /**
61          * @see MultiOperation
62          */
63         protected IJavaModelStatus verify() {
64                 IJavaModelStatus status = super.verify();
65                 if (!status.isOK())
66                         return status;
67                 if (fRenamingsList == null || fRenamingsList.length == 0)
68                         return new JavaModelStatus(IJavaModelStatusConstants.NULL_NAME);
69                 return JavaModelStatus.VERIFIED_OK;
70         }
71
72         /**
73          * @see MultiOperation
74          */
75         protected void verify(IJavaElement element) throws JavaModelException {
76                 int elementType = element.getElementType();
77
78                 if (element == null || !element.exists())
79                         error(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
80
81                 if (element.isReadOnly())
82                         error(IJavaModelStatusConstants.READ_ONLY, element);
83
84                 if (!(element instanceof ISourceReference))
85                         error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
86
87                 if (elementType < IJavaElement.TYPE
88                                 || elementType == IJavaElement.INITIALIZER)
89                         error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
90
91                 verifyRenaming(element);
92         }
93 }