10#include "../utils/OptionsUtils.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13#include "llvm/ADT/Hashing.h"
14#include "llvm/ADT/SmallVector.h"
22constexpr char DefaultForbiddenSuperClassNames[] =
23 "ABNewPersonViewController;"
24 "ABPeoplePickerNavigationController;"
25 "ABPersonViewController;"
26 "ABUnknownPersonViewController;"
34 "UIImagePickerController;"
44 ForbiddenSuperClassNames(
45 utils::options::parseStringList(
46 Options.get(
"ClassNames", DefaultForbiddenSuperClassNames))) {
52 isDerivedFrom(objcInterfaceDecl(hasAnyName(ForbiddenSuperClassNames))
59 const MatchFinder::MatchResult &Result) {
60 const auto *SubClass = Result.Nodes.getNodeAs<ObjCInterfaceDecl>(
62 assert(SubClass !=
nullptr);
63 const auto *SuperClass = Result.Nodes.getNodeAs<ObjCInterfaceDecl>(
65 assert(SuperClass !=
nullptr);
66 diag(SubClass->getLocation(),
67 "Objective-C interface %0 subclasses %1, which is not "
68 "intended to be subclassed")
77 "ForbiddenSuperClassNames",
llvm::SmallString< 256U > Name
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
Base class for all clang-tidy checks.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
ForbiddenSubclassingCheck(StringRef Name, ClangTidyContext *Context)
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
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.
std::string serializeStringList(ArrayRef< StringRef > Strings)
Serialize a sequence of names that can be parsed by parseStringList.
llvm::StringMap< ClangTidyValue > OptionMap