private static ConditionalKind isBooleanOrNumeric(PsiExpression expr) {
    if (expr instanceof PsiParenthesizedExpression) {
      return isBooleanOrNumeric(((PsiParenthesizedExpression)expr).getExpression());
    }
    if (expr == null) return null;
    PsiType type = null;
    //A class instance creation expression (p15.9) for a class that is convertible to a numeric type.
    //As numeric classes do not have type parameters, at this point expressions with diamonds could be ignored
    if (expr instanceof PsiNewExpression && !PsiDiamondType.hasDiamond((PsiNewExpression)expr) ||
        hasStandaloneForm(expr)) {
      type = expr.getType();
    }
    else if (expr instanceof PsiMethodCallExpression) {
      final JavaResolveResult result = ((PsiMethodCallExpression)expr).getMethodExpression().advancedResolve(false);
      final PsiMethod method = (PsiMethod)result.getElement();
      if (method != null) {
        type = method.getReturnType();
        if (result instanceof MethodCandidateInfo) {
          // Spec: Note that, for a generic method, this is the type before instantiating the method's type arguments.
          PsiSubstitutor substitutor = ((MethodCandidateInfo)result).getSubstitutorFromQualifier();
          type = substitutor.substitute(type);
        }
      }
    }

    final ConditionalKind kind = isBooleanOrNumericType(type);
    if (kind != null) {
      return kind;
    }

    if (expr instanceof PsiConditionalExpression) {
      final PsiExpression thenExpression = ((PsiConditionalExpression)expr).getThenExpression();
      final PsiExpression elseExpression = ((PsiConditionalExpression)expr).getElseExpression();
      final ConditionalKind thenKind = isBooleanOrNumeric(thenExpression);
      final ConditionalKind elseKind = isBooleanOrNumeric(elseExpression);
      if (thenKind == elseKind || elseKind == ConditionalKind.NULL) return thenKind;
      if (thenKind == ConditionalKind.NULL) return elseKind;
    }

    if (expr instanceof PsiSwitchExpression) {
      ConditionalKind switchKind = null;
      for (PsiExpression resultExpression : PsiUtil.getSwitchResultExpressions((PsiSwitchExpression)expr)) {
        ConditionalKind resultKind = isBooleanOrNumeric(resultExpression);
        if (resultKind == null) return null;
        if (switchKind == null) {
          switchKind = resultKind;
        }
        else if (switchKind != resultKind) {
          if (switchKind == ConditionalKind.NULL) {
            switchKind = resultKind;
          }
          else if (resultKind != ConditionalKind.NULL) {
            return null;
          }
        }
      }
    }
    return null;
  }
private static ConditionalKind isBooleanOrNumeric(PsiExpression expr)