mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] 'yield' statements support in the 'duplicated switch branches' inspection
GitOrigin-RevId: 02c6103423343552dee71943186e576dc06561ce
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4f2967ab2b
commit
808760e6ec
+2
-1
@@ -708,6 +708,7 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
|
||||
|
||||
private static boolean isSimpleExit(@Nullable PsiStatement statement) {
|
||||
if (statement instanceof PsiBreakStatement ||
|
||||
statement instanceof PsiYieldStatement ||
|
||||
statement instanceof PsiContinueStatement ||
|
||||
statement instanceof PsiThrowStatement) {
|
||||
return true;
|
||||
@@ -935,4 +936,4 @@ public class DuplicateBranchesInSwitchInspection extends LocalInspectionTool {
|
||||
tracker.deleteAndRestoreComments(myRuleToDelete.myLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,8 @@ public interface ElementType extends JavaTokenType, JavaDocTokenType, JavaElemen
|
||||
TokenSet JAVA_STATEMENT_BIT_SET = TokenSet.create(
|
||||
EMPTY_STATEMENT, BLOCK_STATEMENT, EXPRESSION_STATEMENT, EXPRESSION_LIST_STATEMENT, DECLARATION_STATEMENT, IF_STATEMENT,
|
||||
WHILE_STATEMENT, FOR_STATEMENT, FOREACH_STATEMENT, DO_WHILE_STATEMENT, SWITCH_STATEMENT, SWITCH_LABEL_STATEMENT, BREAK_STATEMENT,
|
||||
CONTINUE_STATEMENT, RETURN_STATEMENT, THROW_STATEMENT, SYNCHRONIZED_STATEMENT, TRY_STATEMENT, LABELED_STATEMENT, ASSERT_STATEMENT);
|
||||
CONTINUE_STATEMENT, RETURN_STATEMENT, THROW_STATEMENT, SYNCHRONIZED_STATEMENT, TRY_STATEMENT, LABELED_STATEMENT, ASSERT_STATEMENT,
|
||||
YIELD_STATEMENT);
|
||||
|
||||
TokenSet JAVA_MODULE_STATEMENT_BIT_SET = TokenSet.create(
|
||||
REQUIRES_STATEMENT, EXPORTS_STATEMENT, OPENS_STATEMENT, USES_STATEMENT, PROVIDES_STATEMENT);
|
||||
|
||||
+4
-4
@@ -2,13 +2,13 @@ class C {
|
||||
void test(int n) {
|
||||
String s = switch (n) {
|
||||
case 1:
|
||||
break "a";
|
||||
yield "a";
|
||||
case 2:
|
||||
break "b";
|
||||
yield "b";
|
||||
case 3:
|
||||
<weak_warning descr="Duplicate branch in 'switch'">break "a";</weak_warning>
|
||||
<weak_warning descr="Duplicate branch in 'switch'">yield "a";</weak_warning>
|
||||
default:
|
||||
break "";
|
||||
yield "";
|
||||
};
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -3,11 +3,11 @@ class C {
|
||||
String s = switch (n) {
|
||||
default:
|
||||
case 1:
|
||||
break "a";
|
||||
yield "a";
|
||||
case 2:
|
||||
break "b";
|
||||
yield "b";
|
||||
case 3:
|
||||
<weak_warning descr="Branch in 'switch' is a duplicate of the default branch">break "a";</weak_warning>
|
||||
<weak_warning descr="Branch in 'switch' is a duplicate of the default branch">yield "a";</weak_warning>
|
||||
};
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -2,12 +2,12 @@ class C {
|
||||
void test(int n) {
|
||||
String s = switch (n) {
|
||||
case 1:
|
||||
<weak_warning descr="Branch in 'switch' is a duplicate of the default branch">break "a";</weak_warning>
|
||||
<weak_warning descr="Branch in 'switch' is a duplicate of the default branch">yield "a";</weak_warning>
|
||||
case 2:
|
||||
break "b";
|
||||
yield "b";
|
||||
case 3:
|
||||
default:
|
||||
break "a";
|
||||
yield "a";
|
||||
};
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -2,13 +2,13 @@ class C {
|
||||
void test(int n) {
|
||||
String s = switch (n) {
|
||||
case 1:
|
||||
break "a"; // one comment
|
||||
yield "a"; // one comment
|
||||
case 2:
|
||||
break "b";
|
||||
yield "b";
|
||||
case 3:
|
||||
break "a"; // another comment
|
||||
yield "a"; // another comment
|
||||
default:
|
||||
break "";
|
||||
yield "";
|
||||
};
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -2,13 +2,13 @@ class C {
|
||||
void test(int n) {
|
||||
String s = switch (n) {
|
||||
case 1:
|
||||
break "a"; // same comment
|
||||
yield "a"; // same comment
|
||||
case 2:
|
||||
break "b";
|
||||
yield "b";
|
||||
case 3:
|
||||
<weak_warning descr="Duplicate branch in 'switch'">break "a"; // same comment</weak_warning>
|
||||
<weak_warning descr="Duplicate branch in 'switch'">yield "a"; // same comment</weak_warning>
|
||||
default:
|
||||
break "";
|
||||
yield "";
|
||||
};
|
||||
}
|
||||
}
|
||||
+2
-9
@@ -10,16 +10,8 @@ import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
|
||||
* @author Pavel.Dolgov
|
||||
*/
|
||||
class DuplicateBranchesInEnhancedSwitchTest : LightJavaCodeInsightFixtureTestCase() {
|
||||
val inspection = DuplicateBranchesInSwitchInspection()
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
myFixture.enableInspections(inspection)
|
||||
}
|
||||
|
||||
override fun getBasePath() = JavaTestUtil.getRelativeJavaTestDataPath() + "/inspection/duplicateBranchesInEnhancedSwitch"
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = JAVA_12
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = JAVA_13
|
||||
|
||||
fun testSimpleExpression() = doTest()
|
||||
fun testSimpleStatement() = doTest()
|
||||
@@ -35,6 +27,7 @@ class DuplicateBranchesInEnhancedSwitchTest : LightJavaCodeInsightFixtureTestCas
|
||||
fun testCaseLabelsExpressionSameComments() = doTest()
|
||||
|
||||
private fun doTest() {
|
||||
myFixture.enableInspections(DuplicateBranchesInSwitchInspection())
|
||||
myFixture.testHighlighting("${getTestName(false)}.java")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user