mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
com.siyeh.ig.psiutils.ExpressionUtils#nonStructuralChildren: switch expressions support
GitOrigin-RevId: ea7039750712eab413f72d4b88240a9fee5d0dea
This commit is contained in:
committed by
intellij-monorepo-bot
parent
916feabc2d
commit
976a5b5417
+35
-1
@@ -221,9 +221,31 @@ public final class ExpressionUtils {
|
||||
if (e instanceof PsiParenthesizedExpression parens) {
|
||||
return StreamEx.ofNullable(parens.getExpression());
|
||||
}
|
||||
if (e instanceof PsiSwitchExpression switchExpression) {
|
||||
PsiCodeBlock switchBody = switchExpression.getBody();
|
||||
if (switchBody == null) return StreamEx.empty();
|
||||
List<PsiExpression> result = new ArrayList<>();
|
||||
PsiStatement[] statements = switchBody.getStatements();
|
||||
for (PsiStatement statement : statements) {
|
||||
if (statement instanceof PsiSwitchLabeledRuleStatement rule) {
|
||||
PsiStatement ruleBody = rule.getBody();
|
||||
if (ruleBody instanceof PsiBlockStatement blockStatement) {
|
||||
collectYieldExpressions(blockStatement, switchExpression, result);
|
||||
}
|
||||
else if (ruleBody instanceof PsiExpressionStatement expr) {
|
||||
result.add(expr.getExpression());
|
||||
}
|
||||
}
|
||||
else {
|
||||
collectYieldExpressions(statement, switchExpression, result);
|
||||
}
|
||||
}
|
||||
return StreamEx.of(result);
|
||||
}
|
||||
return null;
|
||||
}).remove(e -> e instanceof PsiConditionalExpression ||
|
||||
e instanceof PsiParenthesizedExpression)
|
||||
e instanceof PsiParenthesizedExpression ||
|
||||
e instanceof PsiSwitchExpression)
|
||||
.map(e -> {
|
||||
if (e instanceof PsiTypeCastExpression cast) {
|
||||
PsiExpression operand = cast.getOperand();
|
||||
@@ -244,6 +266,18 @@ public final class ExpressionUtils {
|
||||
});
|
||||
}
|
||||
|
||||
private static void collectYieldExpressions(@NotNull PsiStatement statement,
|
||||
@NotNull PsiSwitchExpression switchExpression,
|
||||
@NotNull Collection<PsiExpression> result) {
|
||||
Collection<PsiYieldStatement> blockStatement = statement instanceof PsiYieldStatement yieldStatement
|
||||
? Collections.singleton(yieldStatement)
|
||||
: PsiTreeUtil.findChildrenOfType(statement, PsiYieldStatement.class);
|
||||
List<PsiYieldStatement> myYields = ContainerUtil.filter(blockStatement, st -> st.findEnclosingExpression() == switchExpression);
|
||||
for (PsiYieldStatement yield : myYields) {
|
||||
ContainerUtil.addIfNotNull(result, yield.getExpression());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isZero(@Nullable PsiExpression expression) {
|
||||
if (expression == null) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user