clang  14.0.0git
RefactoringActionRule.h
Go to the documentation of this file.
1 //===--- RefactoringActionRule.h - Clang refactoring library -------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_RULE_H
10 #define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_RULE_H
11 
12 #include "clang/Basic/LLVM.h"
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/StringRef.h"
15 
16 namespace clang {
17 namespace tooling {
18 
19 class RefactoringOptionVisitor;
20 class RefactoringResultConsumer;
21 class RefactoringRuleContext;
22 
24  /// A unique identifier for the specific refactoring.
25  StringRef Name;
26  /// A human readable title for the refactoring.
27  StringRef Title;
28  /// A human readable description of what the refactoring does.
29  StringRef Description;
30 };
31 
32 /// A common refactoring action rule interface that defines the 'invoke'
33 /// function that performs the refactoring operation (either fully or
34 /// partially).
36 public:
38 
39  /// Initiates and performs a specific refactoring action.
40  ///
41  /// The specific rule will invoke an appropriate \c handle method on a
42  /// consumer to propagate the result of the refactoring action.
43  virtual void invoke(RefactoringResultConsumer &Consumer,
44  RefactoringRuleContext &Context) = 0;
45 
46  /// Returns the structure that describes the refactoring.
47  // static const RefactoringDescriptor &describe() = 0;
48 };
49 
50 /// A refactoring action rule is a wrapper class around a specific refactoring
51 /// action rule (SourceChangeRefactoringRule, etc) that, in addition to invoking
52 /// the action, describes the requirements that determine when the action can be
53 /// initiated.
55 public:
56  /// Returns true when the rule has a source selection requirement that has
57  /// to be fulfilled before refactoring can be performed.
58  virtual bool hasSelectionRequirement() = 0;
59 
60  /// Traverses each refactoring option used by the rule and invokes the
61  /// \c visit callback in the consumer for each option.
62  ///
63  /// Options are visited in the order of use, e.g. if a rule has two
64  /// requirements that use options, the options from the first requirement
65  /// are visited before the options in the second requirement.
66  virtual void visitRefactoringOptions(RefactoringOptionVisitor &Visitor) = 0;
67 };
68 
69 } // end namespace tooling
70 } // end namespace clang
71 
72 #endif // LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_ACTION_RULE_H
clang::tooling::RefactoringActionRule
A refactoring action rule is a wrapper class around a specific refactoring action rule (SourceChangeR...
Definition: RefactoringActionRule.h:54
clang::tooling::RefactoringActionRule::visitRefactoringOptions
virtual void visitRefactoringOptions(RefactoringOptionVisitor &Visitor)=0
Traverses each refactoring option used by the rule and invokes the visit callback in the consumer for...
clang::tooling::RefactoringDescriptor::Name
StringRef Name
A unique identifier for the specific refactoring.
Definition: RefactoringActionRule.h:25
clang::tooling::RefactoringDescriptor
Definition: RefactoringActionRule.h:23
clang::tooling::RefactoringActionRuleBase
A common refactoring action rule interface that defines the 'invoke' function that performs the refac...
Definition: RefactoringActionRule.h:35
clang::tooling::RefactoringActionRuleBase::~RefactoringActionRuleBase
virtual ~RefactoringActionRuleBase()
Definition: RefactoringActionRule.h:37
clang::tooling::RefactoringDescriptor::Description
StringRef Description
A human readable description of what the refactoring does.
Definition: RefactoringActionRule.h:29
clang::tooling::RefactoringDescriptor::Title
StringRef Title
A human readable title for the refactoring.
Definition: RefactoringActionRule.h:27
clang::tooling::RefactoringRuleContext
The refactoring rule context stores all of the inputs that might be needed by a refactoring action ru...
Definition: RefactoringRuleContext.h:33
LLVM.h
clang::tooling::RefactoringResultConsumer
An abstract interface that consumes the various refactoring results that can be produced by refactori...
Definition: RefactoringResultConsumer.h:24
clang
Definition: CalledOnceCheck.h:17
clang::tooling::RefactoringActionRule::hasSelectionRequirement
virtual bool hasSelectionRequirement()=0
Returns true when the rule has a source selection requirement that has to be fulfilled before refacto...
clang::tooling::RefactoringOptionVisitor
An interface that declares functions that handle different refactoring option types.
Definition: RefactoringOptionVisitor.h:25
clang::tooling::RefactoringActionRuleBase::invoke
virtual void invoke(RefactoringResultConsumer &Consumer, RefactoringRuleContext &Context)=0
Initiates and performs a specific refactoring action.