Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0f1aa9c8409dab876da717e425dc07cb69341352 (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
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.text.edits;

import org.eclipse.core.runtime.Assert;


class TreeIterationInfo {

	interface Visitor {
		void visit(TextEdit edit);
	}

	private int fMark= -1;
	private TextEdit[][] fEditStack= new TextEdit[10][];
	private int[] fIndexStack= new int[10];

	public int getSize() {
		return fMark + 1;
	}
	public void push(TextEdit[] edits) {
		if (++fMark == fEditStack.length) {
			TextEdit[][] t1= new TextEdit[fEditStack.length * 2][];
			System.arraycopy(fEditStack, 0, t1, 0, fEditStack.length);
			fEditStack= t1;
			int[] t2= new int[fEditStack.length];
			System.arraycopy(fIndexStack, 0, t2, 0, fIndexStack.length);
			fIndexStack= t2;
		}
		fEditStack[fMark]= edits;
		fIndexStack[fMark]= -1;
	}
	public void setIndex(int index) {
		fIndexStack[fMark]= index;
	}
	public void pop() {
		fEditStack[fMark]= null;
		fIndexStack[fMark]= -1;
		fMark--;
	}
	public void accept(Visitor visitor) {
		for (int i= fMark; i >= 0; i--) {
			Assert.isTrue(fIndexStack[i] >= 0);
			int start= fIndexStack[i] + 1;
			TextEdit[] edits= fEditStack[i];
			for (int s= start; s < edits.length; s++) {
				visitor.visit(edits[s]);
			}
		}
	}
}

Back to the top