This is called "a motion". Even though linewise motions result in a line range.
Normally, it's enough to do 5J and there's no need for "join" operator. However, if you really want it, you can make use of :h g@ and :h 'opfunc' A simplified example:
" very basic "join" operator
nnoremap <silent>J :set opfunc=OperJoin<CR>g@
If using plug-ins is acceptable to you, then the vim-commentary plug-in can help you.
It defines a gc text object to select a comment, which you can use in operator pending mode. Use gqgc anywhere in the comment block to format the comment.
Note that if you are using C or C++ you may need to tell Vim to use // comments instead of /**/ comments. You can ...
Plug-in wellle/targets.vim includes an operator mapping for this specific situation. The mapping is A( or Ab, which is analogous to a( but includes the whitespace following the pair.
See the plug-in's documentation for the "Around Pair" operator.
You can control that with the 'selection' option. To disable the "past line" cursor behavior, use the following command:
Beware that using a non-default setting for this option is possibly likely to break behavior of some plug-ins, so it might not be a great idea to change it.
There's also a motion that might be close to what you ...
All of the text-objects are documented under :help text-objects.
Excerpted from :help objects:
|v_iquote| i" double quoted string without the quotes
|v_i'| i' single quoted string without the quotes
|v_i(| i( same as ib
|v_i)| i) same as ib
|v_i<| i< "inner <>" from '<' to the ...
Well, since J works in visual mode...
More generally v[motion or text object]J. Normally I would say this is a bit of an anti-pattern (prefer [operator][motion or text object]), but there is no join operator.
Here, even v%J should work
Alternately, use :join, which takes a range, and ranges can be quite powerful: