-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-5744] Refactoring action to convert if-let to guard-let and vice versa #24566
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
Conversation
@swift-ci test |
You can't invoke CI yourself, you need commit access for it. |
cc @akyrtzi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks great overall👍! I have only several nitpicks inline.
lib/IDE/Refactoring.cpp
Outdated
|
||
if (Info.ContainedNodes.size() == 1) { | ||
if (auto S = Info.ContainedNodes[0].dyn_cast<Stmt*>()) { | ||
If = dyn_cast<IfStmt>(S); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always use 2-spaces indentation. Could you fix other indentation issues as well in this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
lib/IDE/Refactoring.cpp
Outdated
|
||
if (CondList.size() != 1) | ||
return true; // abort | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can assume performChange()
is called only when isApplicable
returns true. So it seems the above logics are unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
lib/IDE/Refactoring.cpp
Outdated
auto Body = dyn_cast_or_null<BraceStmt>(If->getThenStmt()); | ||
|
||
if (!Body) | ||
return true; // abort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move the ThenStmt
check to the isApplicable
function too? so we don't need to check it here and surprising the users by aborting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to the isApplicable
.
lib/IDE/Refactoring.cpp
Outdated
|
||
// Get if-let else body. | ||
auto ElseBody = dyn_cast_or_null<BraceStmt>(If->getElseStmt()); | ||
if (ElseBody) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two statements can be merged as if (auto *ElseBody = dyn_cast_or_null<BraceStmt>(If->getElseStmt())) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
lib/IDE/Refactoring.cpp
Outdated
auto E = CondList[0]; | ||
auto P = E.getPatternOrNull(); | ||
if (!P) | ||
return true; // abort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, can we move these condition checkings into isApplicable
function and only check it there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved.
lib/IDE/Refactoring.cpp
Outdated
auto ReplaceRange = RangeInfo.ContentRange; | ||
EditConsumer.accept(SM, ReplaceRange, DeclBuffer.str()); | ||
|
||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation issue here and all other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@swift-ci please smoke test |
@swift-ci please stress test |
Also I fixed similar issues at this PR: Refactoring action to convert to computed property. |
All tests passed. Congratulations for your first Swift contribution!🚢 |
Implement action to convert from:
to
and vice-versa
Resolves new feature request SR-5744.
Refactoring action to convert if-let to guard-let and vice versa
Feedback is very much appreciated!