1
/*******************************************************************************
2
* Copyright (c) 2002, 2008 QNX Software Systems 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
9
* QNX Software Systems - Initial API and implementation
10
* Anton Leherbauer (Wind River Systems)
11
*******************************************************************************/
13
package org.eclipse.cdt.internal.core.model;
15
import org.eclipse.cdt.core.model.CModelException;
16
import org.eclipse.cdt.core.model.ICElement;
17
import org.eclipse.cdt.core.model.ICModelStatus;
18
import org.eclipse.cdt.core.model.ICModelStatusConstants;
19
import org.eclipse.cdt.core.model.ISourceReference;
22
* RenameElementsOperation
24
public class RenameElementsOperation extends MoveElementsOperation {
26
* When executed, this operation will rename the specified elements with the given names in the
27
* corresponding destinations.
29
public RenameElementsOperation(ICElement[] elements, ICElement[] destinations, String[] newNames, boolean force) {
30
//a rename is a move to the same parent with a new name specified
31
//these elements are from different parents
32
super(elements, destinations, force);
33
setRenamings(newNames);
39
protected String getMainTaskName() {
40
return CoreModelMessages.getString("operation.renameElementProgress"); //$NON-NLS-1$
43
* @see CopyElementsOperation#isRename()
46
protected boolean isRename() {
53
protected ICModelStatus verify() {
54
ICModelStatus status = super.verify();
57
if (this.fRenamingsList == null || this.fRenamingsList.length == 0)
58
return new CModelStatus(ICModelStatusConstants.NULL_NAME);
59
return CModelStatus.VERIFIED_OK;
65
protected void verify(ICElement element) throws CModelException {
67
if (element == null || !element.exists())
68
error(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
70
int elementType = element.getElementType();
71
if (element.isReadOnly())
72
error(ICModelStatusConstants.READ_ONLY, element);
74
if (!(element instanceof ISourceReference))
75
error(ICModelStatusConstants.INVALID_ELEMENT_TYPES, element);
77
if (elementType < ICElement.C_UNIT /*|| elementType == ICElement.INITIALIZER*/)
78
error(ICModelStatusConstants.INVALID_ELEMENT_TYPES, element);
80
// Member localContext;
81
// if (element instanceof Member && (localContext = ((Member)element).getOuterMostLocalContext()) != null && localContext != element) {
82
// // JDOM doesn't support source manipulation in local/anonymous types
83
// error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
86
verifyRenaming(element);