mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
[java-completion] Support yield in smart-enter
Fixes IDEA-321061 'Complete Current Statement' doesn't handle 'yield' in switch expressions GitOrigin-RevId: 4fa96c88bebb66d90f2d22a6e1bf5dd36f38c5c7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9ae20627f0
commit
18063dd7f0
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.editorActions.smartEnter;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -30,6 +16,7 @@ public class AfterSemicolonEnterProcessor implements EnterProcessor {
|
||||
psiElement instanceof PsiThrowStatement ||
|
||||
psiElement instanceof PsiBreakStatement ||
|
||||
psiElement instanceof PsiContinueStatement ||
|
||||
psiElement instanceof PsiYieldStatement ||
|
||||
psiElement instanceof PsiAssertStatement ||
|
||||
psiElement instanceof PsiField ||
|
||||
psiElement instanceof PsiImportStatementBase ||
|
||||
|
||||
@@ -76,6 +76,7 @@ public class SemicolonFixer implements Fixer {
|
||||
psiElement instanceof PsiThrowStatement ||
|
||||
psiElement instanceof PsiBreakStatement ||
|
||||
psiElement instanceof PsiContinueStatement ||
|
||||
psiElement instanceof PsiYieldStatement ||
|
||||
psiElement instanceof PsiAssertStatement ||
|
||||
psiElement instanceof PsiPackageStatement ||
|
||||
isStandaloneField(psiElement) ||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class X {
|
||||
String yieldState(Thread.State state) {
|
||||
return switch (state) {
|
||||
case NEW -> {
|
||||
System.out.println();
|
||||
yield "NEW"<caret>
|
||||
}
|
||||
case BLOCKED -> "BLOCKED";
|
||||
default -> "some";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class X {
|
||||
String yieldState(Thread.State state) {
|
||||
return switch (state) {
|
||||
case NEW -> {
|
||||
System.out.println();
|
||||
yield "NEW";
|
||||
}
|
||||
case BLOCKED -> "BLOCKED";
|
||||
default -> "some";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
@@ -8,9 +8,12 @@ import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.testFramework.EditorActionTestCase;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase.JAVA_LATEST_WITH_LATEST_JDK;
|
||||
|
||||
@TestDataPath("$CONTENT_ROOT/testData")
|
||||
public class CompleteStatementTest extends EditorActionTestCase {
|
||||
private CodeStyleSettings mySettings;
|
||||
@@ -219,6 +222,12 @@ public class CompleteStatementTest extends EditorActionTestCase {
|
||||
public void testAddMissingLambdaBody2() { doTest(); }
|
||||
public void testBlockInSwitchRule() { doTest(); }
|
||||
public void testSwitchAddArrow() { doTest(); }
|
||||
public void testYieldSemicolon() { doTest(); }
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_LATEST_WITH_LATEST_JDK;
|
||||
}
|
||||
|
||||
private void doTestBracesNextLineStyle() {
|
||||
myJavaSettings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
|
||||
|
||||
Reference in New Issue
Block a user