1 11 package org.eclipse.text.edits; 12 13 import java.util.List ; 14 15 import org.eclipse.core.runtime.Assert; 16 17 import org.eclipse.jface.text.BadLocationException; 18 import org.eclipse.jface.text.IDocument; 19 import org.eclipse.jface.text.IRegion; 20 21 33 public class MultiTextEdit extends TextEdit { 34 35 private boolean fDefined; 36 37 46 public MultiTextEdit() { 47 super(0, Integer.MAX_VALUE); 48 fDefined= false; 49 } 50 51 61 public MultiTextEdit(int offset, int length) { 62 super(offset, length); 63 fDefined= true; 64 } 65 66 69 protected MultiTextEdit(MultiTextEdit other) { 70 super(other); 71 } 72 73 85 protected void checkIntegrity() throws MalformedTreeException { 86 } 88 89 92 final boolean isDefined() { 93 if (fDefined) 94 return true; 95 return hasChildren(); 96 } 97 98 101 public final int getOffset() { 102 if (fDefined) 103 return super.getOffset(); 104 105 List children= internalGetChildren(); 106 if (children == null || children.size() == 0) 107 return 0; 108 return ((TextEdit)children.get(0)).getOffset(); 110 } 111 112 115 public final int getLength() { 116 if (fDefined) 117 return super.getLength(); 118 119 List children= internalGetChildren(); 120 if (children == null || children.size() == 0) 121 return 0; 122 TextEdit first= (TextEdit)children.get(0); 124 TextEdit last= (TextEdit)children.get(children.size() - 1); 125 return last.getOffset() - first.getOffset() + last.getLength(); 126 } 127 128 131 public final boolean covers(TextEdit other) { 132 if (fDefined) 133 return super.covers(other); 134 return true; 136 } 137 138 141 protected boolean canZeroLengthCover() { 142 return true; 143 } 144 145 148 protected TextEdit doCopy() { 149 Assert.isTrue(MultiTextEdit.class == getClass(), "Subclasses must reimplement copy0"); return new MultiTextEdit(this); 151 } 152 153 156 protected void accept0(TextEditVisitor visitor) { 157 boolean visitChildren= visitor.visit(this); 158 if (visitChildren) { 159 acceptChildren(visitor); 160 } 161 } 162 163 167 void adjustOffset(int delta) { 168 if (fDefined) 169 super.adjustOffset(delta); 170 } 171 172 176 void adjustLength(int delta) { 177 if (fDefined) 178 super.adjustLength(delta); 179 } 180 181 184 void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { 185 checkIntegrity(); 186 } 187 188 191 int performDocumentUpdating(IDocument document) throws BadLocationException { 192 fDelta= 0; 193 return fDelta; 194 } 195 196 199 boolean deleteChildren() { 200 return false; 201 } 202 203 void aboutToBeAdded(TextEdit parent) { 204 defineRegion(parent.getOffset()); 205 } 206 207 void defineRegion(int parentOffset) { 208 if (fDefined) 209 return; 210 if (hasChildren()) { 211 IRegion region= getCoverage(getChildren()); 212 internalSetOffset(region.getOffset()); 213 internalSetLength(region.getLength()); 214 } else { 215 internalSetOffset(parentOffset); 216 internalSetLength(0); 217 } 218 fDefined= true; 219 } 220 221 225 void internalToString(StringBuffer buffer, int indent) { 226 super.internalToString(buffer, indent); 227 if (! fDefined) 228 buffer.append(" [undefined]"); } 230 } 231 | Popular Tags |