Home | History | Annotate | Download | only in Refactoring
      1 //===--- RefactoringResultConsumer.h - Clang refactoring library ----------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_RESULT_CONSUMER_H
     11 #define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_RESULT_CONSUMER_H
     12 
     13 #include "clang/Basic/LLVM.h"
     14 #include "clang/Tooling/Refactoring/AtomicChange.h"
     15 #include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h"
     16 #include "llvm/Support/Error.h"
     17 
     18 namespace clang {
     19 namespace tooling {
     20 
     21 /// An abstract interface that consumes the various refactoring results that can
     22 /// be produced by refactoring actions.
     23 ///
     24 /// A valid refactoring result must be handled by a \c handle method.
     25 class RefactoringResultConsumer {
     26 public:
     27   virtual ~RefactoringResultConsumer() {}
     28 
     29   /// Handles an initation or an invication error. An initiation error typically
     30   /// has a \c DiagnosticError payload that describes why initation failed.
     31   virtual void handleError(llvm::Error Err) = 0;
     32 
     33   /// Handles the source replacements that are produced by a refactoring action.
     34   virtual void handle(AtomicChanges SourceReplacements) {
     35     defaultResultHandler();
     36   }
     37 
     38   /// Handles the symbol occurrences that are found by an interactive
     39   /// refactoring action.
     40   virtual void handle(SymbolOccurrences Occurrences) { defaultResultHandler(); }
     41 
     42 private:
     43   void defaultResultHandler() {
     44     handleError(llvm::make_error<llvm::StringError>(
     45         "unsupported refactoring result", llvm::inconvertibleErrorCode()));
     46   }
     47 };
     48 
     49 } // end namespace tooling
     50 } // end namespace clang
     51 
     52 #endif // LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_RESULT_CONSUMER_H
     53