blob: a9cfdeee41b298744eec18a4c0fa9a519427b081 (
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
|
/*******************************************************************************
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences 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:
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
/**
*
* This class serves as a container to pass several nodes to the
* <code>ASTWriter</code>. This container is used if source code for several sibling nodes but
* for their common parent node should be generated.
*
* @author Emanuel Graf IFS
*
*/
public class ContainerNode extends ASTNode {
private final IASTTranslationUnit tu = null;
private final ArrayList<IASTNode> nodes = new ArrayList<IASTNode>();
public ContainerNode(IASTNode... nodes) {
for (IASTNode each : nodes) {
addNode(each);
}
}
public ContainerNode copy() {
return copy(CopyStyle.withoutLocations);
}
public ContainerNode copy(CopyStyle style) {
ContainerNode copy = new ContainerNode();
for (IASTNode node : getNodes())
copy.addNode(node == null ? null : node.copy(style));
copy.setOffsetAndLength(this);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
}
public void addNode(IASTNode node) {
nodes.add(node);
if(node.getParent() == null) {
node.setParent(tu);
}
}
@Override
public boolean accept(ASTVisitor visitor) {
boolean ret = true;
for (IASTNode node : nodes) {
ret = node.accept(visitor);
}
return ret;
}
public IASTTranslationUnit getTu() {
return tu;
}
public List<IASTNode> getNodes(){
return Collections.unmodifiableList(nodes);
}
}
|