Skip to content

migrator: rename a property declaration if the framework property it overrides has been renamed. #21437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
}