1 11 package org.eclipse.jdt.internal.compiler.problem; 12 13 import org.eclipse.jdt.core.compiler.CategorizedProblem; 14 import org.eclipse.jdt.core.compiler.IProblem; 15 import org.eclipse.jdt.internal.compiler.util.Messages; 16 import org.eclipse.jdt.internal.compiler.util.Util; 17 18 public class DefaultProblem extends CategorizedProblem { 19 private char[] fileName; 20 private int id; 21 private int startPosition, endPosition, line, column; 22 private int severity; 23 private String [] arguments; 24 private String message; 25 26 private static final String MARKER_TYPE_PROBLEM = "org.eclipse.jdt.core.problem"; private static final String MARKER_TYPE_TASK = "org.eclipse.jdt.core.task"; 30 public static final Object [] EMPTY_VALUES = {}; 31 32 public DefaultProblem( 33 char[] originatingFileName, 34 String message, 35 int id, 36 String [] stringArguments, 37 int severity, 38 int startPosition, 39 int endPosition, 40 int line, 41 int column) { 42 43 this.fileName = originatingFileName; 44 this.message = message; 45 this.id = id; 46 this.arguments = stringArguments; 47 this.severity = severity; 48 this.startPosition = startPosition; 49 this.endPosition = endPosition; 50 this.line = line; 51 this.column = column; 52 } 53 54 public String errorReportSource(char[] unitSource) { 55 59 61 if ((this.startPosition > this.endPosition) 63 || ((this.startPosition < 0) && (this.endPosition < 0)) 64 || unitSource.length == 0) 65 return Messages.problem_noSourceInformation; 66 67 StringBuffer errorBuffer = new StringBuffer (); 68 errorBuffer.append(' ').append(Messages.bind(Messages.problem_atLine, String.valueOf(this.line))); 69 errorBuffer.append(Util.LINE_SEPARATOR); 70 errorBuffer.append('\t'); 71 72 char c; 73 final char SPACE = '\u0020'; 74 final char MARK = '^'; 75 final char TAB = '\t'; 76 81 int length = unitSource.length, begin, end; 83 for (begin = this.startPosition >= length ? length - 1 : this.startPosition; begin > 0; begin--) { 84 if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break; 85 } 86 for (end = this.endPosition >= length ? length - 1 : this.endPosition ; end+1 < length; end++) { 87 if ((c = unitSource[end + 1]) == '\r' || c == '\n') break; 88 } 89 90 while ((c = unitSource[begin]) == ' ' || c == '\t') begin++; 92 94 errorBuffer.append(unitSource, begin, end-begin+1); 96 errorBuffer.append(Util.LINE_SEPARATOR).append("\t"); 98 for (int i = begin; i <this.startPosition; i++) { 100 errorBuffer.append((unitSource[i] == TAB) ? TAB : SPACE); 101 } 102 for (int i = this.startPosition; i <= (this.endPosition >= length ? length - 1 : this.endPosition); i++) { 103 errorBuffer.append(MARK); 104 } 105 return errorBuffer.toString(); 106 } 107 111 public String [] getArguments() { 112 return this.arguments; 113 } 114 117 public int getCategoryID() { 118 return ProblemReporter.getProblemCategory(this.severity, this.id); 119 } 120 121 126 public int getID() { 127 return this.id; 128 } 129 130 136 public String getInternalCategoryMessage() { 137 switch(getCategoryID()) { 138 case CAT_UNSPECIFIED: 139 return "unspecified"; case CAT_BUILDPATH: 141 return "buildpath"; case CAT_SYNTAX: 143 return "syntax"; case CAT_IMPORT: 145 return "import"; case CAT_TYPE: 147 return "type"; case CAT_MEMBER: 149 return "member"; case CAT_INTERNAL: 151 return "internal"; case CAT_JAVADOC: 153 return "javadoc"; case CAT_CODE_STYLE: 155 return "code style"; case CAT_POTENTIAL_PROGRAMMING_PROBLEM: 157 return "potential programming problem"; case CAT_NAME_SHADOWING_CONFLICT: 159 return "name shadowing conflict"; case CAT_DEPRECATION: 161 return "deprecation"; case CAT_UNNECESSARY_CODE: 163 return "unnecessary code"; case CAT_UNCHECKED_RAW: 165 return "unchecked/raw"; case CAT_NLS: 167 return "nls"; case CAT_RESTRICTION: 169 return "restriction"; } 171 return null; 172 } 173 174 178 public String getMarkerType() { 179 return this.id == IProblem.Task 180 ? MARKER_TYPE_TASK 181 : MARKER_TYPE_PROBLEM; 182 } 183 184 188 public String getMessage() { 189 return this.message; 190 } 191 192 196 public char[] getOriginatingFileName() { 197 return this.fileName; 198 } 199 200 204 public int getSourceEnd() { 205 return this.endPosition; 206 } 207 211 public int getSourceColumnNumber() { 212 return this.column; 213 } 214 218 public int getSourceLineNumber() { 219 return this.line; 220 } 221 225 public int getSourceStart() { 226 return this.startPosition; 227 } 228 229 233 public boolean isError() { 234 return (this.severity & ProblemSeverities.Error) != 0; 235 } 236 237 241 public boolean isWarning() { 242 return (this.severity & ProblemSeverities.Error) == 0; 243 } 244 245 public void setOriginatingFileName(char[] fileName) { 246 this.fileName = fileName; 247 } 248 249 255 public void setSourceEnd(int sourceEnd) { 256 this.endPosition = sourceEnd; 257 } 258 259 263 public void setSourceLineNumber(int lineNumber) { 264 265 this.line = lineNumber; 266 } 267 268 274 public void setSourceStart(int sourceStart) { 275 this.startPosition = sourceStart; 276 } 277 278 public String toString() { 279 String s = "Pb(" + (this.id & IProblem.IgnoreCategoriesMask) + ") "; if (this.message != null) { 281 s += this.message; 282 } else { 283 if (this.arguments != null) 284 for (int i = 0; i < this.arguments.length; i++) 285 s += " " + this.arguments[i]; } 287 return s; 288 } 289 } 290 | Popular Tags |