@NotNull
    private static PsiType getLeastValueType(@NotNull PsiExpression returnValue, @NotNull PsiType type) {
      if (type instanceof PsiPrimitiveType) {
        int rank = TypeConversionUtil.getTypeRank(type);
        if (rank < TypeConversionUtil.BYTE_RANK || rank > TypeConversionUtil.INT_RANK) return type;
        PsiConstantEvaluationHelper evaluator = JavaPsiFacade.getInstance(returnValue.getProject()).getConstantEvaluationHelper();
        Object res = evaluator.computeConstantExpression(returnValue);
        if (res instanceof Number) {
          long value = ((Number)res).longValue();
          if (-128 <= value && value <= 127) return PsiTypes.byteType();
          if (-32768 <= value && value <= 32767) return PsiTypes.shortType();
          if (0 <= value && value <= 0xFFFF) return PsiTypes.charType();
        }
      }
      return type;
    }
@NotNull
    private static PsiType getLeastValueType(@NotNull PsiExpression returnValue, @NotNull PsiType type)