Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4d8e65c8908fbad644e9c37904bd192835291797 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*******************************************************************************
 * Copyright (c) 2002, 2008 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *     Anton Leherbauer (Wind River Systems)
 *******************************************************************************/

package org.eclipse.cdt.internal.core.model;

import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatus;
import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.core.model.ISourceReference;

/**
 * RenameElementsOperation
 */
public class RenameElementsOperation extends MoveElementsOperation {
	/**
	 * When executed, this operation will rename the specified elements with the given names in the
	 * corresponding destinations.
	 */
	public RenameElementsOperation(ICElement[] elements, ICElement[] destinations, String[] newNames, boolean force) {
		//a rename is a move to the same parent with a new name specified
		//these elements are from different parents
		super(elements, destinations, force);
		setRenamings(newNames);
	}
	/**
	 * @see MultiOperation
	 */
	@Override
	protected String getMainTaskName() {
		return CoreModelMessages.getString("operation.renameElementProgress"); //$NON-NLS-1$
	}
	/**
	 * @see CopyElementsOperation#isRename()
	 */
	@Override
	protected boolean isRename() {
		return true;
	}
	/**
	 * @see MultiOperation
	 */
	@Override
	protected ICModelStatus verify() {
		ICModelStatus status = super.verify();
		if (! status.isOK())
			return status;
		if (this.fRenamingsList == null || this.fRenamingsList.length == 0)
			return new CModelStatus(ICModelStatusConstants.NULL_NAME);
		return CModelStatus.VERIFIED_OK;
	}
	/**
	 * @see MultiOperation
	 */
	@Override
	protected void verify(ICElement element) throws CModelException {
		int elementType = element.getElementType();
		
		if (element == null || !element.exists())
			error(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element);
			
		if (element.isReadOnly())
			error(ICModelStatusConstants.READ_ONLY, element);
			
		if (!(element instanceof ISourceReference))
			error(ICModelStatusConstants.INVALID_ELEMENT_TYPES, element);
			
		if (elementType < ICElement.C_UNIT /*|| elementType == ICElement.INITIALIZER*/)
			error(ICModelStatusConstants.INVALID_ELEMENT_TYPES, element);
			
//		Member localContext;
//		if (element instanceof Member && (localContext = ((Member)element).getOuterMostLocalContext()) != null && localContext != element) {
//			// JDOM doesn't support source manipulation in local/anonymous types
//			error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
//		}

		verifyRenaming(element);
	}

}

Back to the top