[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:
Tagir Valeev
2023-06-02 12:20:37 +02:00
committed by intellij-monorepo-bot
parent 9ae20627f0
commit 18063dd7f0
5 changed files with 37 additions and 16 deletions

View File

@@ -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 ||

View File

@@ -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) ||

View File

@@ -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";
};
}
}

View File

@@ -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";
};
}
}

View File

@@ -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;