1 11 package org.eclipse.jdt.internal.corext.refactoring.util; 12 13 import java.util.Arrays ; 14 import java.util.Comparator ; 15 import java.util.HashMap ; 16 import java.util.Map ; 17 import java.util.Set ; 18 19 import org.eclipse.jdt.core.ICompilationUnit; 20 21 import org.eclipse.jdt.internal.corext.refactoring.changes.CompilationUnitChange; 22 import org.eclipse.ltk.core.refactoring.TextChange; 23 24 28 public class TextChangeManager { 29 30 private Map fMap= new HashMap (10); 31 32 private final boolean fKeepExecutedTextEdits; 33 34 public TextChangeManager() { 35 this(false); 36 } 37 38 public TextChangeManager(boolean keepExecutedTextEdits) { 39 fKeepExecutedTextEdits= keepExecutedTextEdits; 40 } 41 42 49 public void manage(ICompilationUnit cu, TextChange change) { 50 fMap.put(cu, change); 51 } 52 53 60 public TextChange get(ICompilationUnit cu) { 61 TextChange result= (TextChange)fMap.get(cu); 62 if (result == null) { 63 result= new CompilationUnitChange(cu.getElementName(), cu); 64 result.setKeepPreviewEdits(fKeepExecutedTextEdits); 65 fMap.put(cu, result); 66 } 67 return result; 68 } 69 70 77 public TextChange remove(ICompilationUnit unit) { 78 return (TextChange)fMap.remove(unit); 79 } 80 81 86 public TextChange[] getAllChanges(){ 87 Set cuSet= fMap.keySet(); 88 ICompilationUnit[] cus= (ICompilationUnit[]) cuSet.toArray(new ICompilationUnit[cuSet.size()]); 89 Arrays.sort(cus, new Comparator () { 91 public int compare(Object o1, Object o2) { 92 String name1= ((ICompilationUnit) o1).getElementName(); 93 String name2= ((ICompilationUnit) o2).getElementName(); 94 return name1.compareTo(name2); 95 } 96 }); 97 98 TextChange[] textChanges= new TextChange[cus.length]; 99 for (int i= 0; i < cus.length; i++) { 100 textChanges[i]= (TextChange) fMap.get(cus[i]); 101 } 102 return textChanges; 103 } 104 105 110 public ICompilationUnit[] getAllCompilationUnits(){ 111 return (ICompilationUnit[]) fMap.keySet().toArray(new ICompilationUnit[fMap.keySet().size()]); 112 } 113 114 117 public void clear() { 118 fMap.clear(); 119 } 120 121 127 public boolean containsChangesIn(ICompilationUnit cu){ 128 return fMap.containsKey(cu); 129 } 130 } 131 132 | Popular Tags |