2017-02-11 17:02:38 -05:00
|
|
|
" Author: farenjihn <farenjihn@gmail.com>, w0rp <devw0rp@gmail.com>
|
2017-02-11 16:29:48 -05:00
|
|
|
" Description: Lints java files using javac
|
|
|
|
|
2017-02-11 17:02:38 -05:00
|
|
|
let g:ale_java_javac_options = get(g:, 'ale_java_javac_options', '')
|
|
|
|
let g:ale_java_javac_classpath = get(g:, 'ale_java_javac_classpath', '')
|
2017-02-11 16:29:48 -05:00
|
|
|
|
2017-02-11 17:06:20 -05:00
|
|
|
function! ale_linters#java#javac#GetCommand(buffer) abort
|
2017-04-15 20:24:08 -04:00
|
|
|
let l:cp_option = !empty(ale#Var(a:buffer, 'java_javac_classpath'))
|
|
|
|
\ ? '-cp ' . ale#Var(a:buffer, 'java_javac_classpath')
|
2017-02-11 17:02:38 -05:00
|
|
|
\ : ''
|
|
|
|
|
2017-03-31 15:14:53 -04:00
|
|
|
" Create .class files in a temporary directory, which we will delete later.
|
|
|
|
let l:class_file_directory = ale#engine#CreateDirectory(a:buffer)
|
|
|
|
|
2017-02-11 17:02:38 -05:00
|
|
|
return 'javac -Xlint '
|
|
|
|
\ . l:cp_option
|
2017-03-31 15:14:53 -04:00
|
|
|
\ . ' -d ' . fnameescape(l:class_file_directory)
|
2017-04-15 20:24:08 -04:00
|
|
|
\ . ' ' . ale#Var(a:buffer, 'java_javac_options')
|
2017-02-11 17:02:38 -05:00
|
|
|
\ . ' %t'
|
|
|
|
endfunction
|
2017-02-11 16:29:48 -05:00
|
|
|
|
|
|
|
function! ale_linters#java#javac#Handle(buffer, lines) abort
|
|
|
|
" Look for lines like the following.
|
|
|
|
"
|
|
|
|
" Main.java:13: warning: [deprecation] donaught() in Testclass has been deprecated
|
|
|
|
" Main.java:16: error: ';' expected
|
|
|
|
|
|
|
|
let l:pattern = '^.*\:\(\d\+\):\ \(.*\):\(.*\)$'
|
|
|
|
let l:output = []
|
|
|
|
|
2017-04-17 19:35:53 -04:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2017-02-11 16:29:48 -05:00
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:match[1] + 0,
|
|
|
|
\ 'text': l:match[2] . ':' . l:match[3],
|
|
|
|
\ 'type': l:match[2] ==# 'error' ? 'E' : 'W',
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('java', {
|
|
|
|
\ 'name': 'javac',
|
|
|
|
\ 'output_stream': 'stderr',
|
|
|
|
\ 'executable': 'javac',
|
|
|
|
\ 'command_callback': 'ale_linters#java#javac#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#java#javac#Handle',
|
|
|
|
\})
|