1 11 package org.eclipse.jdt.internal.eval; 12 13 import org.eclipse.jdt.core.compiler.CategorizedProblem; 14 15 24 public class EvaluationResult { 25 26 static final CategorizedProblem[] NO_PROBLEMS = new CategorizedProblem[0]; 27 28 char[] evaluationID; 29 int evaluationType; 30 CategorizedProblem[] problems; 31 char[] displayString; 32 char[] typeName; 33 34 41 public static final int T_VARIABLE = 1; 42 43 47 public static final int T_CODE_SNIPPET = 2; 48 49 52 public static final int T_IMPORT = 3; 53 54 57 public static final int T_PACKAGE = 4; 58 59 62 public static final int T_INTERNAL = 5; 63 64 public EvaluationResult(char[] evaluationID, int evaluationType, char[] displayString, char[] typeName) { 65 this.evaluationID = evaluationID; 66 this.evaluationType = evaluationType; 67 this.displayString = displayString; 68 this.typeName = typeName; 69 this.problems = NO_PROBLEMS; 70 } 71 public EvaluationResult(char[] evaluationID, int evaluationType, CategorizedProblem[] problems) { 72 this.evaluationID = evaluationID; 73 this.evaluationType = evaluationType; 74 this.problems = problems; 75 } 76 79 void addProblem(CategorizedProblem problem) { 80 CategorizedProblem[] existingProblems = this.problems; 81 int existingLength = existingProblems.length; 82 this.problems = new CategorizedProblem[existingLength + 1]; 83 System.arraycopy(existingProblems, 0, this.problems, 0, existingLength); 84 this.problems[existingLength] = problem; 85 } 86 93 public char[] getEvaluationID() { 94 return this.evaluationID; 95 } 96 102 public int getEvaluationType() { 103 return this.evaluationType; 104 } 105 111 public CategorizedProblem[] getProblems() { 112 return this.problems; 113 } 114 125 public Object getValue() { 126 return null; } 128 135 public char[] getValueDisplayString() { 136 return this.displayString; 137 } 138 144 public char[] getValueTypeName() { 145 return this.typeName; 146 } 147 150 public boolean hasErrors() { 151 if (this.problems == null) { 152 return false; 153 } else { 154 for (int i = 0; i < this.problems.length; i++) { 155 if (this.problems[i].isError()) { 156 return true; 157 } 158 } 159 return false; 160 } 161 } 162 165 public boolean hasProblems() { 166 return (this.problems != null) && (this.problems.length != 0); 167 } 168 171 public boolean hasValue() { 172 return this.displayString != null; 173 } 174 177 public boolean hasWarnings() { 178 if (this.problems == null) { 179 return false; 180 } else { 181 for (int i = 0; i < this.problems.length; i++) { 182 if (this.problems[i].isWarning()) { 183 return true; 184 } 185 } 186 return false; 187 } 188 } 189 193 public String toString() { 194 StringBuffer buffer = new StringBuffer (); 195 switch (this.evaluationType) { 196 case T_CODE_SNIPPET: 197 buffer.append("Code snippet"); break; 199 case T_IMPORT: 200 buffer.append("Import"); break; 202 case T_INTERNAL: 203 buffer.append("Internal problem"); break; 205 case T_PACKAGE: 206 buffer.append("Package"); break; 208 case T_VARIABLE: 209 buffer.append("Global variable"); break; 211 } 212 buffer.append(": "); buffer.append(this.evaluationID == null ? "<unknown>".toCharArray() : this.evaluationID); buffer.append("\n"); if (hasProblems()) { 216 buffer.append("Problems:\n"); for (int i = 0; i < this.problems.length; i++) { 218 buffer.append(this.problems[i].toString()); 219 } 220 } else { 221 if (hasValue()) { 222 buffer.append("("); buffer.append(this.typeName); 224 buffer.append(") "); buffer.append(this.displayString); 226 } else { 227 buffer.append("(No explicit return value)"); } 229 } 230 return buffer.toString(); 231 } 232 } 233 | Popular Tags |