mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-highlighting] shouldAddDefault moved from SwitchBlockHighlightingModel to DeleteSwitchLabelFix
Part of IDEA-365344 Create a new Java error highlighter with minimal dependencies (PSI only) GitOrigin-RevId: 23717aeb658e6a29cff944651d1304c813d99ae9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6a15ae8ed9
commit
1e74ac0725
-6
@@ -21,12 +21,6 @@ import static com.intellij.java.codeserver.core.JavaPatternExhaustivenessUtil.ha
|
||||
import static java.util.Objects.requireNonNullElse;
|
||||
|
||||
public final class SwitchBlockHighlightingModel {
|
||||
public static boolean shouldAddDefault(@NotNull PsiSwitchBlock block) {
|
||||
if (!ExpressionUtil.isEnhancedSwitch(block)) return false;
|
||||
if (JavaPsiSwitchUtil.getUnconditionalPatternLabel(block) != null) return false;
|
||||
if (JavaPsiSwitchUtil.findDefaultElement(block) != null) return false;
|
||||
return hasExhaustivenessError(block);
|
||||
}
|
||||
|
||||
static void checkExhaustiveness(@NotNull PsiSwitchBlock block, @NotNull Consumer<? super HighlightInfo.Builder> errorSink) {
|
||||
PsiCodeBlock body = block.getBody();
|
||||
|
||||
+11
-2
@@ -1,7 +1,7 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInspection.dataFlow.fix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.SwitchBlockHighlightingModel;
|
||||
import com.intellij.codeInsight.ExpressionUtil;
|
||||
import com.intellij.java.analysis.JavaAnalysisBundle;
|
||||
import com.intellij.java.codeserver.core.JavaPsiSwitchUtil;
|
||||
import com.intellij.modcommand.ActionContext;
|
||||
@@ -27,6 +27,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.intellij.java.codeserver.core.JavaPatternExhaustivenessUtil.hasExhaustivenessError;
|
||||
|
||||
public class DeleteSwitchLabelFix extends PsiUpdateModCommandAction<PsiCaseLabelElement> {
|
||||
private final String myName;
|
||||
private final boolean myAddDefaultIfNecessary;
|
||||
@@ -74,7 +76,7 @@ public class DeleteSwitchLabelFix extends PsiUpdateModCommandAction<PsiCaseLabel
|
||||
PsiSwitchBlock block = label.getEnclosingSwitchBlock();
|
||||
if (block == null) return;
|
||||
deleteLabelElement(context.project(), labelElement);
|
||||
if (myAddDefaultIfNecessary && SwitchBlockHighlightingModel.shouldAddDefault(block)) {
|
||||
if (myAddDefaultIfNecessary && shouldAddDefault(block)) {
|
||||
CreateDefaultBranchFix.addDefault(block, updater);
|
||||
}
|
||||
}
|
||||
@@ -155,4 +157,11 @@ public class DeleteSwitchLabelFix extends PsiUpdateModCommandAction<PsiCaseLabel
|
||||
}
|
||||
new CommentTracker().deleteAndRestoreComments(label);
|
||||
}
|
||||
|
||||
public static boolean shouldAddDefault(@NotNull PsiSwitchBlock block) {
|
||||
if (!ExpressionUtil.isEnhancedSwitch(block)) return false;
|
||||
if (JavaPsiSwitchUtil.getUnconditionalPatternLabel(block) != null) return false;
|
||||
if (JavaPsiSwitchUtil.findDefaultElement(block) != null) return false;
|
||||
return hasExhaustivenessError(block);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user