aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2012-05-30 16:04:29 +0000
committerManuel Klimek <klimek@google.com>2012-05-30 16:04:29 +0000
commit5d51e8894624d5a12ed2c4fd80c31112d3d70f80 (patch)
treed45c0dd331621287f849d5c9b103b9dddc347502
parent240193b3e7e6b852134ea94353bbaf42f1495fdd (diff)
Adds a toString method to Replacement, which helps debugging.
Adds missing header guards to Refactoring.h. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157694 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Tooling/Refactoring.h9
-rw-r--r--lib/Tooling/Refactoring.cpp8
2 files changed, 17 insertions, 0 deletions
diff --git a/include/clang/Tooling/Refactoring.h b/include/clang/Tooling/Refactoring.h
index 56509a61d5..0e42a0ec64 100644
--- a/include/clang/Tooling/Refactoring.h
+++ b/include/clang/Tooling/Refactoring.h
@@ -16,6 +16,9 @@
//
//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_TOOLING_REFACTORING_H
+#define LLVM_CLANG_TOOLING_REFACTORING_H
+
#include "llvm/ADT/StringRef.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Tooling/Tooling.h"
@@ -76,6 +79,9 @@ public:
/// \brief Applies the replacement on the Rewriter.
bool apply(Rewriter &Rewrite) const;
+ /// \brief Returns a human readable string representation.
+ std::string toString() const;
+
/// \brief Comparator to be able to use Replacement in std::set for uniquing.
class Less {
public:
@@ -140,3 +146,6 @@ Replacement::Replacement(SourceManager &Sources, const Node &NodeToReplace,
} // end namespace tooling
} // end namespace clang
+
+#endif // end namespace LLVM_CLANG_TOOLING_REFACTORING_H
+
diff --git a/lib/Tooling/Refactoring.cpp b/lib/Tooling/Refactoring.cpp
index 6e90ba010c..628435307c 100644
--- a/lib/Tooling/Refactoring.cpp
+++ b/lib/Tooling/Refactoring.cpp
@@ -71,6 +71,14 @@ bool Replacement::apply(Rewriter &Rewrite) const {
return RewriteSucceeded;
}
+std::string Replacement::toString() const {
+ std::string result;
+ llvm::raw_string_ostream stream(result);
+ stream << FilePath << ": " << Offset << ":+" << Length
+ << ":\"" << ReplacementText << "\"";
+ return result;
+}
+
bool Replacement::Less::operator()(const Replacement &R1,
const Replacement &R2) const {
if (R1.FilePath != R2.FilePath) return R1.FilePath < R2.FilePath;