void (@NotNull PsiStatement statement, @NotNull PsiSwitchExpression switchExpression, @NotNull Collection<PsiExpression> result) { Collection<PsiYieldStatement> yields = statement instanceof PsiYieldStatement yieldStatement ? Collections.singleton(yieldStatement) : PsiTreeUtil.findChildrenOfType(statement, PsiYieldStatement.class); List<PsiYieldStatement> myYields = ContainerUtil.filter(yields, st -> st.findEnclosingExpression() == switchExpression); for (PsiYieldStatement yield : myYields) { ContainerUtil.addIfNotNull(result, yield.getExpression()); } }