Fix #502 - Report undefined symbol errors better for javac
This commit is contained in:
		
							parent
							
								
									528355e2c6
								
							
						
					
					
						commit
						8e70dc14f2
					
				| @ -85,15 +85,23 @@ function! ale_linters#java#javac#Handle(buffer, lines) abort | ||||
|     " Main.java:13: warning: [deprecation] donaught() in Testclass has been deprecated | ||||
|     " Main.java:16: error: ';' expected | ||||
| 
 | ||||
|     let l:pattern = '^.*\:\(\d\+\):\ \(.*\):\(.*\)$' | ||||
|     let l:pattern = '\v^.*:(\d+): (.+):(.+)$' | ||||
|     let l:symbol_pattern = '\v^ +symbol: *(class) +([^ ]+)' | ||||
|     let l:output = [] | ||||
| 
 | ||||
|     for l:match in ale#util#GetMatches(a:lines, l:pattern) | ||||
|         call add(l:output, { | ||||
|         \   'lnum': l:match[1] + 0, | ||||
|         \   'text': l:match[2] . ':' . l:match[3], | ||||
|         \   'type': l:match[2] ==# 'error' ? 'E' : 'W', | ||||
|         \}) | ||||
|     for l:match in ale#util#GetMatches(a:lines, [l:pattern, l:symbol_pattern]) | ||||
|         if empty(l:match[3]) | ||||
|             " Add symbols to 'cannot find symbol' errors. | ||||
|             if l:output[-1].text ==# 'error: cannot find symbol' | ||||
|                 let l:output[-1].text .= ': ' . l:match[2] | ||||
|             endif | ||||
|         else | ||||
|             call add(l:output, { | ||||
|             \   'lnum': l:match[1] + 0, | ||||
|             \   'text': l:match[2] . ':' . l:match[3], | ||||
|             \   'type': l:match[2] ==# 'error' ? 'E' : 'W', | ||||
|             \}) | ||||
|         endif | ||||
|     endfor | ||||
| 
 | ||||
|     return l:output | ||||
|  | ||||
							
								
								
									
										45
									
								
								test/handler/test_javac_handler.vader
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								test/handler/test_javac_handler.vader
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,45 @@ | ||||
| Before: | ||||
|   runtime ale_linters/java/javac.vim | ||||
| 
 | ||||
| After: | ||||
|   call ale#linter#Reset() | ||||
| 
 | ||||
| Execute(The javac handler should handle cannot find symbol errors): | ||||
|   AssertEqual | ||||
|   \ [ | ||||
|   \   { | ||||
|   \     'lnum': 1, | ||||
|   \     'text': 'error: some error', | ||||
|   \     'type': 'E', | ||||
|   \   }, | ||||
|   \   { | ||||
|   \     'lnum': 2, | ||||
|   \     'text': 'error: cannot find symbol: BadName', | ||||
|   \     'type': 'E', | ||||
|   \   }, | ||||
|   \   { | ||||
|   \     'lnum': 34, | ||||
|   \     'text': 'error: cannot find symbol: BadName2', | ||||
|   \     'type': 'E', | ||||
|   \   }, | ||||
|   \   { | ||||
|   \     'lnum': 37, | ||||
|   \     'text': 'warning: some warning', | ||||
|   \     'type': 'W', | ||||
|   \   }, | ||||
|   \ ], | ||||
|   \ ale_linters#java#javac#Handle(347, [ | ||||
|   \   '/tmp/vLPr4Q5/33/foo.java:1: error: some error', | ||||
|   \   '/tmp/vLPr4Q5/33/foo.java:2: error: cannot find symbol', | ||||
|   \   '    BadName foo() {', | ||||
|   \   '    ^', | ||||
|   \   '  symbol:   class BadName', | ||||
|   \   '  location: class Bar', | ||||
|   \   '/tmp/vLPr4Q5/33/foo.java:34: error: cannot find symbol', | ||||
|   \   '    BadName2 foo() {', | ||||
|   \   '    ^', | ||||
|   \   '  symbol:   class BadName2', | ||||
|   \   '  location: class Bar', | ||||
|   \   '/tmp/vLPr4Q5/33/foo.java:37: warning: some warning', | ||||
|   \   '4 errors', | ||||
|   \ ]) | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 w0rp
						w0rp