KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > RenameElementsOperation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core;
12
13 import org.eclipse.jdt.core.IJavaElement;
14 import org.eclipse.jdt.core.IJavaModelStatus;
15 import org.eclipse.jdt.core.IJavaModelStatusConstants;
16 import org.eclipse.jdt.core.ISourceReference;
17 import org.eclipse.jdt.core.JavaModelException;
18 import org.eclipse.jdt.internal.core.util.Messages;
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 JavaDoc[] 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 JavaDoc getMainTaskName() {
45     return Messages.operation_renameElementProgress;
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 (this.renamingsList == null || this.renamingsList.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     if (element == null || !element.exists())
69         error(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
70         
71     if (element.isReadOnly())
72         error(IJavaModelStatusConstants.READ_ONLY, element);
73         
74     if (!(element instanceof ISourceReference))
75         error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
76         
77     int elementType = element.getElementType();
78     if (elementType < IJavaElement.TYPE || elementType == IJavaElement.INITIALIZER)
79         error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
80         
81     verifyRenaming(element);
82 }
83 }
84
Popular Tags