KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.IJavaModelStatusConstants;
15 import org.eclipse.jdt.core.JavaModelException;
16 import org.eclipse.jdt.internal.core.util.Messages;
17
18 /**
19  * This operation renames resources (Package fragments and compilation units).
20  *
21  * <p>Notes:<ul>
22  * <li>When a compilation unit is renamed, its main type and the constructors of the
23  * main type are renamed.
24  * </ul>
25  */

26 public class RenameResourceElementsOperation extends MoveResourceElementsOperation {
27 /**
28  * When executed, this operation will rename the specified elements with the given names in the
29  * corresponding destinations.
30  */

31 public RenameResourceElementsOperation(IJavaElement[] elements, IJavaElement[] destinations, String JavaDoc[] newNames, boolean force) {
32     //a rename is a move to the same parent with a new name specified
33
//these elements are from different parents
34
super(elements, destinations, force);
35     setRenamings(newNames);
36 }
37 /**
38  * @see MultiOperation
39  */

40 protected String JavaDoc getMainTaskName() {
41     return Messages.operation_renameResourceProgress;
42 }
43 /**
44  * @see CopyResourceElementsOperation#isRename()
45  */

46 protected boolean isRename() {
47     return true;
48 }
49 /**
50  * @see MultiOperation
51  */

52 protected void verify(IJavaElement element) throws JavaModelException {
53     super.verify(element);
54
55     int elementType = element.getElementType();
56     
57     if (!(elementType == IJavaElement.COMPILATION_UNIT || elementType == IJavaElement.PACKAGE_FRAGMENT)) {
58         error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
59     }
60     if (elementType == IJavaElement.COMPILATION_UNIT) {
61         CompilationUnit cu = (CompilationUnit)element;
62         if (cu.isWorkingCopy() && !cu.isPrimary()) {
63             error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
64         }
65     }
66     verifyRenaming(element);
67 }
68 }
69
Popular Tags