|
1 |
| -//===--- Refactoring.cpp ---------------------------------------------------===// |
| 1 | +//===----------------------------------------------------------------------===// |
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift.org open source project
|
4 | 4 | //
|
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | #include "swift/Refactoring/Refactoring.h"
|
| 14 | +#include "RefactoringActions.h" |
14 | 15 | #include "swift/AST/ASTContext.h"
|
15 | 16 | #include "swift/AST/ASTPrinter.h"
|
16 | 17 | #include "swift/AST/Decl.h"
|
|
41 | 42 | using namespace swift;
|
42 | 43 | using namespace swift::ide;
|
43 | 44 | using namespace swift::index;
|
44 |
| - |
45 |
| -namespace { |
| 45 | +using namespace swift::refactoring; |
46 | 46 |
|
47 | 47 | class ContextFinder : public SourceEntityWalker {
|
48 | 48 | SourceFile &SF;
|
@@ -855,110 +855,6 @@ RenameRangeCollector::indexSymbolToRenameLoc(const index::IndexSymbol &symbol,
|
855 | 855 | isFunctionLike, isNonProtocolType};
|
856 | 856 | }
|
857 | 857 |
|
858 |
| -/// Get the source file that corresponds to the given buffer. |
859 |
| -SourceFile *getContainingFile(ModuleDecl *M, RangeConfig Range) { |
860 |
| - auto &SM = M->getASTContext().SourceMgr; |
861 |
| - // TODO: We should add an ID -> SourceFile mapping. |
862 |
| - return M->getSourceFileContainingLocation( |
863 |
| - SM.getRangeForBuffer(Range.BufferID).getStart()); |
864 |
| -} |
865 |
| - |
866 |
| -class RefactoringAction { |
867 |
| -protected: |
868 |
| - ModuleDecl *MD; |
869 |
| - SourceFile *TheFile; |
870 |
| - SourceEditConsumer &EditConsumer; |
871 |
| - ASTContext &Ctx; |
872 |
| - SourceManager &SM; |
873 |
| - DiagnosticEngine DiagEngine; |
874 |
| - SourceLoc StartLoc; |
875 |
| - StringRef PreferredName; |
876 |
| -public: |
877 |
| - RefactoringAction(ModuleDecl *MD, RefactoringOptions &Opts, |
878 |
| - SourceEditConsumer &EditConsumer, |
879 |
| - DiagnosticConsumer &DiagConsumer); |
880 |
| - virtual ~RefactoringAction() = default; |
881 |
| - virtual bool performChange() = 0; |
882 |
| -}; |
883 |
| - |
884 |
| -RefactoringAction:: |
885 |
| -RefactoringAction(ModuleDecl *MD, RefactoringOptions &Opts, |
886 |
| - SourceEditConsumer &EditConsumer, |
887 |
| - DiagnosticConsumer &DiagConsumer): MD(MD), |
888 |
| - TheFile(getContainingFile(MD, Opts.Range)), |
889 |
| - EditConsumer(EditConsumer), Ctx(MD->getASTContext()), |
890 |
| - SM(MD->getASTContext().SourceMgr), DiagEngine(SM), |
891 |
| - StartLoc(Lexer::getLocForStartOfToken(SM, Opts.Range.getStart(SM))), |
892 |
| - PreferredName(Opts.PreferredName) { |
893 |
| - DiagEngine.addConsumer(DiagConsumer); |
894 |
| -} |
895 |
| - |
896 |
| -/// Different from RangeBasedRefactoringAction, TokenBasedRefactoringAction takes |
897 |
| -/// the input of a given token, e.g., a name or an "if" key word. Contextual |
898 |
| -/// refactoring kinds can suggest applicable refactorings on that token, e.g. |
899 |
| -/// rename or reverse if statement. |
900 |
| -class TokenBasedRefactoringAction : public RefactoringAction { |
901 |
| -protected: |
902 |
| - ResolvedCursorInfoPtr CursorInfo; |
903 |
| - |
904 |
| -public: |
905 |
| - TokenBasedRefactoringAction(ModuleDecl *MD, RefactoringOptions &Opts, |
906 |
| - SourceEditConsumer &EditConsumer, |
907 |
| - DiagnosticConsumer &DiagConsumer) : |
908 |
| - RefactoringAction(MD, Opts, EditConsumer, DiagConsumer) { |
909 |
| - // Resolve the sema token and save it for later use. |
910 |
| - CursorInfo = |
911 |
| - evaluateOrDefault(TheFile->getASTContext().evaluator, |
912 |
| - CursorInfoRequest{CursorInfoOwner(TheFile, StartLoc)}, |
913 |
| - new ResolvedCursorInfo()); |
914 |
| - } |
915 |
| -}; |
916 |
| - |
917 |
| -#define CURSOR_REFACTORING(KIND, NAME, ID) \ |
918 |
| - class RefactoringAction##KIND : public TokenBasedRefactoringAction { \ |
919 |
| - public: \ |
920 |
| - RefactoringAction##KIND(ModuleDecl *MD, RefactoringOptions &Opts, \ |
921 |
| - SourceEditConsumer &EditConsumer, \ |
922 |
| - DiagnosticConsumer &DiagConsumer) \ |
923 |
| - : TokenBasedRefactoringAction(MD, Opts, EditConsumer, DiagConsumer) {} \ |
924 |
| - bool performChange() override; \ |
925 |
| - static bool isApplicable(ResolvedCursorInfoPtr Info, \ |
926 |
| - DiagnosticEngine &Diag); \ |
927 |
| - bool isApplicable() { \ |
928 |
| - return RefactoringAction##KIND::isApplicable(CursorInfo, DiagEngine); \ |
929 |
| - } \ |
930 |
| - }; |
931 |
| -#include "swift/Refactoring/RefactoringKinds.def" |
932 |
| - |
933 |
| -class RangeBasedRefactoringAction : public RefactoringAction { |
934 |
| -protected: |
935 |
| - ResolvedRangeInfo RangeInfo; |
936 |
| -public: |
937 |
| - RangeBasedRefactoringAction(ModuleDecl *MD, RefactoringOptions &Opts, |
938 |
| - SourceEditConsumer &EditConsumer, |
939 |
| - DiagnosticConsumer &DiagConsumer) : |
940 |
| - RefactoringAction(MD, Opts, EditConsumer, DiagConsumer), |
941 |
| - RangeInfo(evaluateOrDefault(MD->getASTContext().evaluator, |
942 |
| - RangeInfoRequest(RangeInfoOwner(TheFile, Opts.Range.getStart(SM), Opts.Range.getEnd(SM))), |
943 |
| - ResolvedRangeInfo())) {} |
944 |
| -}; |
945 |
| - |
946 |
| -#define RANGE_REFACTORING(KIND, NAME, ID) \ |
947 |
| -class RefactoringAction##KIND: public RangeBasedRefactoringAction { \ |
948 |
| - public: \ |
949 |
| - RefactoringAction##KIND(ModuleDecl *MD, RefactoringOptions &Opts, \ |
950 |
| - SourceEditConsumer &EditConsumer, \ |
951 |
| - DiagnosticConsumer &DiagConsumer) : \ |
952 |
| - RangeBasedRefactoringAction(MD, Opts, EditConsumer, DiagConsumer) {} \ |
953 |
| - bool performChange() override; \ |
954 |
| - static bool isApplicable(const ResolvedRangeInfo &Info, \ |
955 |
| - DiagnosticEngine &Diag); \ |
956 |
| - bool isApplicable() { \ |
957 |
| - return RefactoringAction##KIND::isApplicable(RangeInfo, DiagEngine) ; \ |
958 |
| - } \ |
959 |
| -}; |
960 |
| -#include "swift/Refactoring/RefactoringKinds.def" |
961 |
| - |
962 | 858 | bool RefactoringActionLocalRename::isApplicable(
|
963 | 859 | ResolvedCursorInfoPtr CursorInfo, DiagnosticEngine &Diag) {
|
964 | 860 | llvm::Optional<RenameInfo> Info = getRenameInfo(CursorInfo);
|
@@ -8801,8 +8697,6 @@ bool RefactoringActionInlineMacro::performChange() {
|
8801 | 8697 | return expandMacro(SM, CursorInfo, EditConsumer, /*adjustExpansion=*/true);
|
8802 | 8698 | }
|
8803 | 8699 |
|
8804 |
| -} // end of anonymous namespace |
8805 |
| - |
8806 | 8700 | StringRef swift::ide::
|
8807 | 8701 | getDescriptiveRefactoringKindName(RefactoringKind Kind) {
|
8808 | 8702 | switch(Kind) {
|
|
0 commit comments