Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 297614f7475347e9bac0ec09fb484b06bd5f0ba2 (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
/*******************************************************************************
 * Copyright (c) 2008, 2011 Wind River Systems, Inc. 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:
 *     Markus Schorn - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.cdt.core.dom.ast.ASTGenericVisitor;
import org.eclipse.cdt.core.dom.ast.IASTNode;

/**
 * Collector to find all children for an ast-node.
 */
class ChildCollector extends ASTGenericVisitor {
	private final IASTNode fNode;
	private List<IASTNode> fNodes;

	public ChildCollector(IASTNode node) {
		super(true);
		fNode= node;
	}

	public IASTNode[] getChildren() {
		fNode.accept(this);
		if (fNodes == null)
			return IASTNode.EMPTY_NODE_ARRAY;

		return fNodes.toArray(new IASTNode[fNodes.size()]);
	}

	@Override
	protected int genericVisit(IASTNode child) {
		if (fNodes == null) {
			if (child == fNode)
				return PROCESS_CONTINUE;
			fNodes= new ArrayList<IASTNode>();
		}
		fNodes.add(child);
		return PROCESS_SKIP;
	}
}

Back to the top