private void buildExceptions(Element element, CtBehavior method) throws NotFoundException { CtClass[] exceptions = method.getExceptionTypes(); for (int k = 0; k < exceptions.length; k++) { Element exceptElement = document.createElement("exception"); addAttribute(exceptElement, "name", exceptions[k].getName()); element.appendChild(exceptElement); } }
private boolean compareThrows(CtBehavior refMethod, CtBehavior implMethod, String className) throws NotFoundException { List refNames = new Vector(); CtClass[] refExceptions = refMethod.getExceptionTypes(); for (int i = 0; i < refExceptions.length; i++) { refNames.add(refExceptions[i].getName()); } boolean ch = false; List implNames = new Vector(); CtClass[] implExceptions = implMethod.getExceptionTypes(); for (int i = 0; i < implExceptions.length; i++) { implNames.add(implExceptions[i].getName()); String exceptionName = implExceptions[i].getName(); ch |= assertTrue(className + " " + refMethod.getName() + refMethod.getSignature() + " should not throw " + exceptionName, refNames.contains(exceptionName)); } if (!config.allowThrowsLess) { for (int i = 0; i < refExceptions.length; i++) { String exceptionName = refExceptions[i].getName(); ch |= assertTrue(className + " " + refMethod.getName() + refMethod.getSignature() + " should throw " + exceptionName, implNames.contains(exceptionName)); } } return ch; }
CtClass[] exceptions = _method.getExceptionTypes();
public ClassInfo[] getExceptionTypes() { if (exceptionTypes == null) { try { CtClass[] types = ctBehavior.getExceptionTypes(); ClassInfo[] exceptionTypes = new ClassInfo[types.length]; for (int i = 0; i < types.length; ++i) exceptionTypes[i] = (ClassInfo) typeInfo.getFactory().getTypeInfo(types[i]); this.exceptionTypes = exceptionTypes; } catch (NotFoundException e) { throw JavassistTypeInfoFactoryImpl.raiseClassNotFound("for exception types of constructor", e); } } return exceptionTypes; }