mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-highlighting] getSwitchBranches moved from SwitchUtils to JavaPsiSwitchUtil
Part of IDEA-365344 Create a new Java error highlighter with minimal dependencies (PSI only) GitOrigin-RevId: 9e356b8522c0bb5a8112d5c30913a4aa3d9cf45d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6d6d8d5725
commit
174ffe0cac
@@ -5,11 +5,9 @@ import com.intellij.codeInsight.ExpressionUtil;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.ConstantExpressionUtil;
|
||||
import com.intellij.psi.util.JavaPsiPatternUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@@ -383,6 +381,27 @@ public final class JavaPsiSwitchUtil {
|
||||
labelElement -> labelElement instanceof PsiDefaultCaseLabelElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param block the switch block
|
||||
* @return a list of switch branches consisting of either {@link PsiSwitchLabelStatementBase} or {@link PsiCaseLabelElement}
|
||||
*/
|
||||
public static @NotNull List<PsiElement> getSwitchBranches(@NotNull PsiSwitchBlock block) {
|
||||
final PsiCodeBlock body = block.getBody();
|
||||
if (body == null) return Collections.emptyList();
|
||||
List<PsiElement> result = new SmartList<>();
|
||||
for (PsiSwitchLabelStatementBase child : PsiTreeUtil.getChildrenOfTypeAsList(body, PsiSwitchLabelStatementBase.class)) {
|
||||
if (child.isDefaultCase()) {
|
||||
result.add(child);
|
||||
}
|
||||
else {
|
||||
PsiCaseLabelElementList labelElementList = child.getCaseLabelElementList();
|
||||
if (labelElementList == null) continue;
|
||||
Collections.addAll(result, labelElementList.getElements());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kinds of switch selector
|
||||
* @see #getSwitchSelectorKind(PsiType)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
/**
|
||||
* Core functionality required by Java codeserver and other parts of Java plugin.
|
||||
* Mostly contains utility classes.
|
||||
* Mostly contains utility classes.
|
||||
* The utility methods in this package are aimed to help reading the PSI and extract some facts from it.
|
||||
*/
|
||||
package com.intellij.java.codeserver.core;
|
||||
|
||||
Reference in New Issue
Block a user