mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Refactoring] Move some more code from RefactoringActions.h to a .cpp file
This commit is contained in:
@@ -12,10 +12,10 @@ add_swift_host_library(swiftRefactoring STATIC
|
||||
Async/ScopedDeclCollector.cpp
|
||||
Async/Utils.cpp
|
||||
CollapseNestedIfStmt.cpp
|
||||
ConvertStringConcatenationToInterpolation.cpp
|
||||
ConvertToComputedProperty.cpp
|
||||
ConvertGuardExprToIfLetExpr.cpp
|
||||
ConvertIfLetExprToGuardExpr.cpp
|
||||
ConvertStringConcatenationToInterpolation.cpp
|
||||
ConvertToComputedProperty.cpp
|
||||
ConvertToDoCatch.cpp
|
||||
ConvertToSwitchStmt.cpp
|
||||
ConvertToTernaryExpr.cpp
|
||||
@@ -24,8 +24,8 @@ add_swift_host_library(swiftRefactoring STATIC
|
||||
ExpandTernaryExpr.cpp
|
||||
ExtractExpr.cpp
|
||||
ExtractExprBase.cpp
|
||||
ExtractRepeatedExpr.cpp
|
||||
ExtractFunction.cpp
|
||||
ExtractRepeatedExpr.cpp
|
||||
FillProtocolStubs.cpp
|
||||
FindRenameRangesAnnotatingConsumer.cpp
|
||||
LocalizeString.cpp
|
||||
@@ -33,6 +33,7 @@ add_swift_host_library(swiftRefactoring STATIC
|
||||
MemberwiseInitLocalRefactoring.cpp
|
||||
MoveMembersToExtension.cpp
|
||||
Refactoring.cpp
|
||||
RefactoringAction.cpp
|
||||
Renamer.cpp
|
||||
ReplaceBodiesWithFatalError.cpp
|
||||
SimplifyNumberLiteral.cpp
|
||||
|
||||
55
lib/Refactoring/RefactoringAction.cpp
Normal file
55
lib/Refactoring/RefactoringAction.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "RefactoringActions.h"
|
||||
|
||||
using namespace swift::refactoring;
|
||||
|
||||
/// Get the source file that corresponds to the given buffer.
|
||||
SourceFile *getContainingFile(ModuleDecl *M, RangeConfig Range) {
|
||||
auto &SM = M->getASTContext().SourceMgr;
|
||||
// TODO: We should add an ID -> SourceFile mapping.
|
||||
return M->getSourceFileContainingLocation(
|
||||
SM.getRangeForBuffer(Range.BufferID).getStart());
|
||||
}
|
||||
|
||||
RefactoringAction::RefactoringAction(ModuleDecl *MD, RefactoringOptions &Opts,
|
||||
SourceEditConsumer &EditConsumer,
|
||||
DiagnosticConsumer &DiagConsumer)
|
||||
: MD(MD), TheFile(getContainingFile(MD, Opts.Range)),
|
||||
EditConsumer(EditConsumer), Ctx(MD->getASTContext()),
|
||||
SM(MD->getASTContext().SourceMgr), DiagEngine(SM),
|
||||
StartLoc(Lexer::getLocForStartOfToken(SM, Opts.Range.getStart(SM))),
|
||||
PreferredName(Opts.PreferredName) {
|
||||
DiagEngine.addConsumer(DiagConsumer);
|
||||
}
|
||||
|
||||
TokenBasedRefactoringAction::TokenBasedRefactoringAction(
|
||||
ModuleDecl *MD, RefactoringOptions &Opts, SourceEditConsumer &EditConsumer,
|
||||
DiagnosticConsumer &DiagConsumer)
|
||||
: RefactoringAction(MD, Opts, EditConsumer, DiagConsumer) {
|
||||
// Resolve the sema token and save it for later use.
|
||||
CursorInfo =
|
||||
evaluateOrDefault(TheFile->getASTContext().evaluator,
|
||||
CursorInfoRequest{CursorInfoOwner(TheFile, StartLoc)},
|
||||
new ResolvedCursorInfo());
|
||||
}
|
||||
|
||||
RangeBasedRefactoringAction::RangeBasedRefactoringAction(
|
||||
ModuleDecl *MD, RefactoringOptions &Opts, SourceEditConsumer &EditConsumer,
|
||||
DiagnosticConsumer &DiagConsumer)
|
||||
: RefactoringAction(MD, Opts, EditConsumer, DiagConsumer),
|
||||
RangeInfo(evaluateOrDefault(
|
||||
MD->getASTContext().evaluator,
|
||||
RangeInfoRequest(RangeInfoOwner(TheFile, Opts.Range.getStart(SM),
|
||||
Opts.Range.getEnd(SM))),
|
||||
ResolvedRangeInfo())) {}
|
||||
@@ -25,17 +25,6 @@ namespace refactoring {
|
||||
using namespace swift;
|
||||
using namespace swift::ide;
|
||||
|
||||
namespace {
|
||||
|
||||
/// Get the source file that corresponds to the given buffer.
|
||||
SourceFile *getContainingFile(ModuleDecl *M, RangeConfig Range) {
|
||||
auto &SM = M->getASTContext().SourceMgr;
|
||||
// TODO: We should add an ID -> SourceFile mapping.
|
||||
return M->getSourceFileContainingLocation(
|
||||
SM.getRangeForBuffer(Range.BufferID).getStart());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
class RefactoringAction {
|
||||
protected:
|
||||
ModuleDecl *MD;
|
||||
@@ -50,14 +39,7 @@ protected:
|
||||
public:
|
||||
RefactoringAction(ModuleDecl *MD, RefactoringOptions &Opts,
|
||||
SourceEditConsumer &EditConsumer,
|
||||
DiagnosticConsumer &DiagConsumer)
|
||||
: MD(MD), TheFile(getContainingFile(MD, Opts.Range)),
|
||||
EditConsumer(EditConsumer), Ctx(MD->getASTContext()),
|
||||
SM(MD->getASTContext().SourceMgr), DiagEngine(SM),
|
||||
StartLoc(Lexer::getLocForStartOfToken(SM, Opts.Range.getStart(SM))),
|
||||
PreferredName(Opts.PreferredName) {
|
||||
DiagEngine.addConsumer(DiagConsumer);
|
||||
}
|
||||
DiagnosticConsumer &DiagConsumer);
|
||||
virtual ~RefactoringAction() = default;
|
||||
virtual bool performChange() = 0;
|
||||
};
|
||||
@@ -73,14 +55,7 @@ protected:
|
||||
public:
|
||||
TokenBasedRefactoringAction(ModuleDecl *MD, RefactoringOptions &Opts,
|
||||
SourceEditConsumer &EditConsumer,
|
||||
DiagnosticConsumer &DiagConsumer)
|
||||
: RefactoringAction(MD, Opts, EditConsumer, DiagConsumer) {
|
||||
// Resolve the sema token and save it for later use.
|
||||
CursorInfo =
|
||||
evaluateOrDefault(TheFile->getASTContext().evaluator,
|
||||
CursorInfoRequest{CursorInfoOwner(TheFile, StartLoc)},
|
||||
new ResolvedCursorInfo());
|
||||
}
|
||||
DiagnosticConsumer &DiagConsumer);
|
||||
};
|
||||
|
||||
#define CURSOR_REFACTORING(KIND, NAME, ID) \
|
||||
@@ -106,13 +81,7 @@ protected:
|
||||
public:
|
||||
RangeBasedRefactoringAction(ModuleDecl *MD, RefactoringOptions &Opts,
|
||||
SourceEditConsumer &EditConsumer,
|
||||
DiagnosticConsumer &DiagConsumer)
|
||||
: RefactoringAction(MD, Opts, EditConsumer, DiagConsumer),
|
||||
RangeInfo(evaluateOrDefault(
|
||||
MD->getASTContext().evaluator,
|
||||
RangeInfoRequest(RangeInfoOwner(TheFile, Opts.Range.getStart(SM),
|
||||
Opts.Range.getEnd(SM))),
|
||||
ResolvedRangeInfo())) {}
|
||||
DiagnosticConsumer &DiagConsumer);
|
||||
};
|
||||
|
||||
#define RANGE_REFACTORING(KIND, NAME, ID) \
|
||||
|
||||
Reference in New Issue
Block a user