diff --git a/README.md b/README.md index c461001..e1dcb34 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ name. That seems to be the fairest way to arrange this table. | Go | [gofmt -e](https://golang.org/cmd/gofmt/), [go vet](https://golang.org/cmd/vet/), [golint](https://godoc.org/github.com/golang/lint), [go build](https://golang.org/cmd/go/) | | Haskell | [ghc](https://www.haskell.org/ghc/), [hlint](https://hackage.haskell.org/package/hlint) | | HTML | [HTMLHint](http://htmlhint.com/), [tidy](http://www.html-tidy.org/) | +| Java | [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html) | | JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [flow](https://flowtype.org/), [standard](http://standardjs.com/) | JSON | [jsonlint](http://zaa.ch/jsonlint/) | | LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck) | diff --git a/ale_linters/java/javac.vim b/ale_linters/java/javac.vim index 8098631..9815ffa 100644 --- a/ale_linters/java/javac.vim +++ b/ale_linters/java/javac.vim @@ -1,11 +1,19 @@ -" Author: farenjihn +" Author: farenjihn , w0rp " Description: Lints java files using javac -let g:loaded_ale_linters_java_javac = 1 -let g:ale_java_javac_classpath = '' +let g:ale_java_javac_options = get(g:, 'ale_java_javac_options', '') +let g:ale_java_javac_classpath = get(g:, 'ale_java_javac_classpath', '') -let s:eclipse_classpath = '' -let s:tmppath = '/tmp/java_ale/' +function! ale_linters#java#javac#GetCommand(buffer) + let l:cp_option = !empty(g:ale_java_javac_classpath) + \ ? '-cp ' . g:ale_java_javac_classpath + \ : '' + + return 'javac -Xlint ' + \ . l:cp_option + \ . ' ' . g:ale_java_javac_options + \ . ' %t' +endfunction function! ale_linters#java#javac#Handle(buffer, lines) abort " Look for lines like the following. @@ -37,62 +45,6 @@ function! ale_linters#java#javac#Handle(buffer, lines) abort return l:output endfunction -function! ale_linters#java#javac#ParseEclipseClasspath() - let l:eclipse_classpath = '' - -python << EOF - - import xml.etree.ElementTree as ET, vim - tree = ET.parse(".classpath") - root = tree.getroot() - - classpath = '' - - for child in root: - classpath += child.get("path") - classpath += ':' - - vim.command("let l:eclipse_classpath = '%s'" % classpath); - -# Cannot indent this EOF token as per :h python -EOF - - return l:eclipse_classpath -endfunction - -function! ale_linters#java#javac#CheckEclipseClasspath() - " Eclipse .classpath parsing through python - if file_readable('.classpath') - let s:eclipse_classpath = ale_linters#java#javac#ParseEclipseClasspath() - endif -endfunction - -function! ale_linters#java#javac#GetCommand(buffer) - let l:path = s:tmppath . expand('%:p:h') - let l:file = expand('%:t') - let l:buf = getline(1, '$') - - " Javac cannot compile files from stdin so we move a copy into /tmp instead - call mkdir(l:path, 'p') - call writefile(l:buf, l:path . '/' . l:file) - - return 'javac ' - \ . '-Xlint ' - \ . '-cp ' . s:eclipse_classpath . g:ale_java_javac_classpath . ':. ' - \ . g:ale_java_javac_options - \ . ' ' . l:path . '/' . l:file -endfunction - -function! ale_linters#java#javac#CleanupTmp() - call delete(s:tmppath, 'rf') -endfunction - -augroup java_ale_au - autocmd! BufEnter *.java call ale_linters#java#javac#CheckEclipseClasspath() - autocmd! BufLeave *.java call ale_linters#java#javac#CleanupTmp() -augroup END - -call ale_linters#java#javac#CheckEclipseClasspath() call ale#linter#Define('java', { \ 'name': 'javac', \ 'output_stream': 'stderr', diff --git a/doc/ale.txt b/doc/ale.txt index 835f980..3695de7 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -38,6 +38,7 @@ CONTENTS *ale-contents* 4.26. erlang..........................|ale-linter-options-erlang| 4.27. phpmd...........................|ale-linter-options-phpmd| 4.28. xo..............................|ale-linter-options-xo| + 4.28. javac...........................|ale-linter-options-javac| 5. Linter Integration Notes.............|ale-linter-integration| 5.1. merlin..........................|ale-linter-integration-ocaml-merlin| 5.2. rust.............................|ale-integration-rust| @@ -88,6 +89,7 @@ The following languages and tools are supported. * Go: 'gofmt -e', 'go vet', 'golint', 'go build' * Haskell: 'ghc', 'hlint' * HTML: 'HTMLHint', 'tidy' +* Java: 'javac' * JavaScript: 'eslint', 'jscs', 'jshint', 'flow', 'xo' * JSON: 'jsonlint' * LaTeX: 'chktex', 'lacheck' @@ -955,6 +957,24 @@ g:ale_javascript_xo_use_global *g:ale_javascript_xo_use_global* global version of xo, in preference to locally installed versions of xo in node_modules. +------------------------------------------------------------------------------ +4.28. javac *ale-linter-options-javac* + +g:ale_java_javac_classpath *g:ale_java_javac_classpath* + + Type: |String| + Default: `''` + + This variable can be set to change the global classpath for Java. + + +g:ale_java_javac_options *g:ale_java_javac_options* + + Type: |String| + Default: `''` + + This variable can be set to pass additional options to javac. + =============================================================================== 5. Linter Integration Notes *ale-linter-integration*