Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: aec7be638c94d95597733e29319b6fe1b18d66c9 (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
/*******************************************************************************
 * Copyright (c) 2007 Symbian 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:
 *    Andrew Ferguson (Symbian) - Initial implementation
 *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;

import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.core.runtime.CoreException;

/**
 * Applies the specified visitor to the node being visited, and recursively to 
 * any nodes which act as containers
 */
public class ApplyVisitor implements IBTreeVisitor, IPDOMVisitor {
	protected PDOMLinkage linkage;
	protected IPDOMVisitor visitor;
	
	public ApplyVisitor(PDOMLinkage linkage, IPDOMVisitor visitor) {
		this.linkage= linkage;
		this.visitor= visitor;
	}
	
	public int compare(long record) throws CoreException {
		return 0; // visit all nodes in a b-tree
	}
	
	public boolean visit(IPDOMNode node) throws CoreException {
		if(node instanceof PDOMBinding) {
			((PDOMBinding)node).accept(visitor);
			((PDOMBinding)node).accept(this);
		}
		return false; // don't visit children of the node
	}
	
	public boolean visit(long record) throws CoreException {
		if (record == 0)
			return true;
		PDOMNode node= linkage.getNode(record);
		if(node instanceof PDOMBinding) {
			((PDOMBinding)node).accept(visitor);
			((PDOMBinding)node).accept(this);
		} 
		return true;
	}

	public void leave(IPDOMNode node) throws CoreException {
	}	
}

Back to the top