public static boolean isVoidContext(PsiExpression expression) {
    PsiElement element = PsiUtil.skipParenthesizedExprUp(expression.getParent());
    if (element instanceof PsiExpressionStatement) {
      if (element.getParent() instanceof PsiCodeFragment && PsiTreeUtil.skipWhitespacesAndCommentsForward(element) == null) {
        // The last statement in the code fragment could be used as fragment return value (e.g., in the debugger watch window)
        return false;
      }
      return !(element.getParent() instanceof PsiSwitchLabeledRuleStatement ruleStatement) ||
             !(ruleStatement.getEnclosingSwitchBlock() instanceof PsiSwitchExpression);
    }
    if (element instanceof PsiExpressionList && element.getParent() instanceof PsiExpressionListStatement) {
      return true;
    }
    if (element instanceof PsiLambdaExpression lambda) {
      return PsiTypes.voidType().equals(LambdaUtil.getFunctionalInterfaceReturnType(lambda));
    }
    return false;
  }
public static boolean isVoidContext(PsiExpression expression)