10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
20 void AvoidThrowingObjCExceptionCheck::registerMatchers(MatchFinder *Finder) {
22 Finder->addMatcher(objcThrowStmt().bind(
"throwStmt"),
this);
24 objcMessageExpr(anyOf(hasSelector(
"raise:format:"),
25 hasSelector(
"raise:format:arguments:")),
26 hasReceiverType(asString(
"NSException")))
27 .bind(
"raiseException"),
31 void AvoidThrowingObjCExceptionCheck::check(
32 const MatchFinder::MatchResult &Result) {
33 const auto *MatchedStmt =
34 Result.Nodes.getNodeAs<ObjCAtThrowStmt>(
"throwStmt");
35 const auto *MatchedExpr =
36 Result.Nodes.getNodeAs<ObjCMessageExpr>(
"raiseException");
37 auto SourceLoc = MatchedStmt ==
nullptr ? MatchedExpr->getSelectorStartLoc()
38 : MatchedStmt->getThrowLoc();
40 "pass in NSError ** instead of throwing exception to indicate "
41 "Objective-C errors");