public static @NotNull LongRangeSet castTo(@NotNull LongRangeSet range, @NotNull PsiPrimitiveType type) {
    if (!TypeConversionUtil.isIntegralNumberType(type)) {
      throw new IllegalArgumentException(type.toString());
    }
    if (type.equals(PsiTypes.longType())) return range;
    if (range.isEmpty()) return range;
    Long value = range.getConstantValue();
    if (value != null) {
      long point = value;
      long newValue;
      if (PsiTypes.charType().equals(type)) {
        newValue = (char)point;
      }
      else if (PsiTypes.intType().equals(type)) {
        newValue = (int)point;
      }
      else if (PsiTypes.shortType().equals(type)) {
        newValue = (short)point;
      }
      else if (PsiTypes.byteType().equals(type)) {
        newValue = (byte)point;
      }
      else {
        throw new IllegalArgumentException(type.toString());
      }
      return newValue == point ? range : LongRangeSet.point(newValue);
    }
    LongRangeSet result = LongRangeSet.empty();
    for (LongRangeSet subRange : range.asRanges()) {
      result = result.join(castContinuousRange(subRange, type));
    }
    return result;
  }
public static @NotNull LongRangeSet castTo(@NotNull LongRangeSet range, @NotNull PsiPrimitiveType type)