]> granicus.if.org Git - clang/commitdiff
Adds a toString method to Replacement, which helps debugging.
authorManuel Klimek <klimek@google.com>
Wed, 30 May 2012 16:04:29 +0000 (16:04 +0000)
committerManuel Klimek <klimek@google.com>
Wed, 30 May 2012 16:04:29 +0000 (16:04 +0000)
Adds missing header guards to Refactoring.h.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157694 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Tooling/Refactoring.h
lib/Tooling/Refactoring.cpp

index 56509a61d59600ca9117cea8c2e88b78b8082046..0e42a0ec64fc485dab851be5c0acc651acbe0241 100644 (file)
@@ -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
+
index 6e90ba010cbde5ebd41cc427edf6029f3ae306cd..628435307c0bef2f1ead44564f5fcba7112d276e 100644 (file)
@@ -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;