@@ -633,15 +633,6 @@ class TokenBasedRefactoringAction : public RefactoringAction {
633
633
}
634
634
};
635
635
636
- struct ApplicabilityContext {
637
- DiagnosticEngine &DiagEngine;
638
- SourceFile *SF;
639
- ApplicabilityContext (DiagnosticEngine &DiagEngine,
640
- SourceFile *SF):
641
- DiagEngine (DiagEngine),
642
- SF (SF) {}
643
- };
644
-
645
636
#define CURSOR_REFACTORING (KIND, NAME, ID ) \
646
637
class RefactoringAction ##KIND: public TokenBasedRefactoringAction { \
647
638
public: \
@@ -650,10 +641,9 @@ class RefactoringAction##KIND: public TokenBasedRefactoringAction { \
650
641
DiagnosticConsumer &DiagConsumer) : \
651
642
TokenBasedRefactoringAction (MD, Opts, EditConsumer, DiagConsumer) {} \
652
643
bool performChange () override ; \
653
- static bool isApplicable (ResolvedCursorInfo Tok, ApplicabilityContext &ACtx); \
644
+ static bool isApplicable (ResolvedCursorInfo Tok, DiagnosticEngine &Diag); \
654
645
bool isApplicable () { \
655
- auto Context = ApplicabilityContext (DiagEngine, TheFile); \
656
- return RefactoringAction##KIND::isApplicable (CursorInfo, Context) ; \
646
+ return RefactoringAction##KIND::isApplicable (CursorInfo, DiagEngine) ; \
657
647
} \
658
648
};
659
649
#include " swift/IDE/RefactoringKinds.def"
@@ -679,16 +669,15 @@ class RefactoringAction##KIND: public RangeBasedRefactoringAction { \
679
669
DiagnosticConsumer &DiagConsumer) : \
680
670
RangeBasedRefactoringAction (MD, Opts, EditConsumer, DiagConsumer) {} \
681
671
bool performChange () override ; \
682
- static bool isApplicable (ResolvedRangeInfo Info, ApplicabilityContext &ACtx); \
672
+ static bool isApplicable (ResolvedRangeInfo Info, DiagnosticEngine &Diag); \
683
673
bool isApplicable () { \
684
- auto Context = ApplicabilityContext (DiagEngine, TheFile); \
685
- return RefactoringAction##KIND::isApplicable (RangeInfo, Context) ; \
674
+ return RefactoringAction##KIND::isApplicable (RangeInfo, DiagEngine) ; \
686
675
} \
687
676
};
688
677
#include " swift/IDE/RefactoringKinds.def"
689
678
690
679
bool RefactoringActionLocalRename::
691
- isApplicable (ResolvedCursorInfo CursorInfo, ApplicabilityContext &ACtx ) {
680
+ isApplicable (ResolvedCursorInfo CursorInfo, DiagnosticEngine &Diag ) {
692
681
if (CursorInfo.Kind != CursorInfoKind::ValueRef)
693
682
return false ;
694
683
auto RenameOp = getAvailableRenameForDecl (CursorInfo.ValueD );
@@ -887,7 +876,7 @@ ExtractCheckResult checkExtractConditions(ResolvedRangeInfo &RangeInfo,
887
876
}
888
877
889
878
bool RefactoringActionExtractFunction::
890
- isApplicable (ResolvedRangeInfo Info, ApplicabilityContext &ACtx ) {
879
+ isApplicable (ResolvedRangeInfo Info, DiagnosticEngine &Diag ) {
891
880
switch (Info.Kind ) {
892
881
case RangeKind::PartOfExpression:
893
882
case RangeKind::SingleDecl:
@@ -896,7 +885,7 @@ isApplicable(ResolvedRangeInfo Info, ApplicabilityContext &ACtx) {
896
885
case RangeKind::SingleExpression:
897
886
case RangeKind::SingleStatement:
898
887
case RangeKind::MultiStatement: {
899
- return checkExtractConditions (Info, ACtx. DiagEngine ).
888
+ return checkExtractConditions (Info, Diag ).
900
889
success ({CannotExtractReason::VoidType});
901
890
}
902
891
}
@@ -1414,14 +1403,14 @@ bool RefactoringActionExtractExprBase::performChange() {
1414
1403
}
1415
1404
1416
1405
bool RefactoringActionExtractExpr::
1417
- isApplicable (ResolvedRangeInfo Info, ApplicabilityContext &ACtx ) {
1406
+ isApplicable (ResolvedRangeInfo Info, DiagnosticEngine &Diag ) {
1418
1407
switch (Info.Kind ) {
1419
1408
case RangeKind::SingleExpression:
1420
1409
// We disallow extract literal expression for two reasons:
1421
1410
// (1) since we print the type for extracted expression, the type of a
1422
1411
// literal may print as "int2048" where it is not typically users' choice;
1423
1412
// (2) Extracting one literal provides little value for users.
1424
- return checkExtractConditions (Info, ACtx. DiagEngine ).success ();
1413
+ return checkExtractConditions (Info, Diag ).success ();
1425
1414
case RangeKind::PartOfExpression:
1426
1415
case RangeKind::SingleDecl:
1427
1416
case RangeKind::SingleStatement:
@@ -1438,10 +1427,10 @@ bool RefactoringActionExtractExpr::performChange() {
1438
1427
}
1439
1428
1440
1429
bool RefactoringActionExtractRepeatedExpr::
1441
- isApplicable (ResolvedRangeInfo Info, ApplicabilityContext &ACtx ) {
1430
+ isApplicable (ResolvedRangeInfo Info, DiagnosticEngine &Diag ) {
1442
1431
switch (Info.Kind ) {
1443
1432
case RangeKind::SingleExpression:
1444
- return checkExtractConditions (Info, ACtx. DiagEngine ).
1433
+ return checkExtractConditions (Info, Diag ).
1445
1434
success ({CannotExtractReason::Literal});
1446
1435
case RangeKind::PartOfExpression:
1447
1436
case RangeKind::SingleDecl:
@@ -1532,7 +1521,7 @@ static CollapsibleNestedIfInfo findCollapseNestedIfTarget(ResolvedCursorInfo Cur
1532
1521
}
1533
1522
1534
1523
bool RefactoringActionCollapseNestedIfExpr::
1535
- isApplicable (ResolvedCursorInfo Tok, ApplicabilityContext &ACtx ) {
1524
+ isApplicable (ResolvedCursorInfo Tok, DiagnosticEngine &Diag ) {
1536
1525
return findCollapseNestedIfTarget (Tok).isValid ();
1537
1526
}
1538
1527
@@ -1649,7 +1638,7 @@ static void interpolatedExpressionForm(Expr *E, SourceManager &SM,
1649
1638
}
1650
1639
1651
1640
bool RefactoringActionConvertStringsConcatenationToInterpolation::
1652
- isApplicable (ResolvedRangeInfo Info, ApplicabilityContext &ACtx ) {
1641
+ isApplicable (ResolvedRangeInfo Info, DiagnosticEngine &Diag ) {
1653
1642
auto RangeContext = Info.RangeContext ;
1654
1643
if (RangeContext) {
1655
1644
auto &Ctx = Info.RangeContext ->getASTContext ();
@@ -1762,7 +1751,7 @@ getUnsatisfiedRequirements(const DeclContext *DC) {
1762
1751
}
1763
1752
1764
1753
bool RefactoringActionFillProtocolStub::
1765
- isApplicable (ResolvedCursorInfo Tok, ApplicabilityContext &ACtx ) {
1754
+ isApplicable (ResolvedCursorInfo Tok, DiagnosticEngine &Diag ) {
1766
1755
return FillProtocolStubContext::getContextFromCursorInfo (Tok).canProceed ();
1767
1756
};
1768
1757
@@ -1879,8 +1868,7 @@ static SwitchStmt* findEnclosingSwitchStmt(CaseStmt *CS,
1879
1868
}
1880
1869
1881
1870
bool RefactoringActionExpandDefault::
1882
- isApplicable (ResolvedCursorInfo CursorInfo, ApplicabilityContext &ACtx) {
1883
- auto &Diag = ACtx.DiagEngine ;
1871
+ isApplicable (ResolvedCursorInfo CursorInfo, DiagnosticEngine &Diag) {
1884
1872
auto Exit = [&](bool Applicable) {
1885
1873
if (!Applicable)
1886
1874
Diag.diagnose (SourceLoc (), diag::invalid_default_location);
@@ -1890,8 +1878,8 @@ isApplicable(ResolvedCursorInfo CursorInfo, ApplicabilityContext &ACtx) {
1890
1878
return Exit (false );
1891
1879
if (auto *CS = dyn_cast<CaseStmt>(CursorInfo.TrailingStmt )) {
1892
1880
auto EnclosingSwitchStmt = findEnclosingSwitchStmt (CS,
1893
- ACtx .SF ,
1894
- ACtx. DiagEngine );
1881
+ CursorInfo .SF ,
1882
+ Diag );
1895
1883
if (!EnclosingSwitchStmt)
1896
1884
return false ;
1897
1885
auto EnumD = getEnumDeclFromSwitchStmt (EnclosingSwitchStmt);
@@ -1917,7 +1905,7 @@ bool RefactoringActionExpandDefault::performChange() {
1917
1905
}
1918
1906
1919
1907
bool RefactoringActionExpandSwitchCases::
1920
- isApplicable (ResolvedCursorInfo CursorInfo, ApplicabilityContext &ACtx ) {
1908
+ isApplicable (ResolvedCursorInfo CursorInfo, DiagnosticEngine &DiagEngine ) {
1921
1909
if (!CursorInfo.TrailingStmt )
1922
1910
return false ;
1923
1911
if (auto *Switch = dyn_cast<SwitchStmt>(CursorInfo.TrailingStmt )) {
@@ -1978,7 +1966,7 @@ static Expr *findLocalizeTarget(ResolvedCursorInfo CursorInfo) {
1978
1966
}
1979
1967
1980
1968
bool RefactoringActionLocalizeString::
1981
- isApplicable (ResolvedCursorInfo Tok, ApplicabilityContext &ACtx ) {
1969
+ isApplicable (ResolvedCursorInfo Tok, DiagnosticEngine &Diag ) {
1982
1970
return findLocalizeTarget (Tok);
1983
1971
}
1984
1972
@@ -2022,7 +2010,7 @@ static CharSourceRange
2022
2010
}
2023
2011
2024
2012
bool RefactoringActionConvertToDoCatch::
2025
- isApplicable (ResolvedCursorInfo Tok, ApplicabilityContext &ACtx ) {
2013
+ isApplicable (ResolvedCursorInfo Tok, DiagnosticEngine &Diag ) {
2026
2014
if (!Tok.TrailingExpr )
2027
2015
return false ;
2028
2016
return isa<ForceTryExpr>(Tok.TrailingExpr );
@@ -2110,7 +2098,7 @@ static void insertUnderscoreInDigits(StringRef Digits,
2110
2098
}
2111
2099
2112
2100
bool RefactoringActionSimplifyNumberLiteral::
2113
- isApplicable (ResolvedCursorInfo Tok, ApplicabilityContext &ACtx ) {
2101
+ isApplicable (ResolvedCursorInfo Tok, DiagnosticEngine &Diag ) {
2114
2102
if (auto *Literal = getTrailingNumberLiteral (Tok)) {
2115
2103
llvm::SmallString<64 > Buffer;
2116
2104
llvm::raw_svector_ostream OS (Buffer);
@@ -2326,9 +2314,8 @@ collectAvailableRefactorings(SourceFile *SF,
2326
2314
}
2327
2315
}
2328
2316
DiagnosticEngine DiagEngine (SF->getASTContext ().SourceMgr );
2329
- auto Context = ApplicabilityContext (DiagEngine, SF);
2330
2317
#define CURSOR_REFACTORING (KIND, NAME, ID ) \
2331
- if (RefactoringAction##KIND::isApplicable (CursorInfo, Context )) \
2318
+ if (RefactoringAction##KIND::isApplicable (CursorInfo, DiagEngine )) \
2332
2319
AllKinds.push_back (RefactoringKind::KIND);
2333
2320
#include " swift/IDE/RefactoringKinds.def"
2334
2321
@@ -2364,7 +2351,6 @@ collectAvailableRefactorings(SourceFile *SF, RangeConfig Range,
2364
2351
ASTContext &Ctx = SF->getASTContext ();
2365
2352
SourceManager &SM = Ctx.SourceMgr ;
2366
2353
DiagnosticEngine DiagEngine (SM);
2367
- auto Context = ApplicabilityContext (DiagEngine, SF);
2368
2354
std::for_each (DiagConsumers.begin (), DiagConsumers.end (),
2369
2355
[&](DiagnosticConsumer *Con) { DiagEngine.addConsumer (*Con); });
2370
2356
@@ -2373,7 +2359,7 @@ collectAvailableRefactorings(SourceFile *SF, RangeConfig Range,
2373
2359
ResolvedRangeInfo Result = Resolver.resolve ();
2374
2360
2375
2361
#define RANGE_REFACTORING (KIND, NAME, ID ) \
2376
- if (RefactoringAction##KIND::isApplicable (Result, Context )) \
2362
+ if (RefactoringAction##KIND::isApplicable (Result, DiagEngine )) \
2377
2363
Scratch.push_back (RefactoringKind::KIND);
2378
2364
#include " swift/IDE/RefactoringKinds.def"
2379
2365
0 commit comments