1 11 package org.eclipse.ltk.core.refactoring; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 17 import org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin; 18 19 32 public class RefactoringStatusEntry { 33 34 39 public static final int NO_CODE= -1; 40 41 42 private final int fSeverity; 43 44 45 private final String fMessage; 46 47 48 private final int fCode; 49 50 51 private final String fPluginId; 52 53 54 private final RefactoringStatusContext fContext; 55 56 57 private final Object fData; 58 59 68 public RefactoringStatusEntry(int severity, String msg) { 69 this(severity, msg, null); 70 } 71 72 81 public RefactoringStatusEntry(int severity, String msg, RefactoringStatusContext context) { 82 this(severity, msg, context, null, NO_CODE, null); 83 } 84 85 96 public RefactoringStatusEntry(int severity, String msg, RefactoringStatusContext context, String pluginId, int code) { 97 this(severity, msg, context, pluginId, code, null); 98 } 99 100 111 public RefactoringStatusEntry(int severity, String msg, RefactoringStatusContext context, String pluginId, int code, Object data) { 112 Assert.isTrue(severity == RefactoringStatus.INFO || severity == RefactoringStatus.WARNING 113 || severity == RefactoringStatus.ERROR || severity == RefactoringStatus.FATAL); 114 Assert.isNotNull(msg); 115 Assert.isTrue(code == NO_CODE || code >= 0); 116 if (code != NO_CODE) Assert.isTrue(pluginId != null); 117 fMessage= msg; 118 fSeverity= severity; 119 fContext= context; 120 fPluginId= pluginId; 121 fCode= code; 122 fData= data; 123 } 124 125 130 public String getMessage() { 131 return fMessage; 132 } 133 134 144 public int getSeverity() { 145 return fSeverity; 146 } 147 148 155 public RefactoringStatusContext getContext() { 156 return fContext; 157 } 158 159 166 public String getPluginId() { 167 return fPluginId; 168 } 169 170 175 public int getCode() { 176 return fCode; 177 } 178 179 186 public Object getData() { 187 return fData; 188 } 189 190 195 public boolean isFatalError() { 196 return fSeverity == RefactoringStatus.FATAL; 197 } 198 199 204 public boolean isError() { 205 return fSeverity == RefactoringStatus.ERROR; 206 } 207 208 213 public boolean isWarning() { 214 return fSeverity == RefactoringStatus.WARNING; 215 } 216 217 222 public boolean isInfo() { 223 return fSeverity == RefactoringStatus.INFO; 224 } 225 226 242 public IStatus toStatus() { 243 int statusSeverity= IStatus.ERROR; 244 switch (getSeverity()) { 245 case RefactoringStatus.OK: 246 statusSeverity= IStatus.OK; 247 break; 248 case RefactoringStatus.INFO: 249 statusSeverity= IStatus.INFO; 250 break; 251 case RefactoringStatus.WARNING: 252 case RefactoringStatus.ERROR: 253 statusSeverity= IStatus.WARNING; 254 break; 255 } 256 String pluginId= getPluginId(); 257 int code= getCode(); 258 if (pluginId == null) { 259 pluginId= RefactoringCorePlugin.getPluginId(); 260 code= IStatus.ERROR; 261 } 262 return new Status(statusSeverity, pluginId, code, getMessage(), null); 263 } 264 265 268 public String toString() { 269 String contextString= fContext == null ? "<Unspecified context>" : fContext.toString(); return "\n" + RefactoringStatus.getSeverityString(fSeverity) + ": " + fMessage + "\nContext: " + contextString + (fCode == NO_CODE ? "\ncode: none" : "\nplug-in id: " + fPluginId + "code: " + fCode) + "\nData: " + fData; } 276 } 277 | Popular Tags |