KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > text > edits > TreeIterationInfo


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.text.edits;
12
13 import org.eclipse.core.runtime.Assert;
14
15
16 class TreeIterationInfo {
17
18     interface Visitor {
19         void visit(TextEdit edit);
20     }
21
22     private int fMark= -1;
23     private TextEdit[][] fEditStack= new TextEdit[10][];
24     private int[] fIndexStack= new int[10];
25
26     public int getSize() {
27         return fMark + 1;
28     }
29     public void push(TextEdit[] edits) {
30         if (++fMark == fEditStack.length) {
31             TextEdit[][] t1= new TextEdit[fEditStack.length * 2][];
32             System.arraycopy(fEditStack, 0, t1, 0, fEditStack.length);
33             fEditStack= t1;
34             int[] t2= new int[fEditStack.length];
35             System.arraycopy(fIndexStack, 0, t2, 0, fIndexStack.length);
36             fIndexStack= t2;
37         }
38         fEditStack[fMark]= edits;
39         fIndexStack[fMark]= -1;
40     }
41     public void setIndex(int index) {
42         fIndexStack[fMark]= index;
43     }
44     public void pop() {
45         fEditStack[fMark]= null;
46         fIndexStack[fMark]= -1;
47         fMark--;
48     }
49     public void accept(Visitor visitor) {
50         for (int i= fMark; i >= 0; i--) {
51             Assert.isTrue(fIndexStack[i] >= 0);
52             int start= fIndexStack[i] + 1;
53             TextEdit[] edits= fEditStack[i];
54             for (int s= start; s < edits.length; s++) {
55                 visitor.visit(edits[s]);
56             }
57         }
58     }
59 }
60
Popular Tags