blob: 6d0f86795bfdc40c7b35d55aa2f534b9746d18b0 [file] [log] [blame]
Yitzhak Mandelbaum9df7ce52019-05-22 18:56:18 +00001//===---------- TransformerClangTidyCheck.h - clang-tidy ------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H
11
12#include "../ClangTidy.h"
13#include "clang/ASTMatchers/ASTMatchFinder.h"
14#include "clang/Tooling/Refactoring/Transformer.h"
15#include <deque>
16#include <vector>
17
18namespace clang {
19namespace tidy {
20namespace utils {
21
22// A base class for defining a ClangTidy check based on a `RewriteRule`.
23//
24// For example, given a rule `MyCheckAsRewriteRule`, one can define a tidy check
25// as follows:
26//
27// class MyCheck : public TransformerClangTidyCheck {
28// public:
29// MyCheck(StringRef Name, ClangTidyContext *Context)
30// : TransformerClangTidyCheck(MyCheckAsRewriteRule, Name, Context) {}
31// };
32class TransformerClangTidyCheck : public ClangTidyCheck {
33public:
34 TransformerClangTidyCheck(tooling::RewriteRule R, StringRef Name,
35 ClangTidyContext *Context)
36 : ClangTidyCheck(Name, Context), Rule(std::move(R)) {}
37
38 void registerMatchers(ast_matchers::MatchFinder *Finder) final;
39 void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
40
41private:
42 tooling::RewriteRule Rule;
43};
44
45} // namespace utils
46} // namespace tidy
47} // namespace clang
48
49#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H