[PATCH] D118782: clangd: Add a break for every case in the PopulateSwitch tweak
Christian Kandeler via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 2 05:57:47 PST 2022
ckandeler updated this revision to Diff 405240.
ckandeler added a comment.
Fixed unintentional whitespace change.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118782/new/
https://reviews.llvm.org/D118782
Files:
clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
Index: clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
@@ -123,7 +123,7 @@
)"",
R""(
enum class Enum {A,B};
- switch (Enum::A) {case Enum::A:case Enum::B:break;}
+ switch (Enum::A) {case Enum::A:break;case Enum::B:break;}
)"",
},
{
@@ -135,7 +135,7 @@
)"",
R""(
enum Enum {A,B,C};
- switch (A) {case B:break;case A:case C:break;}
+ switch (A) {case B:break;case A:break;case C:break;}
)"",
},
{
@@ -148,7 +148,7 @@
)"",
R""(
enum Enum {A,B=1,C};
- switch (A) {case 1:break;case A:case C:break;}
+ switch (A) {case 1:break;case A:break;case C:break;}
)"",
},
{
@@ -162,7 +162,7 @@
R""(
enum class Enum {A,B,C};
switch (Enum::A)
- {case Enum::B:break;case Enum::A:case Enum::C:break;}
+ {case Enum::B:break;case Enum::A:break;case Enum::C:break;}
)"",
},
{
@@ -193,12 +193,12 @@
// Duplicated constant names
Function,
R""(enum Enum {A,B,b=B}; ^switch (A) {})"",
- R""(enum Enum {A,B,b=B}; switch (A) {case A:case B:break;})"",
+ R""(enum Enum {A,B,b=B}; switch (A) {case A:break;case B:break;})"",
},
{
// Duplicated constant names all in switch
Function,
- R""(enum Enum {A,B,b=B}; ^switch (A) {case A:case B:break;})"",
+ R""(enum Enum {A,B,b=B}; ^switch (A) {case A:break;case B:break;})"",
"unavailable",
},
{
@@ -217,7 +217,7 @@
R""(
enum CEnum {A,B,C};
enum CEnum val = A;
- switch (val) {case B:break;case A:case C:break;}
+ switch (val) {case B:break;case A:break;case C:break;}
)"",
"TestTU.c"},
{// C: Only filling in missing enumerators w/ typedefs
@@ -236,7 +236,7 @@
typedef enum ControlState ControlState;
enum ControlState : UInteger {A,B,C};
ControlState controlState = A;
- switch (controlState) {case A:break;case B:case C:break;}
+ switch (controlState) {case A:break;case B:break;case C:break;}
)"",
"TestTU.c"},
};
Index: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -22,7 +22,9 @@
// void f(Color color) {
// switch (color) {
// case RED:
+// break;
// case GREEN:
+// break;
// case BLUE:
// break;
// }
@@ -204,10 +206,10 @@
if (EnumD->isScoped())
Text.append({EnumD->getName(), "::"});
Text.append({EnumConstant.second.getEnumConstant()->getName(), ":"});
+ Text += "break;";
}
assert(!Text.empty() && "No enumerators to insert!");
- Text += "break;";
const SourceManager &SM = Ctx.getSourceManager();
return Effect::mainFileEdit(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118782.405240.patch
Type: text/x-patch
Size: 3403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220202/039be396/attachment.bin>
More information about the cfe-commits
mailing list