blob: 9f2e21cb87f5b22de9c83a27de15fead6f5469c1 (
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
|
/**********************************************************************
* Copyright (c) 2002,2003,2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
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.ITranslationUnit;
/**
* CreateSourceReferenceOperation
*/
public class CreateSourceReferenceOperation extends CreateElementInTUOperation {
/**
* Element Name
*/
String fName;
/**
* Element Type
*/
int fElementType;
/**
* Source Reference element to copy to parent
*/
String fSource;
/**
* @param parentElement
*/
public CreateSourceReferenceOperation(ICElement parentElement, String name, int elementType, String source) {
super(parentElement);
fName = name;
fElementType = elementType;
fSource = source;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.CreateElementInTUOperation#generateElement(org.eclipse.cdt.core.model.ITranslationUnit)
*/
protected String generateElement(ITranslationUnit unit) throws CModelException {
return fSource;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.CreateElementInTUOperation#generateResultHandle()
*/
protected ICElement generateResultHandle() {
ITranslationUnit unit = getTranslationUnit();
try {
ICElement[] celements = unit.getChildren();
for (int i = 0; i < celements.length; ++i) {
if (celements[i].getElementType() == fElementType) {
String name = celements[i].getElementName();
if (name.equals(fName)) {
return celements[i];
}
}
}
} catch (CModelException e) {
//
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.CreateElementInTUOperation#getMainTaskName()
*/
protected String getMainTaskName() {
return "operation.createsourceReference"; //$NON-NLS-1$
}
}
|