neoformat icon indicating copy to clipboard operation
neoformat copied to clipboard

Add google-java-format support for java

Open icearith opened this issue 8 years ago • 4 comments

google-java-format is a program that reformats Java source code to comply with Google Java Style, which is widely used by developers.

if it's ok, I will submit a PR.

icearith avatar Mar 19 '17 15:03 icearith

PRs are always welcome.

Thanks!

sbdchd avatar Mar 19 '17 20:03 sbdchd

I suggest the existing custom formatter configuration for this issue, as the google formatter is a jar file, which needs to be invoked via java command under an arbitrary filepath. The following neoformat configuration does add the google formatter to neoformat.

let g:neoformat_java_google = {
            \ 'exe': 'java',
            \ 'args': ['-jar /path/to/google-java-format.jar -'],
            \ 'stdin': 1, 
            \ }

let g:neoformat_enabled_java = ['google']

nimmzwei avatar Jul 06 '17 22:07 nimmzwei

@icearith yeah, this formatter should be custom by user themselfs.

wsdjeg avatar Apr 18 '18 16:04 wsdjeg

Expecting each user to self-define formatter for google-java-format is not user-friendly. I see two solutions:

a) expecting user to provide own shell wrapper around command (I use Arch Linux and AUR package comes with google-java-format command on path) b) introducing global variable pointing to jar file, like so:

let g:neoformat_java_google = {
            \ 'exe': 'java',
            \ 'args': ['-jar' . g:neoformat_java_google_jar . ' -'],
            \ 'stdin': 1, 
            \ }

Of course, formatter would be defined only if variable is set.

fenuks avatar Dec 09 '19 20:12 fenuks