blob: daec5744e09b13359b4cd5e122cfe3e9dafb4254 (
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
90
91
92
|
/*******************************************************************************
* Copyright (c) 2000, 2016 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.make.internal.core.makefile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.make.core.makefile.IDirective;
import org.eclipse.cdt.make.core.makefile.IParent;
/**
* IParent
*/
public abstract class Parent extends Directive implements IParent {
ArrayList<Directive> children = new ArrayList<Directive>();
public Parent(Directive parent) {
super(parent);
}
public IDirective[] getDirectives(boolean expand) {
if (expand) {
List<IDirective> directives = new ArrayList<IDirective>();
getDirectives(); // populates children for class Include
for (IDirective directive : children) {
directives.add(directive);
if (directive instanceof Parent) {
directives.addAll(Arrays.asList(((Parent) directive).getDirectives(expand)));
}
}
return directives.toArray(new IDirective[directives.size()]);
}
return getDirectives();
}
@Override
public IDirective[] getDirectives() {
children.trimToSize();
return children.toArray(new IDirective[0]);
}
public void addDirective(Directive directive) {
children.add(directive);
// reparent
directive.setParent(this);
}
public void addDirectives(Directive[] directives) {
children.addAll(Arrays.asList(directives));
// reparent
for (int i = 0; i < directives.length; i++) {
directives[i].setParent(this);
}
}
public void clearDirectives() {
children.clear();
}
public Directive[] getStatements() {
children.trimToSize();
return children.toArray(new Directive[0]);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
IDirective[] directives = getDirectives();
for (int i = 0; i < directives.length; i++) {
sb.append(directives[i]);
}
return sb.toString();
}
}
|