Skip to content

Commit 83382c5

Browse files
committed
migrator: rename a property declaration if the framework property it overrides has been renamed.
1 parent c4bf8fd commit 83382c5

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,19 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
14041404
D->walk(Removal);
14051405
}
14061406
}
1407+
1408+
// Handle property overriding migration.
1409+
if (auto *VD = dyn_cast<VarDecl>(D)) {
1410+
for (auto *Item: getRelatedDiffItems(VD)) {
1411+
if (auto *CD = dyn_cast<CommonDiffItem>(Item)) {
1412+
// If the overriden property has been renamed, we should rename
1413+
// this property decl as well.
1414+
if (CD->isRename() && VD->getNameLoc().isValid()) {
1415+
Editor.replaceToken(VD->getNameLoc(), CD->getNewName());
1416+
}
1417+
}
1418+
}
1419+
}
14071420
return true;
14081421
}
14091422
};

test/Migrator/Inputs/API.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,5 +539,16 @@
539539
"RightUsr": "",
540540
"RightComment": "FontWeighting",
541541
"ModuleName": "Cities"
542-
}
542+
},
543+
{
544+
"DiffItemKind": "CommonDiffItem",
545+
"NodeKind": "Var",
546+
"NodeAnnotation": "Rename",
547+
"ChildIndex": "0",
548+
"LeftUsr": "s:6CitiesAAC6yogurtSivp",
549+
"LeftComment": "yogurt",
550+
"RightUsr": "",
551+
"RightComment": "cheese",
552+
"ModuleName": "Cities"
553+
},
543554
]

test/Migrator/Inputs/Cities.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ open class Cities {
99
open func buderim() -> Cities? { return Cities(x: 1) }
1010
open func noosa() -> [[String : Cities]?] { return [] }
1111
open func maroochy(x: Int?, y: Int?) {}
12+
open var yogurt: Int { return 1 }
1213
public struct CityKind {
1314
public static let Town = 1
1415
public static let Village = 1

test/Migrator/rename-func-decl.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ class MySubTopLevelType: ToplevelType {
1818
class MySubTopLevelType2: ToplevelType {
1919
override func member(_ x: @escaping (((([(Any)])?))) -> Void) {}
2020
}
21+
22+
class SubCities: Cities {
23+
override var yogurt: Int { return 2 }
24+
}

test/Migrator/rename-func-decl.swift.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ class MySubTopLevelType: ToplevelType {
1818
class MySubTopLevelType2: ToplevelType {
1919
override func member(_ x: @escaping (((([(Int)])?))) -> Void) {}
2020
}
21+
22+
class SubCities: Cities {
23+
override var cheese: Int { return 2 }
24+
}

0 commit comments

Comments
 (0)