1 11 package org.eclipse.jface.text.reconciler; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.Collection ; 16 17 import org.eclipse.core.runtime.Assert; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 20 import org.eclipse.jface.text.IRegion; 21 import org.eclipse.jface.text.reconciler.DirtyRegion; 22 23 24 29 public abstract class AbstractReconcileStep implements IReconcileStep { 30 31 private IReconcileStep fNextStep; 32 private IReconcileStep fPreviousStep; 33 private IProgressMonitor fProgressMonitor; 34 protected IReconcilableModel fInputModel; 35 36 42 public AbstractReconcileStep(IReconcileStep step) { 43 Assert.isNotNull(step); 44 fNextStep= step; 45 fNextStep.setPreviousStep(this); 46 } 47 48 51 public AbstractReconcileStep() { 52 } 53 54 public boolean isLastStep() { 55 return fNextStep == null; 56 } 57 58 public boolean isFirstStep() { 59 return fPreviousStep == null; 60 } 61 62 65 public void setProgressMonitor(IProgressMonitor monitor) { 66 fProgressMonitor= monitor; 67 68 if (!isLastStep()) 69 fNextStep.setProgressMonitor(monitor); 70 } 71 72 75 public IProgressMonitor getProgressMonitor() { 76 return fProgressMonitor; 77 } 78 79 82 public final IReconcileResult[] reconcile(IRegion partition) { 83 IReconcileResult[] result= reconcileModel(null, partition); 84 if (!isLastStep()) { 85 fNextStep.setInputModel(getModel()); 86 IReconcileResult[] nextResult= fNextStep.reconcile(partition); 87 return merge(result, convertToInputModel(nextResult)); 88 } 89 return result; 90 } 91 92 95 public final IReconcileResult[] reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { 96 IReconcileResult[] result= reconcileModel(dirtyRegion, subRegion); 97 if (!isLastStep()) { 98 fNextStep.setInputModel(getModel()); 99 IReconcileResult[] nextResult= fNextStep.reconcile(dirtyRegion, subRegion); 100 return merge(result, convertToInputModel(nextResult)); 101 } 102 return result; 103 } 104 105 106 114 abstract protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, IRegion subRegion); 115 116 123 protected IReconcileResult[] convertToInputModel(IReconcileResult[] inputResults) { 124 return inputResults; 125 } 126 127 134 private IReconcileResult[] merge(IReconcileResult[] results1, IReconcileResult[] results2) { 135 if (results1 == null) 136 return results2; 137 138 if (results2 == null) 139 return results1; 140 141 Collection collection= new ArrayList (Arrays.asList(results1)); 143 collection.addAll(Arrays.asList(results2)); 144 return (IReconcileResult[])collection.toArray(new IReconcileResult[collection.size()]); 145 } 146 147 150 protected final boolean isCanceled() { 151 return fProgressMonitor != null && fProgressMonitor.isCanceled(); 152 } 153 154 157 public void setPreviousStep(IReconcileStep step) { 158 Assert.isNotNull(step); 159 Assert.isTrue(fPreviousStep == null); 160 fPreviousStep= step; 161 } 162 163 166 public void setInputModel(IReconcilableModel inputModel) { 167 fInputModel= inputModel; 168 169 if (!isLastStep()) 170 fNextStep.setInputModel(getModel()); 171 } 172 173 178 public IReconcilableModel getInputModel() { 179 return fInputModel; 180 } 181 182 187 abstract public IReconcilableModel getModel(); 188 } 189 | Popular Tags |