2

I am writing a clang-tidy check to automate renaming of some variables of a certain type. I can successfully match their declarations with matcher varDecl(hasType(asString("class MyType"))). But then I want to rename these variables and their usages. If I use FixItHint::CreateReplacement(), it only replaces names in the declarations, but not in all usages.

I found a RenamerClangTidyCheck, which seems to be exactly what I need:

/// Base class for clang-tidy checks that want to flag declarations and/or
/// macros for renaming based on customizable criteria.

However, it is customized by overriding virtual functions like getDeclFailureInfo(), which are called from ClangTidyCheck::check() function and they do not have any matchers at hand, they operate with NamedDecl. I am only interested in variables declarations, so I can cast it down to VarDecl, but then how I make sure this particular VarDecl corresponds to a variable with type MyType?

Mikhail
  • 20,685
  • 7
  • 70
  • 146

0 Answers0