mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java switch expressions 2.0: fix formatting around yield; wrap labeled rule in code block support yield format
GitOrigin-RevId: 286e4a9fab64d19b039dc01e1a5618c1778d1d65
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e892dae139
commit
c9a6dd96cc
+4
-1
@@ -8,8 +8,10 @@ import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -102,7 +104,8 @@ public class SwitchLabeledRuleCanBeCodeBlockInspection extends LocalInspectionTo
|
||||
|
||||
private static void wrapExpression(PsiExpressionStatement expressionStatement) {
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
tracker.replaceAndRestoreComments(expressionStatement, "{ break " + tracker.text(expressionStatement) + " }");
|
||||
String valueKeyword = PsiUtil.getLanguageLevel(expressionStatement) == LanguageLevel.JDK_12_PREVIEW ? PsiKeyword.BREAK : PsiKeyword.YIELD;
|
||||
tracker.replaceAndRestoreComments(expressionStatement, "{ " + valueKeyword + " " + tracker.text(expressionStatement) + " }");
|
||||
}
|
||||
|
||||
private static void wrapStatement(@NotNull PsiStatement statement) {
|
||||
|
||||
@@ -833,6 +833,13 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitYieldStatement(PsiYieldStatement statement) {
|
||||
if (myType1 == JavaTokenType.YIELD_KEYWORD && ElementType.EXPRESSION_BIT_SET.contains(myType2)) {
|
||||
createSpaceProperty(true, false, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitContinueStatement(PsiContinueStatement statement) {
|
||||
if (myType1 == JavaTokenType.CONTINUE_KEYWORD && myType2 == JavaTokenType.IDENTIFIER) {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ class C {
|
||||
String foo(int n) {
|
||||
return switch (n) {
|
||||
case 1 -> /*1*/{
|
||||
break Integer.toString(/*2*/n);
|
||||
yield Integer.toString(/*2*/n);
|
||||
}/*3*/
|
||||
default -> "b";
|
||||
};
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ class C {
|
||||
String foo(int n) {
|
||||
return switch (n) {
|
||||
case 1 -> /*1*/ {
|
||||
break "a";
|
||||
yield "a";
|
||||
} /*2*/
|
||||
default -> "b";
|
||||
};
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ class SwitchLabeledRuleCanBeCodeBlockFixTest : LightQuickFixParameterizedTestCas
|
||||
|
||||
override fun configureLocalInspectionTools(): Array<LocalInspectionTool> = arrayOf(SwitchLabeledRuleCanBeCodeBlockInspection())
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = LightJavaCodeInsightFixtureTestCase.JAVA_12
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = LightJavaCodeInsightFixtureTestCase.JAVA_13
|
||||
|
||||
override fun getBasePath() = "/inspection/switchLabeledRuleCanBeCodeBlockFix"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user