11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 35 return Node.getMethodFamily() == OMF_init;
58 ast_matchers::internal::Matcher<ObjCInterfaceDecl>,
61 for (
const ObjCInterfaceDecl *SuperClass =
62 Node.getClassInterface()->getSuperClass();
63 SuperClass !=
nullptr; SuperClass = SuperClass->getSuperClass()) {
64 if (InterfaceDecl.matches(*SuperClass, Finder,
Builder))
84 AST_MATCHER(ObjCMessageExpr, isMessagingSuperInstance) {
85 return Node.getReceiverKind() == ObjCMessageExpr::SuperInstance;
90 void SuperSelfCheck::registerMatchers(MatchFinder *Finder) {
92 if (!getLangOpts().ObjC)
97 hasSelector(
"self"), isMessagingSuperInstance(),
98 hasAncestor(objcMethodDecl(isInitializer(),
99 hasDeclContext(objcImplementationDecl(
100 isSubclassOf(hasName(
"NSObject")))))))
105 void SuperSelfCheck::check(
const MatchFinder::MatchResult &
Result) {
106 const auto *
Message = Result.Nodes.getNodeAs<ObjCMessageExpr>(
"message");
108 auto Diag = diag(
Message->getExprLoc(),
"suspicious invocation of %0 in " 109 "initializer; did you mean to " 110 "invoke a superclass initializer?")
113 SourceLocation ReceiverLoc =
Message->getReceiverRange().getBegin();
114 if (ReceiverLoc.isMacroID() || ReceiverLoc.isInvalid())
117 SourceLocation SelectorLoc =
Message->getSelectorStartLoc();
118 if (SelectorLoc.isMacroID() || SelectorLoc.isInvalid())
121 Diag << FixItHint::CreateReplacement(
Message->getSourceRange(),
122 StringRef(
"[super init]"));
AST_MATCHER(Expr, isMacroID)
constexpr llvm::StringLiteral Message
CodeCompletionBuilder Builder
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl, ast_matchers::internal::Matcher< CXXMethodDecl >, InnerMatcher)