1 11 package org.eclipse.text.edits; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.Assert; 18 19 import org.eclipse.jface.text.IRegion; 20 21 22 34 public class TextEditGroup { 35 36 private String fDescription; 37 private List fEdits; 38 39 45 public TextEditGroup(String name) { 46 super(); 47 Assert.isNotNull(name); 48 fDescription= name; 49 fEdits= new ArrayList (3); 50 } 51 52 60 public TextEditGroup(String name, TextEdit edit) { 61 Assert.isNotNull(name); 62 Assert.isNotNull(edit); 63 fDescription= name; 64 fEdits= new ArrayList (1); 65 fEdits.add(edit); 66 } 67 68 76 public TextEditGroup(String name, TextEdit[] edits) { 77 super(); 78 Assert.isNotNull(name); 79 Assert.isNotNull(edits); 80 fDescription= name; 81 fEdits= new ArrayList (Arrays.asList(edits)); 82 } 83 84 89 public String getName() { 90 return fDescription; 91 } 92 93 98 public void addTextEdit(TextEdit edit) { 99 fEdits.add(edit); 100 } 101 102 109 public boolean removeTextEdit(TextEdit edit) { 110 return fEdits.remove(edit); 111 } 112 113 118 public void clearTextEdits() { 119 fEdits.clear(); 120 } 121 122 123 124 132 public boolean isEmpty() { 133 return fEdits.isEmpty(); 134 } 135 136 142 public TextEdit[] getTextEdits() { 143 return (TextEdit[]) fEdits.toArray(new TextEdit[fEdits.size()]); 144 } 145 146 154 public IRegion getRegion() { 155 int size= fEdits.size(); 156 if (size == 0) { 157 return null; 158 } else if (size == 1) { 159 return ((TextEdit)fEdits.get(0)).getRegion(); 160 } else { 161 return TextEdit.getCoverage((TextEdit[])fEdits.toArray(new TextEdit[fEdits.size()])); 162 } 163 } 164 } 165 | Popular Tags |