#include "clang/Tooling/Refactoring.h"
namespace clang {
-namespace ast_matchers {
+namespace tooling {
/// \brief Base class for RefactoringCallbacks.
///
/// Collects \c tooling::Replacements while running.
-class RefactoringCallback : public MatchFinder::MatchCallback {
+class RefactoringCallback : public ast_matchers::MatchFinder::MatchCallback {
public:
RefactoringCallback();
- tooling::Replacements &getReplacements();
+ Replacements &getReplacements();
protected:
- tooling::Replacements Replace;
+ Replacements Replace;
};
/// \brief Replace the text of the statement bound to \c FromId with the text in
class ReplaceStmtWithText : public RefactoringCallback {
public:
ReplaceStmtWithText(StringRef FromId, StringRef ToText);
- virtual void run(const MatchFinder::MatchResult &Result);
+ virtual void run(const ast_matchers::MatchFinder::MatchResult &Result);
private:
std::string FromId;
class ReplaceStmtWithStmt : public RefactoringCallback {
public:
ReplaceStmtWithStmt(StringRef FromId, StringRef ToId);
- virtual void run(const MatchFinder::MatchResult &Result);
+ virtual void run(const ast_matchers::MatchFinder::MatchResult &Result);
private:
std::string FromId;
class ReplaceIfStmtWithItsBody : public RefactoringCallback {
public:
ReplaceIfStmtWithItsBody(StringRef Id, bool PickTrueBranch);
- virtual void run(const MatchFinder::MatchResult &Result);
+ virtual void run(const ast_matchers::MatchFinder::MatchResult &Result);
private:
std::string Id;
const bool PickTrueBranch;
};
-} // end namespace ast_matchers
+} // end namespace tooling
} // end namespace clang
#endif // LLVM_CLANG_TOOLING_REFACTORING_CALLBACKS_H
#include "clang/Tooling/RefactoringCallbacks.h"
namespace clang {
-namespace ast_matchers {
+namespace tooling {
RefactoringCallback::RefactoringCallback() {}
tooling::Replacements &RefactoringCallback::getReplacements() {
return Replace;
}
-static tooling::Replacement replaceStmtWithText(SourceManager &Sources,
- const Stmt &From,
- StringRef Text) {
+static Replacement replaceStmtWithText(SourceManager &Sources,
+ const Stmt &From,
+ StringRef Text) {
return tooling::Replacement(Sources, CharSourceRange::getTokenRange(
From.getSourceRange()), Text);
}
-static tooling::Replacement replaceStmtWithStmt(SourceManager &Sources,
- const Stmt &From,
- const Stmt &To) {
+static Replacement replaceStmtWithStmt(SourceManager &Sources,
+ const Stmt &From,
+ const Stmt &To) {
return replaceStmtWithText(Sources, From, Lexer::getSourceText(
CharSourceRange::getTokenRange(To.getSourceRange()),
Sources, LangOptions()));
ReplaceStmtWithText::ReplaceStmtWithText(StringRef FromId, StringRef ToText)
: FromId(FromId), ToText(ToText) {}
-void ReplaceStmtWithText::run(const MatchFinder::MatchResult &Result) {
+void ReplaceStmtWithText::run(
+ const ast_matchers::MatchFinder::MatchResult &Result) {
if (const Stmt *FromMatch = Result.Nodes.getStmtAs<Stmt>(FromId)) {
Replace.insert(tooling::Replacement(
*Result.SourceManager,
ReplaceStmtWithStmt::ReplaceStmtWithStmt(StringRef FromId, StringRef ToId)
: FromId(FromId), ToId(ToId) {}
-void ReplaceStmtWithStmt::run(const MatchFinder::MatchResult &Result) {
+void ReplaceStmtWithStmt::run(
+ const ast_matchers::MatchFinder::MatchResult &Result) {
const Stmt *FromMatch = Result.Nodes.getStmtAs<Stmt>(FromId);
const Stmt *ToMatch = Result.Nodes.getStmtAs<Stmt>(ToId);
if (FromMatch && ToMatch)
bool PickTrueBranch)
: Id(Id), PickTrueBranch(PickTrueBranch) {}
-void ReplaceIfStmtWithItsBody::run(const MatchFinder::MatchResult &Result) {
+void ReplaceIfStmtWithItsBody::run(
+ const ast_matchers::MatchFinder::MatchResult &Result) {
if (const IfStmt *Node = Result.Nodes.getStmtAs<IfStmt>(Id)) {
const Stmt *Body = PickTrueBranch ? Node->getThen() : Node->getElse();
if (Body) {
}
}
-} // end namespace ast_matchers
+} // end namespace tooling
} // end namespace clang