1 26 27 package org.objectweb.openccm.parser.lib; 28 29 import org.objectweb.openccm.ast.api.Declaration; 31 import org.objectweb.openccm.ast.api.WithDeclarators; 32 33 41 42 public class ErrorManager 43 { 44 50 53 private String fileName_; 54 55 58 private int nbWarnings_; 59 60 63 private int nbErrors_; 64 65 71 76 public 77 ErrorManager(String fileName) 78 { 79 fileName_ = fileName; 81 nbWarnings_ = 0; 82 nbErrors_ = 0; 83 } 84 85 91 99 protected void 100 log(int line, String kind, String text) 101 { 102 System.out.println(fileName_ + ':' + line + ": " + kind + ": " + text); 103 } 104 105 111 116 public int 117 getNbWarnings() 118 { 119 return nbWarnings_; 120 } 121 122 127 public int 128 getNbErrors() 129 { 130 return nbErrors_; 131 } 132 133 138 public String 139 getFileName() 140 { 141 return fileName_; 142 } 143 144 149 public void 150 setFileName(String fileName) 151 { 152 fileName_ = fileName; 153 } 154 155 161 public void 162 warning(int line, String text) 163 { 164 log(line, "warning", text); 165 nbWarnings_ ++; 166 } 167 168 174 public void 175 error(int line, String text) 176 { 177 log(line, "error", text); 178 nbErrors_ ++; 179 } 180 181 188 public void 189 error(int line, String text, Exception exc) 190 { 191 error(line, text); 192 exc.printStackTrace(); 193 } 194 195 201 public void 202 error(int line, org.omg.CORBA.SystemException sysExc) 203 { 204 error(line, sysExc, null); 205 } 206 207 214 public void 215 error(int line, 216 org.omg.CORBA.SystemException sysExc, 217 Declaration decl) 218 { 219 int minor = sysExc.minor; 220 221 if(sysExc instanceof org.omg.CORBA.BAD_PARAM ) 222 { 223 switch(minor) 224 { 225 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.RidAlreadyDefined: 226 error(line, '`' + decl.getId() + 227 "' already defined in the IFR"); 228 return; 229 230 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NameAlreadyUsed: 231 error(line, '`' + decl.getName() + 232 "' already defined in the context"); 233 return; 234 235 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.InvalidContainer: 236 error(line, "Target is an invalid container"); 237 return; 238 239 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NameClashInInheritedContext: 240 error(line, '`' + decl.getName() + 241 "' already defined in inherited context"); 242 return; 243 244 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.InvalidAbstractInterfaceInheritance: 245 error(line, "invalid abstract interface inheritance"); 246 return; 247 248 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.InvalidLocalInterfaceInheritance: 249 error(line, "invalid local interface inheritance"); 250 return; 251 252 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NotLocalObject: 253 return; 255 256 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NameAlreadyUsedByImmediateScope: 257 error(line, '`' + decl.getName() + 258 "' already used by immediate scope"); 259 return; 260 261 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NeedOnlyInParams: 262 error(line, '`' + decl.getName() + 263 "' only needs in parameters"); 264 return; 265 266 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NoExceptionsForOnewayOperation: 267 error(line, '`' + decl.getName() + 268 "' no exceptions expected for oneway operation"); 269 return; 270 271 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.InvalidValueBoxType: 272 error(line, '`' + decl.getName() + 273 "' invalid valuebox type"); 274 return; 275 } 276 277 if (minor >= org.objectweb.openccm.ir3.SystemExceptionMinorValues.DuplicateDeclarator) 278 { 279 int index = minor - org.objectweb.openccm.ir3.SystemExceptionMinorValues.DuplicateDeclarator; 280 error(line, '`' + ((WithDeclarators)decl).declaratorAt(index) + 281 "' duplicate declarator in " + decl.getAbsoluteName()); 282 return; 283 } 284 285 } 286 287 if(sysExc instanceof org.omg.CORBA.BAD_INV_ORDER ) 288 { 289 switch(minor) 290 { 291 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.Dependency: 292 error(line, "dependency exits in IFR preventing destruction"); 293 return; 294 295 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.CanNotBeDestroyed: 296 error(line, "indestructible object"); 297 return; 298 } 299 } 300 301 if(sysExc instanceof org.omg.CORBA.INTF_REPOS ) 302 { 303 switch(minor) 304 { 305 case org.objectweb.openccm.ir3.SystemExceptionMinorValues.AmbiguousLookup: 306 error(line, "ambiguous lookup"); 307 return; 308 } 309 } 310 311 if (decl != null) 312 error(line, sysExc.toString() + " on " + decl.getAbsoluteName()); 313 else 314 error(line, sysExc.toString()); 315 316 sysExc.printStackTrace(); 317 } 318 } 319 | Popular Tags |