1 11 package org.eclipse.ltk.core.refactoring; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.NullProgressMonitor; 17 18 import org.eclipse.core.resources.IWorkspaceRunnable; 19 20 37 public class CheckConditionsOperation implements IWorkspaceRunnable { 38 39 private Refactoring fRefactoring; 40 private int fStyle; 41 private RefactoringStatus fStatus; 42 43 44 public final static int NONE= 0; 45 46 public final static int INITIAL_CONDITONS= 1 << 1; 47 48 public final static int FINAL_CONDITIONS= 1 << 2; 49 50 public final static int ALL_CONDITIONS= INITIAL_CONDITONS | FINAL_CONDITIONS; 51 52 private final static int LAST= 1 << 3; 53 54 63 public CheckConditionsOperation(Refactoring refactoring, int style) { 64 Assert.isNotNull(refactoring); 65 fRefactoring= refactoring; 66 fStyle= style; 67 Assert.isTrue(checkStyle(fStyle)); 68 } 69 70 73 public void run(IProgressMonitor pm) throws CoreException { 74 if (pm == null) 75 pm= new NullProgressMonitor(); 76 try { 77 fStatus= null; 78 if ((fStyle & ALL_CONDITIONS) == ALL_CONDITIONS) 79 fStatus= fRefactoring.checkAllConditions(pm); 80 else if ((fStyle & INITIAL_CONDITONS) == INITIAL_CONDITONS) 81 fStatus= fRefactoring.checkInitialConditions(pm); 82 else if ((fStyle & FINAL_CONDITIONS) == FINAL_CONDITIONS) 83 fStatus= fRefactoring.checkFinalConditions(pm); 84 } finally { 85 pm.done(); 86 } 87 } 88 89 96 public RefactoringStatus getStatus() { 97 return fStatus; 98 } 99 100 105 public Refactoring getRefactoring() { 106 return fRefactoring; 107 } 108 109 114 public int getStyle() { 115 return fStyle; 116 } 117 118 private boolean checkStyle(int style) { 119 return style > NONE && style < LAST; 120 } 121 122 int getTicks(RefactoringTickProvider provider) { 123 if ((fStyle & ALL_CONDITIONS) == ALL_CONDITIONS) 124 return provider.getCheckAllConditionsTicks(); 125 else if ((fStyle & INITIAL_CONDITONS) == INITIAL_CONDITONS) 126 return provider.getCheckInitialConditionsTicks(); 127 else if ((fStyle & FINAL_CONDITIONS) == FINAL_CONDITIONS) 128 return provider.getCheckFinalConditionsTicks(); 129 return 0; 130 } 131 } 132 | Popular Tags |