checkstyle.vim 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "============================================================================
  2. "File: checkstyle.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Dmitry Geurkov <d.geurkov at gmail dot com>
  5. "License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "
  11. " Tested with checkstyle 5.5
  12. "============================================================================
  13. if exists('g:loaded_syntastic_java_checkstyle_checker')
  14. finish
  15. endif
  16. let g:loaded_syntastic_java_checkstyle_checker = 1
  17. if !exists('g:syntastic_java_checkstyle_classpath')
  18. let g:syntastic_java_checkstyle_classpath = 'checkstyle-5.5-all.jar'
  19. endif
  20. if !exists('g:syntastic_java_checkstyle_conf_file')
  21. let g:syntastic_java_checkstyle_conf_file = 'sun_checks.xml'
  22. endif
  23. let s:save_cpo = &cpo
  24. set cpo&vim
  25. function! SyntaxCheckers_java_checkstyle_IsAvailable() dict
  26. if !executable(self.getExec())
  27. return 0
  28. endif
  29. let classpath = expand(g:syntastic_java_checkstyle_classpath, 1)
  30. let conf_file = expand(g:syntastic_java_checkstyle_conf_file, 1)
  31. call self.log(
  32. \ 'filereadable(' . string(classpath) . ') = ' . filereadable(classpath) . ', ' .
  33. \ 'filereadable(' . string(conf_file) . ') = ' . filereadable(conf_file))
  34. return filereadable(classpath) && filereadable(conf_file)
  35. endfunction
  36. function! SyntaxCheckers_java_checkstyle_GetLocList() dict
  37. let fname = syntastic#util#shescape( expand('%:p:h', 1) . syntastic#util#Slash() . expand('%:t', 1) )
  38. if has('win32unix')
  39. let fname = substitute(syntastic#util#system('cygpath -m ' . fname), '\m\%x00', '', 'g')
  40. endif
  41. let makeprg = self.makeprgBuild({
  42. \ 'args_after': [
  43. \ '-cp', expand(g:syntastic_java_checkstyle_classpath, 1),
  44. \ 'com.puppycrawl.tools.checkstyle.Main',
  45. \ '-c', expand(g:syntastic_java_checkstyle_conf_file, 1),
  46. \ '-f', 'xml'],
  47. \ 'fname': fname })
  48. let errorformat = '%f:%t:%l:%c:%m'
  49. return SyntasticMake({
  50. \ 'makeprg': makeprg,
  51. \ 'errorformat': errorformat,
  52. \ 'preprocess': 'checkstyle',
  53. \ 'subtype': 'Style' })
  54. endfunction
  55. call g:SyntasticRegistry.CreateAndRegisterChecker({
  56. \ 'filetype': 'java',
  57. \ 'name': 'checkstyle',
  58. \ 'exec': 'java'})
  59. let &cpo = s:save_cpo
  60. unlet s:save_cpo
  61. " vim: set sw=4 sts=4 et fdm=marker: