Skip to content

Commit

Permalink
migrator: rename a property declaration if the framework property it …
Browse files Browse the repository at this point in the history
…overrides has been renamed.
  • Loading branch information
nkcsgexi committed Dec 19, 2018
1 parent c4bf8fd commit 83382c5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/Migrator/APIDiffMigratorPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,19 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
D->walk(Removal);
}
}

// Handle property overriding migration.
if (auto *VD = dyn_cast<VarDecl>(D)) {
for (auto *Item: getRelatedDiffItems(VD)) {
if (auto *CD = dyn_cast<CommonDiffItem>(Item)) {
// If the overriden property has been renamed, we should rename
// this property decl as well.
if (CD->isRename() && VD->getNameLoc().isValid()) {
Editor.replaceToken(VD->getNameLoc(), CD->getNewName());
}
}
}
}
return true;
}
};
Expand Down
13 changes: 12 additions & 1 deletion test/Migrator/Inputs/API.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,5 +539,16 @@
"RightUsr": "",
"RightComment": "FontWeighting",
"ModuleName": "Cities"
}
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Var",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "s:6CitiesAAC6yogurtSivp",
"LeftComment": "yogurt",
"RightUsr": "",
"RightComment": "cheese",
"ModuleName": "Cities"
},
]
1 change: 1 addition & 0 deletions test/Migrator/Inputs/Cities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open class Cities {
open func buderim() -> Cities? { return Cities(x: 1) }
open func noosa() -> [[String : Cities]?] { return [] }
open func maroochy(x: Int?, y: Int?) {}
open var yogurt: Int { return 1 }
public struct CityKind {
public static let Town = 1
public static let Village = 1
Expand Down
4 changes: 4 additions & 0 deletions test/Migrator/rename-func-decl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ class MySubTopLevelType: ToplevelType {
class MySubTopLevelType2: ToplevelType {
override func member(_ x: @escaping (((([(Any)])?))) -> Void) {}
}

class SubCities: Cities {
override var yogurt: Int { return 2 }
}
4 changes: 4 additions & 0 deletions test/Migrator/rename-func-decl.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ class MySubTopLevelType: ToplevelType {
class MySubTopLevelType2: ToplevelType {
override func member(_ x: @escaping (((([(Int)])?))) -> Void) {}
}

class SubCities: Cities {
override var cheese: Int { return 2 }
}

0 comments on commit 83382c5

Please sign in to comment.