129
|
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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.text.edits.TreeIterationInfo;
|
|
14
|
131
|
15 import dwtx.text.edits.MultiTextEdit; // packageimport
|
|
16 import dwtx.text.edits.CopySourceEdit; // packageimport
|
|
17 import dwtx.text.edits.MoveSourceEdit; // packageimport
|
|
18 import dwtx.text.edits.CopyingRangeMarker; // packageimport
|
|
19 import dwtx.text.edits.ReplaceEdit; // packageimport
|
|
20 import dwtx.text.edits.EditDocument; // packageimport
|
|
21 import dwtx.text.edits.UndoCollector; // packageimport
|
|
22 import dwtx.text.edits.DeleteEdit; // packageimport
|
|
23 import dwtx.text.edits.MoveTargetEdit; // packageimport
|
|
24 import dwtx.text.edits.CopyTargetEdit; // packageimport
|
|
25 import dwtx.text.edits.TextEditCopier; // packageimport
|
|
26 import dwtx.text.edits.ISourceModifier; // packageimport
|
|
27 import dwtx.text.edits.TextEditMessages; // packageimport
|
|
28 import dwtx.text.edits.TextEditProcessor; // packageimport
|
|
29 import dwtx.text.edits.MalformedTreeException; // packageimport
|
|
30 import dwtx.text.edits.TextEditVisitor; // packageimport
|
|
31 import dwtx.text.edits.TextEditGroup; // packageimport
|
|
32 import dwtx.text.edits.TextEdit; // packageimport
|
|
33 import dwtx.text.edits.RangeMarker; // packageimport
|
|
34 import dwtx.text.edits.UndoEdit; // packageimport
|
|
35 import dwtx.text.edits.InsertEdit; // packageimport
|
|
36
|
|
37
|
129
|
38 import dwt.dwthelper.utils;
|
|
39
|
|
40 import dwtx.core.runtime.Assert;
|
|
41
|
|
42
|
|
43 class TreeIterationInfo {
|
|
44
|
|
45 interface Visitor {
|
|
46 void visit(TextEdit edit);
|
|
47 }
|
|
48
|
|
49 private int fMark= -1;
|
159
|
50 private TextEdit[][] fEditStack;
|
|
51 private int[] fIndexStack;
|
|
52
|
|
53 public this(){
|
|
54 fEditStack= new TextEdit[][](10);
|
|
55 fIndexStack= new int[10];
|
|
56 }
|
129
|
57
|
|
58 public int getSize() {
|
|
59 return fMark + 1;
|
|
60 }
|
|
61 public void push(TextEdit[] edits) {
|
|
62 if (++fMark is fEditStack.length) {
|
159
|
63 TextEdit[][] t1= new TextEdit[][](fEditStack.length * 2);
|
|
64 SimpleType!(TextEdit[]).arraycopy(fEditStack, 0, t1, 0, fEditStack.length);
|
129
|
65 fEditStack= t1;
|
|
66 int[] t2= new int[fEditStack.length];
|
|
67 System.arraycopy(fIndexStack, 0, t2, 0, fIndexStack.length);
|
|
68 fIndexStack= t2;
|
|
69 }
|
|
70 fEditStack[fMark]= edits;
|
|
71 fIndexStack[fMark]= -1;
|
|
72 }
|
|
73 public void setIndex(int index) {
|
|
74 fIndexStack[fMark]= index;
|
|
75 }
|
|
76 public void pop() {
|
|
77 fEditStack[fMark]= null;
|
|
78 fIndexStack[fMark]= -1;
|
|
79 fMark--;
|
|
80 }
|
|
81 public void accept(Visitor visitor) {
|
|
82 for (int i= fMark; i >= 0; i--) {
|
|
83 Assert.isTrue(fIndexStack[i] >= 0);
|
|
84 int start= fIndexStack[i] + 1;
|
|
85 TextEdit[] edits= fEditStack[i];
|
|
86 for (int s= start; s < edits.length; s++) {
|
|
87 visitor.visit(edits[s]);
|
|
88 }
|
|
89 }
|
|
90 }
|
|
91 }
|