clang-tools 8.0.0

StringFindStartswithCheck.h
Go to the documentation of this file.
1 //===--- StringFindStartswithCheck.h - clang-tidy----------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_STRINGFINDSTARTSWITHCHECK_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_STRINGFINDSTARTSWITHCHECK_H
12
13 #include "../ClangTidy.h"
14 #include "../utils/IncludeInserter.h"
15 #include "clang/ASTMatchers/ASTMatchFinder.h"
16
17 #include <memory>
18 #include <string>
19 #include <vector>
20
21 namespace clang {
22 namespace tidy {
23 namespace abseil {
24
25 // Find string.find(...) == 0 comparisons and suggest replacing with StartsWith.
26 // FIXME(niko): Add similar check for EndsWith
27 // FIXME(niko): Add equivalent modernize checks for C++20's std::starts_With
28 class StringFindStartswithCheck : public ClangTidyCheck {
29 public:
30 using ClangTidyCheck::ClangTidyCheck;
31 StringFindStartswithCheck(StringRef Name, ClangTidyContext *Context);
32 void registerPPCallbacks(CompilerInstance &Compiler) override;
33 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
34 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
35 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
36
37 private:
38 std::unique_ptr<clang::tidy::utils::IncludeInserter> IncludeInserter;
39 const std::vector<std::string> StringLikeClasses;
40 const utils::IncludeSorter::IncludeStyle IncludeStyle;
41 const std::string AbseilStringsMatchHeader;
42 };
43
44 } // namespace abseil
45 } // namespace tidy
46 } // namespace clang
47
48 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_STRINGFINDSTARTSWITHCHECK_H
clang::tidy::abseil::StringFindStartswithCheck
Definition: StringFindStartswithCheck.h:28
clang::tidy::abseil::StringFindStartswithCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: StringFindStartswithCheck.cpp:61
clang::tidy::abseil::StringFindStartswithCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: StringFindStartswithCheck.cpp:125
clang::tidy::utils::IncludeSorter::IncludeStyle
IncludeStyle
Supported include styles.
Definition: IncludeSorter.h:27
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::abseil::StringFindStartswithCheck::StringFindStartswithCheck
StringFindStartswithCheck(StringRef Name, ClangTidyContext *Context)
Definition: StringFindStartswithCheck.cpp:25
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:98
Result
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
Definition: ClangdServer.cpp:60
clang::tidy::abseil::StringFindStartswithCheck::registerPPCallbacks
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
Definition: StringFindStartswithCheck.cpp:117
clang::tidy::ClangTidyCheck::ClangTidyCheck
ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context)
Initializes the check with CheckName and Context.
Definition: ClangTidy.h:134
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:100
clang::tidy::abseil::StringFindStartswithCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: StringFindStartswithCheck.cpp:35