10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
32 return Node.getMethodFamily() == OMF_init;
51 ast_matchers::internal::Matcher<ObjCInterfaceDecl>, Base) {
52 const ObjCInterfaceDecl *InterfaceDecl =
Node.getClassInterface();
53 return Base.matches(*InterfaceDecl, Finder,
Builder);
68AST_MATCHER(ObjCMessageExpr, isMessagingSuperInstance) {
69 return Node.getReceiverKind() == ObjCMessageExpr::SuperInstance;
76 objcMessageExpr(hasSelector(
"self"), isMessagingSuperInstance(),
77 hasAncestor(objcMethodDecl(
79 hasDeclContext(objcImplementationDecl(hasInterface(
80 isDerivedFrom(hasName(
"NSObject"))))))))
86 const auto *Message = Result.Nodes.getNodeAs<ObjCMessageExpr>(
"message");
88 auto Diag =
diag(Message->getExprLoc(),
"suspicious invocation of %0 in "
89 "initializer; did you mean to "
90 "invoke a superclass initializer?")
91 << Message->getMethodDecl();
93 SourceLocation ReceiverLoc = Message->getReceiverRange().getBegin();
94 if (ReceiverLoc.isMacroID() || ReceiverLoc.isInvalid())
97 SourceLocation SelectorLoc = Message->getSelectorStartLoc();
98 if (SelectorLoc.isMacroID() || SelectorLoc.isInvalid())
101 Diag << FixItHint::CreateReplacement(Message->getSourceRange(),
102 StringRef(
"[super init]"));
CodeCompletionBuilder Builder
::clang::DynTypedNode Node
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
AST_MATCHER_P(UserDefinedLiteral, hasLiteral, clang::ast_matchers::internal::Matcher< Expr >, InnerMatcher)
AST_MATCHER(Decl, declHasNoReturnAttr)
matches a Decl if it has a "no return" attribute of any kind