mirror of https://github.com/dense-analysis/ale
Fix #1061 - Handle the filenames returned by javac
This commit is contained in:
parent
d851f399c0
commit
34674e088d
|
@ -49,7 +49,10 @@ function! ale_linters#java#javac#GetCommand(buffer, import_paths) abort
|
||||||
" Create .class files in a temporary directory, which we will delete later.
|
" Create .class files in a temporary directory, which we will delete later.
|
||||||
let l:class_file_directory = ale#engine#CreateDirectory(a:buffer)
|
let l:class_file_directory = ale#engine#CreateDirectory(a:buffer)
|
||||||
|
|
||||||
return 'javac -Xlint'
|
" Always run javac from the directory the file is in, so we can resolve
|
||||||
|
" relative paths correctly.
|
||||||
|
return ale#path#BufferCdString(a:buffer)
|
||||||
|
\ . 'javac -Xlint'
|
||||||
\ . ' ' . l:cp_option
|
\ . ' ' . l:cp_option
|
||||||
\ . ' ' . l:sp_option
|
\ . ' ' . l:sp_option
|
||||||
\ . ' -d ' . ale#Escape(l:class_file_directory)
|
\ . ' -d ' . ale#Escape(l:class_file_directory)
|
||||||
|
@ -63,14 +66,15 @@ function! ale_linters#java#javac#Handle(buffer, lines) abort
|
||||||
" Main.java:13: warning: [deprecation] donaught() in Testclass has been deprecated
|
" Main.java:13: warning: [deprecation] donaught() in Testclass has been deprecated
|
||||||
" Main.java:16: error: ';' expected
|
" Main.java:16: error: ';' expected
|
||||||
|
|
||||||
let l:pattern = '\v^.*:(\d+): (.+):(.+)$'
|
let l:directory = expand('#' . a:buffer . ':p:h')
|
||||||
|
let l:pattern = '\v^(.*):(\d+): (.+):(.+)$'
|
||||||
let l:col_pattern = '\v^(\s*\^)$'
|
let l:col_pattern = '\v^(\s*\^)$'
|
||||||
let l:symbol_pattern = '\v^ +symbol: *(class|method) +([^ ]+)'
|
let l:symbol_pattern = '\v^ +symbol: *(class|method) +([^ ]+)'
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
for l:match in ale#util#GetMatches(a:lines, [l:pattern, l:col_pattern, l:symbol_pattern])
|
for l:match in ale#util#GetMatches(a:lines, [l:pattern, l:col_pattern, l:symbol_pattern])
|
||||||
if empty(l:match[2]) && empty(l:match[3])
|
if empty(l:match[2]) && empty(l:match[3])
|
||||||
let l:output[-1].col = len(l:match[1])
|
let l:output[-1].col = len(l:match[1])
|
||||||
elseif empty(l:match[3])
|
elseif empty(l:match[3])
|
||||||
" Add symbols to 'cannot find symbol' errors.
|
" Add symbols to 'cannot find symbol' errors.
|
||||||
if l:output[-1].text is# 'error: cannot find symbol'
|
if l:output[-1].text is# 'error: cannot find symbol'
|
||||||
|
@ -78,9 +82,10 @@ function! ale_linters#java#javac#Handle(buffer, lines) abort
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
call add(l:output, {
|
call add(l:output, {
|
||||||
\ 'lnum': l:match[1] + 0,
|
\ 'filename': ale#path#GetAbsPath(l:directory, l:match[1]),
|
||||||
\ 'text': l:match[2] . ':' . l:match[3],
|
\ 'lnum': l:match[2] + 0,
|
||||||
\ 'type': l:match[2] is# 'error' ? 'E' : 'W',
|
\ 'text': l:match[3] . ':' . l:match[4],
|
||||||
|
\ 'type': l:match[3] is# 'error' ? 'E' : 'W',
|
||||||
\})
|
\})
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
|
@ -28,12 +28,15 @@ Before:
|
||||||
|
|
||||||
call ale#test#SetFilename('dummy.java')
|
call ale#test#SetFilename('dummy.java')
|
||||||
|
|
||||||
|
let g:prefix = 'cd ' . ale#Escape(expand('%:p:h')) . ' && javac -Xlint'
|
||||||
|
|
||||||
After:
|
After:
|
||||||
call ale#test#RestoreDirectory()
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
Restore
|
Restore
|
||||||
|
|
||||||
unlet! g:cp_sep
|
unlet! g:cp_sep
|
||||||
|
unlet! g:prefix
|
||||||
|
|
||||||
delfunction GetCommand
|
delfunction GetCommand
|
||||||
|
|
||||||
|
@ -43,20 +46,21 @@ After:
|
||||||
call ale#engine#Cleanup(bufnr(''))
|
call ale#engine#Cleanup(bufnr(''))
|
||||||
|
|
||||||
Execute(The javac callback should return the correct default value):
|
Execute(The javac callback should return the correct default value):
|
||||||
AssertEqual 'javac -Xlint -d TEMP %t', GetCommand([])
|
AssertEqual g:prefix . ' -d TEMP %t', GetCommand([])
|
||||||
|
|
||||||
Execute(The javac callback should use g:ale_java_javac_classpath correctly):
|
Execute(The javac callback should use g:ale_java_javac_classpath correctly):
|
||||||
let g:ale_java_javac_classpath = 'foo.jar'
|
let g:ale_java_javac_classpath = 'foo.jar'
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'javac -Xlint'
|
\ g:prefix
|
||||||
\ . ' -cp ' . ale#Escape('foo.jar')
|
\ . ' -cp ' . ale#Escape('foo.jar')
|
||||||
\ . ' -d TEMP %t',
|
\ . ' -d TEMP %t',
|
||||||
\ GetCommand([])
|
\ GetCommand([])
|
||||||
|
|
||||||
Execute(The javac callback should include discovered classpaths):
|
Execute(The javac callback should include discovered classpaths):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'javac -Xlint -cp '
|
\ g:prefix
|
||||||
|
\ . ' -cp '
|
||||||
\ . ale#Escape(join(['/foo/bar.jar', '/xyz/abc.jar'], g:cp_sep))
|
\ . ale#Escape(join(['/foo/bar.jar', '/xyz/abc.jar'], g:cp_sep))
|
||||||
\ . ' -d TEMP %t',
|
\ . ' -d TEMP %t',
|
||||||
\ GetCommand([
|
\ GetCommand([
|
||||||
|
@ -70,7 +74,8 @@ Execute(The javac callback should combine discovered classpaths and manual ones)
|
||||||
let g:ale_java_javac_classpath = 'configured.jar'
|
let g:ale_java_javac_classpath = 'configured.jar'
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'javac -Xlint -cp '
|
\ g:prefix
|
||||||
|
\ . ' -cp '
|
||||||
\ . ale#Escape(join(
|
\ . ale#Escape(join(
|
||||||
\ [
|
\ [
|
||||||
\ '/foo/bar.jar',
|
\ '/foo/bar.jar',
|
||||||
|
@ -90,7 +95,8 @@ Execute(The javac callback should combine discovered classpaths and manual ones)
|
||||||
let g:ale_java_javac_classpath = 'configured.jar' . g:cp_sep . 'configured2.jar'
|
let g:ale_java_javac_classpath = 'configured.jar' . g:cp_sep . 'configured2.jar'
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'javac -Xlint -cp '
|
\ g:prefix
|
||||||
|
\ . ' -cp '
|
||||||
\ . ale#Escape(join(
|
\ . ale#Escape(join(
|
||||||
\ [
|
\ [
|
||||||
\ '/foo/bar.jar',
|
\ '/foo/bar.jar',
|
||||||
|
@ -114,7 +120,7 @@ Execute(The javac callback should detect source directories):
|
||||||
call ale#engine#InitBufferInfo(bufnr(''))
|
call ale#engine#InitBufferInfo(bufnr(''))
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'javac -Xlint'
|
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && javac -Xlint'
|
||||||
\ . ' -sourcepath ' . ale#Escape(
|
\ . ' -sourcepath ' . ale#Escape(
|
||||||
\ ale#path#Winify(g:dir . '/java_paths/src/main/java/')
|
\ ale#path#Winify(g:dir . '/java_paths/src/main/java/')
|
||||||
\ )
|
\ )
|
||||||
|
@ -127,7 +133,7 @@ Execute(The javac callback should combine detected source directories and classp
|
||||||
call ale#engine#InitBufferInfo(bufnr(''))
|
call ale#engine#InitBufferInfo(bufnr(''))
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'javac -Xlint'
|
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && javac -Xlint'
|
||||||
\ . ' -cp ' . ale#Escape(join(['/foo/bar.jar', '/xyz/abc.jar'], g:cp_sep))
|
\ . ' -cp ' . ale#Escape(join(['/foo/bar.jar', '/xyz/abc.jar'], g:cp_sep))
|
||||||
\ . ' -sourcepath ' . ale#Escape(
|
\ . ' -sourcepath ' . ale#Escape(
|
||||||
\ ale#path#Winify(g:dir . '/java_paths/src/main/java/')
|
\ ale#path#Winify(g:dir . '/java_paths/src/main/java/')
|
||||||
|
@ -146,6 +152,6 @@ Execute(The javac callback should use g:ale_java_javac_options correctly):
|
||||||
let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [])
|
let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [])
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'javac -Xlint'
|
\ g:prefix
|
||||||
\ . ' -d TEMP --anything --else %t',
|
\ . ' -d TEMP --anything --else %t',
|
||||||
\ GetCommand([])
|
\ GetCommand([])
|
||||||
|
|
|
@ -1,42 +1,51 @@
|
||||||
Before:
|
Before:
|
||||||
runtime ale_linters/java/javac.vim
|
runtime ale_linters/java/javac.vim
|
||||||
|
|
||||||
|
call ale#test#SetDirectory('/testplugin/test')
|
||||||
|
call ale#test#SetFilename('dummy.java')
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
call ale#test#RestoreDirectory()
|
||||||
call ale#linter#Reset()
|
call ale#linter#Reset()
|
||||||
|
|
||||||
Execute(The javac handler should handle cannot find symbol errors):
|
Execute(The javac handler should handle cannot find symbol errors):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [
|
\ [
|
||||||
\ {
|
\ {
|
||||||
|
\ 'filename': '/tmp/vLPr4Q5/33/foo.java',
|
||||||
\ 'lnum': 1,
|
\ 'lnum': 1,
|
||||||
\ 'text': 'error: some error',
|
\ 'text': 'error: some error',
|
||||||
\ 'type': 'E',
|
\ 'type': 'E',
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
|
\ 'filename': '/tmp/vLPr4Q5/33/foo.java',
|
||||||
\ 'lnum': 2,
|
\ 'lnum': 2,
|
||||||
\ 'col': 5,
|
\ 'col': 5,
|
||||||
\ 'text': 'error: cannot find symbol: BadName',
|
\ 'text': 'error: cannot find symbol: BadName',
|
||||||
\ 'type': 'E',
|
\ 'type': 'E',
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
|
\ 'filename': '/tmp/vLPr4Q5/33/foo.java',
|
||||||
\ 'lnum': 34,
|
\ 'lnum': 34,
|
||||||
\ 'col': 5,
|
\ 'col': 5,
|
||||||
\ 'text': 'error: cannot find symbol: BadName2',
|
\ 'text': 'error: cannot find symbol: BadName2',
|
||||||
\ 'type': 'E',
|
\ 'type': 'E',
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
|
\ 'filename': '/tmp/vLPr4Q5/33/foo.java',
|
||||||
\ 'lnum': 37,
|
\ 'lnum': 37,
|
||||||
\ 'text': 'warning: some warning',
|
\ 'text': 'warning: some warning',
|
||||||
\ 'type': 'W',
|
\ 'type': 'W',
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
|
\ 'filename': '/tmp/vLPr4Q5/33/foo.java',
|
||||||
\ 'lnum': 42,
|
\ 'lnum': 42,
|
||||||
\ 'col': 11,
|
\ 'col': 11,
|
||||||
\ 'text': 'error: cannot find symbol: bar()',
|
\ 'text': 'error: cannot find symbol: bar()',
|
||||||
\ 'type': 'E',
|
\ 'type': 'E',
|
||||||
\ },
|
\ },
|
||||||
\ ],
|
\ ],
|
||||||
\ ale_linters#java#javac#Handle(347, [
|
\ ale_linters#java#javac#Handle(bufnr(''), [
|
||||||
\ '/tmp/vLPr4Q5/33/foo.java:1: error: some error',
|
\ '/tmp/vLPr4Q5/33/foo.java:1: error: some error',
|
||||||
\ '/tmp/vLPr4Q5/33/foo.java:2: error: cannot find symbol',
|
\ '/tmp/vLPr4Q5/33/foo.java:2: error: cannot find symbol',
|
||||||
\ ' BadName foo() {',
|
\ ' BadName foo() {',
|
||||||
|
@ -49,9 +58,30 @@ Execute(The javac handler should handle cannot find symbol errors):
|
||||||
\ ' symbol: class BadName2',
|
\ ' symbol: class BadName2',
|
||||||
\ ' location: class Bar',
|
\ ' location: class Bar',
|
||||||
\ '/tmp/vLPr4Q5/33/foo.java:37: warning: some warning',
|
\ '/tmp/vLPr4Q5/33/foo.java:37: warning: some warning',
|
||||||
\ '/tmp/vLPr4Q5/264/foo.java:42: error: cannot find symbol',
|
\ '/tmp/vLPr4Q5/33/foo.java:42: error: cannot find symbol',
|
||||||
\ ' this.bar();',
|
\ ' this.bar();',
|
||||||
\ ' ^',
|
\ ' ^',
|
||||||
\ ' symbol: method bar()',
|
\ ' symbol: method bar()',
|
||||||
\ '5 errors',
|
\ '5 errors',
|
||||||
\ ])
|
\ ])
|
||||||
|
|
||||||
|
Execute(The javac handler should resolve files from different directories):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'filename': ale#path#Winify(g:dir . '/Foo.java'),
|
||||||
|
\ 'lnum': 1,
|
||||||
|
\ 'text': 'error: some error',
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'filename': ale#path#Winify(g:dir . '/Bar.java'),
|
||||||
|
\ 'lnum': 1,
|
||||||
|
\ 'text': 'error: some error',
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ ale_linters#java#javac#Handle(bufnr(''), [
|
||||||
|
\ './Foo.java:1: error: some error',
|
||||||
|
\ './Bar.java:1: error: some error',
|
||||||
|
\ ])
|
||||||
|
|
Loading…
Reference in New Issue