private static String generateTernary(CommentTracker ct,
                                        PsiExpression condition,
                                        PsiExpression thenValue,
                                        PsiExpression elseValue,
                                        PsiType type) {
    thenValue = expandDiamondsWhenNeeded(thenValue, type);
    elseValue = expandDiamondsWhenNeeded(elseValue, type);
    @NonNls final StringBuilder conditional = new StringBuilder();
    final String conditionText = ct.text(condition, ParenthesesUtils.CONDITIONAL_PRECEDENCE);
    if (condition instanceof PsiConditionalExpression) {
      conditional.append('(').append(conditionText).append(')');
    }
    else {
      conditional.append(conditionText);
    }
    conditional.append('?');
    final PsiType thenType = thenValue.getType();
    final PsiType elseType = elseValue.getType();
    if (thenType instanceof PsiPrimitiveType primitiveType &&
        !PsiTypes.nullType().equals(thenType) &&
        !(elseType instanceof PsiPrimitiveType) &&
        !(type instanceof PsiPrimitiveType)) {
      // prevent unboxing of boxed value to preserve semantics (IDEA-48267, IDEA-310641)
      conditional.append(primitiveType.getBoxedTypeName());
      conditional.append(".valueOf(").append(ct.text(thenValue)).append("):");
      conditional.append(ct.text(elseValue, ParenthesesUtils.CONDITIONAL_PRECEDENCE));
    }
    else if (elseType instanceof PsiPrimitiveType primitiveType &&
             !PsiTypes.nullType().equals(elseType) &&
             !(thenType instanceof PsiPrimitiveType) &&
             !(type instanceof PsiPrimitiveType)) {
      // prevent unboxing of boxed value to preserve semantics (IDEA-48267, IDEA-310641)
      conditional.append(ct.text(thenValue, ParenthesesUtils.CONDITIONAL_PRECEDENCE));
      conditional.append(':');
      conditional.append(primitiveType.getBoxedTypeName());
      conditional.append(".valueOf(").append(ct.text(elseValue)).append(')');
    }
    else {
      conditional.append(ct.text(thenValue, ParenthesesUtils.CONDITIONAL_PRECEDENCE));
      conditional.append(':');
      conditional.append(ct.text(elseValue, ParenthesesUtils.CONDITIONAL_PRECEDENCE));
    }
    return conditional.toString();
  }
private static String generateTernary(CommentTracker ct,
                                        PsiExpression condition,
                                        PsiExpression thenValue,
                                        PsiExpression elseValue,
                                        PsiType type)