1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 04:30:04 +08:00

Improve java layer (#3954)

This commit is contained in:
Wang Shidong 2020-11-16 22:31:00 +08:00 committed by GitHub
parent e114730e71
commit 322c56a74d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 234 additions and 96 deletions

View File

@ -195,6 +195,7 @@ let g:spacevim_windows_leader = 's'
"" ""
" Enable/Disable spacevim's insert mode leader, default is enable " Enable/Disable spacevim's insert mode leader, default is enable
" This options has been deprecated.
let g:spacevim_enable_insert_leader = 1 let g:spacevim_enable_insert_leader = 1
"" ""

View File

@ -155,7 +155,7 @@ endfunction
function! SpaceVim#default#keyBindings() abort function! SpaceVim#default#keyBindings() abort
if g:spacevim_enable_insert_leader if g:spacevim_enable_insert_leader
inoremap <silent> <Leader><Tab> <C-r>=MyLeaderTabfunc()<CR> " inoremap <silent> <Leader><Tab> <C-r>=MyLeaderTabfunc()<CR>
endif endif
" yank and paste " yank and paste

View File

@ -9,16 +9,36 @@
"" ""
" @section lang#java, layer-lang-java " @section lang#java, layer-lang-java
" @parentsection layers " @parentsection layers
" This layer is for Java development. " This layer is for java development, disabled by default, to enable this
" layer, add following snippet to your SpaceVim configuration file.
" >
" [[layers]]
" name = 'lang#java'
" <
" @subsection Layer options
" "
" 1. `format_on_save`: Enable/disabled code formatting when saving current file.
" Disabled by default.
" 2. `java_fomatter_jar`: Set the full path of google's java formatter jar.
" 3. `java_file_head`: The default file header for new java file.
" by default it is:
" >
" [[layers]]
" name = 'lang#java'
" java_file_head = [
" '/**',
" ' * @author : `fnamemodify(expand("~"), ":t")`',
" ' * @created : `strftime("%Y-%m-%d")`',
" '**/',
" ''
" ]
" <
" @subsection Mappings " @subsection Mappings
" > " >
" Import key bindings: " Import key bindings:
" "
" Mode Key Function " Mode Key Function
" ------------------------------------------------------------- " -------------------------------------------------------------
" normal <F4> import class under cursor
" insert <F4> import class under cursor
" normal SPC l I import missing classes " normal SPC l I import missing classes
" normal SPC l R remove unused imports " normal SPC l R remove unused imports
" normal SPC l i smart import class under cursor " normal SPC l i smart import class under cursor
@ -88,6 +108,23 @@
" and set 'g:spacevim_layer_lang_java_formatter' to the path of the jar. " and set 'g:spacevim_layer_lang_java_formatter' to the path of the jar.
if exists('s:java_fomatter_jar')
finish
endif
let s:java_fomatter_jar = ''
let s:format_on_save = 0
let s:java_file_head = [
\ '/**',
\ ' * @author : `fnamemodify(expand("~"), ":t")`',
\ ' * @created : `strftime("%Y-%m-%d")`',
\ '**/',
\ ''
\ ]
let s:java_interpreter = 'java'
function! SpaceVim#layers#lang#java#plugins() abort function! SpaceVim#layers#lang#java#plugins() abort
let plugins = [ let plugins = [
\ ['wsdjeg/vim-dict', { 'on_ft' : 'java'}], \ ['wsdjeg/vim-dict', { 'on_ft' : 'java'}],
@ -120,34 +157,41 @@ function! SpaceVim#layers#lang#java#config() abort
let g:neoformat_enabled_java = get(g:, 'neoformat_enabled_java', ['googlefmt']) let g:neoformat_enabled_java = get(g:, 'neoformat_enabled_java', ['googlefmt'])
let g:neoformat_java_googlefmt = { let g:neoformat_java_googlefmt = {
\ 'exe': 'java', \ 'exe': 'java',
\ 'args': ['-jar', get(g:,'spacevim_layer_lang_java_formatter', ''), '-'], \ 'args': ['-jar', s:java_fomatter_jar, '-'],
\ 'stdin': 1, \ 'stdin': 1,
\ } \ }
try try
let g:neoformat_enabled_java += neoformat#formatters#java#enabled() let g:neoformat_enabled_java += neoformat#formatters#java#enabled()
catch catch
endtry endtry
" Format on save
if s:format_on_save
call SpaceVim#layers#format#add_filetype({
\ 'filetype' : 'java',
\ 'enable' : 1,
\ })
endif
call SpaceVim#layers#edit#add_ft_head_tamplate('java', s:java_file_head)
endfunction endfunction
function! s:JspFileTypeInit() abort function! s:JspFileTypeInit() abort
setlocal omnifunc=javacomplete#Complete setlocal omnifunc=javacomplete#Complete
inoremap . <c-r>=OnmiConfigForJsp()<cr> inoremap . <c-r>=OnmiConfigForJsp()<cr>
nnoremap <F4> :JCimportAdd<cr>
inoremap <F4> <esc>:JCimportAddI<cr>
endfunction endfunction
function! s:language_specified_mappings() abort function! s:language_specified_mappings() abort
let g:_spacevim_mappings_space.l = {'name' : '+Language Specified'} let g:_spacevim_mappings_space.l = {'name' : '+Language Specified'}
if g:spacevim_enable_insert_leader " we have removed all insert key bindings which use leader as prefix.
inoremap <silent> <buffer> <leader>UU <esc>bgUwea " because when use leader in insert mode key bindings. vim will wait for
inoremap <silent> <buffer> <leader>uu <esc>bguwea " next key after insert \ in insert mode.
inoremap <silent> <buffer> <leader>ua <esc>bgulea " if g:spacevim_enable_insert_leader
inoremap <silent> <buffer> <leader>Ua <esc>bgUlea " inoremap <silent> <buffer> <leader>UU <esc>bgUwea
endif " inoremap <silent> <buffer> <leader>uu <esc>bguwea
nmap <silent><buffer> <F4> <Plug>(JavaComplete-Imports-Add) " inoremap <silent> <buffer> <leader>ua <esc>bgulea
imap <silent><buffer> <F4> <Plug>(JavaComplete-Imports-Add) " inoremap <silent> <buffer> <leader>Ua <esc>bgUlea
" endif
imap <silent><buffer> <C-j>I <Plug>(JavaComplete-Imports-AddMissing) imap <silent><buffer> <C-j>I <Plug>(JavaComplete-Imports-AddMissing)
imap <silent><buffer> <C-j>R <Plug>(JavaComplete-Imports-RemoveUnused) imap <silent><buffer> <C-j>R <Plug>(JavaComplete-Imports-RemoveUnused)
imap <silent><buffer> <C-j>i <Plug>(JavaComplete-Imports-AddSmart) imap <silent><buffer> <C-j>i <Plug>(JavaComplete-Imports-AddSmart)
@ -199,12 +243,6 @@ function! s:language_specified_mappings() abort
\ '<Plug>(JavaComplete-Generate-NewClass)', \ '<Plug>(JavaComplete-Generate-NewClass)',
\ 'Generate NewClass in current Package', 0) \ 'Generate NewClass in current Package', 0)
" Jump
let g:_spacevim_mappings_space.l.j = {'name' : '+Jump'}
call SpaceVim#mapping#space#langSPC('nnoremap', ['l','j', 'a'], 'call call('
\ . string(function('s:jump_to_alternate')) . ', [])',
\ 'jump to alternate file', 1)
" execute " execute
let g:_spacevim_mappings_space.l.r = {'name' : '+Run'} let g:_spacevim_mappings_space.l.r = {'name' : '+Run'}
" run main method " run main method
@ -212,11 +250,6 @@ function! s:language_specified_mappings() abort
call SpaceVim#mapping#space#langSPC('nmap', ['l','r', 'c'], 'JavaUnitExec', 'Run current method', 1) call SpaceVim#mapping#space#langSPC('nmap', ['l','r', 'c'], 'JavaUnitExec', 'Run current method', 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','r', 'a'], 'JavaUnitTestAll', 'Run all test methods', 1) call SpaceVim#mapping#space#langSPC('nmap', ['l','r', 'a'], 'JavaUnitTestAll', 'Run all test methods', 1)
" debug
let g:_spacevim_mappings_space.l.d = {'name' : '+Debug'}
call SpaceVim#mapping#space#langSPC('nmap', ['l','d', 's'], ':VBGstartJDB', 'start jdb', 0)
call SpaceVim#mapping#space#langSPC('nmap', ['l','d', 't'], 'VBGtoggleBreakpointThisLine', 'toggle breakpoint at this line', 1)
" maven " maven
let g:_spacevim_mappings_space.l.m = {'name' : '+Maven'} let g:_spacevim_mappings_space.l.m = {'name' : '+Maven'}
call SpaceVim#mapping#space#langSPC('nnoremap', ['l','m', 'i'], 'call call(' call SpaceVim#mapping#space#langSPC('nnoremap', ['l','m', 'i'], 'call call('
@ -290,12 +323,17 @@ function! s:execCMD(cmd) abort
call javaunit#util#ExecCMD(a:cmd) call javaunit#util#ExecCMD(a:cmd)
endfunction endfunction
function! s:jump_to_alternate() abort function! SpaceVim#layers#lang#java#set_variable(var) abort
try let s:format_on_save = get(a:var,
A \ 'format_on_save',
catch /^Vim\%((\a\+)\)\=:E464/ \ s:format_on_save)
echom 'no alternate file' let s:java_file_head = get(a:var,
endtry \ 'java_file_head',
\ s:java_file_head)
let s:java_interpreter = get(a:var,
\ 'java_interpreter',
\ s:java_interpreter
\ )
endfunction endfunction
" vim:set et sw=2 cc=80: " vim:set et sw=2 cc=80:

View File

@ -826,7 +826,8 @@ this feature, or you can set to another char.
< <
*g:spacevim_enable_insert_leader* *g:spacevim_enable_insert_leader*
Enable/Disable spacevim's insert mode leader, default is enable Enable/Disable spacevim's insert mode leader, default is enable This options
has been deprecated.
*g:spacevim_data_dir* *g:spacevim_data_dir*
Set the cache directory of SpaceVim. Default is `$XDG_CACHE_HOME` or if not Set the cache directory of SpaceVim. Default is `$XDG_CACHE_HOME` or if not
@ -2375,8 +2376,31 @@ This layer also provides REPL support for janet, the key bindings are:
============================================================================== ==============================================================================
LANG#JAVA *SpaceVim-layer-lang-java* LANG#JAVA *SpaceVim-layer-lang-java*
This layer is for Java development. This layer is for java development, disabled by default, to enable this layer,
add following snippet to your SpaceVim configuration file.
>
[[layers]]
name = 'lang#java'
<
LAYER OPTIONS
1. `format_on_save`: Enable/disabled code formatting when saving current
file. Disabled by default.
2. `java_fomatter_jar`: Set the full path of google's java formatter jar.
3. `java_file_head`: The default file header for new java file. by default
it is:
>
[[layers]]
name = 'lang#java'
java_file_head = [
'/**',
' * @author : `fnamemodify(expand("~"), ":t")`',
' * @created : `strftime("%Y-%m-%d")`',
'**/',
''
]
<
MAPPINGS MAPPINGS
> >
@ -2384,8 +2408,6 @@ MAPPINGS
Mode Key Function Mode Key Function
------------------------------------------------------------- -------------------------------------------------------------
normal <F4> import class under cursor
insert <F4> import class under cursor
normal SPC l I import missing classes normal SPC l I import missing classes
normal SPC l R remove unused imports normal SPC l R remove unused imports
normal SPC l i smart import class under cursor normal SPC l i smart import class under cursor

View File

@ -10,12 +10,14 @@ commentsID: "Use Vim as a Java IDE"
# [Blogs](../blog/) >> Use Vim as a Java IDE # [Blogs](../blog/) >> Use Vim as a Java IDE
This is a general guide for using SpaceVim as a Java IDE, including layer configuration and usage. This tutorial introduces you to SpaceVim as a Java environment,
by using the `lang#java` layer, you make SpaceVim into a great lightweight Java IDE.
Each of the following sections will be covered: Each of the following sections will be covered:
<!-- vim-markdown-toc GFM --> <!-- vim-markdown-toc GFM -->
- [Installation](#installation) - [Enable language layer](#enable-language-layer)
- [Language server](#language-server) - [Language server](#language-server)
- [Code completion](#code-completion) - [Code completion](#code-completion)
- [Code outline](#code-outline) - [Code outline](#code-outline)
@ -24,22 +26,24 @@ Each of the following sections will be covered:
- [Syntax lint](#syntax-lint) - [Syntax lint](#syntax-lint)
- [Import packages](#import-packages) - [Import packages](#import-packages)
- [Jump to test file](#jump-to-test-file) - [Jump to test file](#jump-to-test-file)
- [running code](#running-code) - [Code running](#code-running)
- [Code formatting](#code-formatting) - [Code formatting](#code-formatting)
- [REPL](#repl) - [REPL](#repl)
<!-- vim-markdown-toc --> <!-- vim-markdown-toc -->
### Installation This tutorial is not intended to teach you Java itself.
SpaceVim is a Vim and neovim configuration, so you need to install vim or neovim, If you have any problems,
here are two guides for installing neovim and vim8 with `+python3` feature. feel free to join the [SpaceVim gitter chatting room](https://gitter.im/SpaceVim/SpaceVim)
following the [quick start guide](../quick-start-guide/) to install SpaceVim. for general discussion.
SpaceVim do not enable language layer by default, so you need to enable `lang#java` layer. ### Enable language layer
`lang#java` layer is not loaded by default in SpaceVim, to use SpaceVim for java,
you need to enable this layer in SpaceVim configuration file.
Press `SPC f v d` to open SpaceVim configuration file, and add following section: Press `SPC f v d` to open SpaceVim configuration file, and add following section:
```toml ```toml
[[layers]] [[layers]]
name = "lang#java" name = "lang#java"
@ -74,7 +78,6 @@ To enable language server protocol support, you may need to enable lsp layer.
] ]
``` ```
You need to replace `D:\dev\jdt-language-server-latest\plugins\org.eclipse.equinox.launcher_1.5.200.v20180922-1751.jar` with the actual name of the org.eclipse.equinox.launcher jar You need to replace `D:\dev\jdt-language-server-latest\plugins\org.eclipse.equinox.launcher_1.5.200.v20180922-1751.jar` with the actual name of the org.eclipse.equinox.launcher jar
The configuration flag can point to either: The configuration flag can point to either:
@ -106,7 +109,8 @@ then press `Leader f o`:
### Rename symbol ### Rename symbol
After enable lsp layer for java, you can use `SPC l e` to rename symbol under the cursor: To rename java symbol, you need to enable `lsp` layer for java. The default key binding
for rename symbol under the cursor is `SPC l e`.
![rename java symblo](https://user-images.githubusercontent.com/13142418/53250190-da115580-36f4-11e9-9590-bf945fa8dcc0.gif) ![rename java symblo](https://user-images.githubusercontent.com/13142418/53250190-da115580-36f4-11e9-9590-bf945fa8dcc0.gif)
@ -132,8 +136,10 @@ within above picture, we can see the checkers layer provides following feature:
### Import packages ### Import packages
There are two kind features for importing packages, import packages automatically and manually. SpaceVim will import the packages after selecting the class name on popmenu. There are two kind features for importing packages, import packages automatically and manually.
Also, you can use key binding `<F4>` to import the class at the cursor point. If there are more than one class, a menu will be shown below current windows. SpaceVim will import the packages after selecting the class name on popmenu.
Also, you can use key binding `SPC l i` to import the class at the cursor point.
If there are more than one class, a menu will be shown below current windows.
![import class](https://user-images.githubusercontent.com/13142418/46298485-c04e6500-c5d1-11e8-96f3-01d84f9fe237.png) ![import class](https://user-images.githubusercontent.com/13142418/46298485-c04e6500-c5d1-11e8-96f3-01d84f9fe237.png)
@ -143,8 +149,10 @@ SpaceVim use vim-project to manager the files in a project, you can add a `.proj
```json ```json
{ {
"src/main/java/*.java": {"alternate": "src/test/java/{dirname}/Test{basename}.java"}, "src/main/java/*.java": {
"src/test/java/**/Test*.java": {"alternate": "src/main/java/{}.java"} "alternate": "src/test/java/{dirname}/Test{basename}.java"
},
"src/test/java/**/Test*.java": { "alternate": "src/main/java/{}.java" }
} }
``` ```
@ -152,18 +160,25 @@ with this configuration, you can jump between the source code and test file via
![jump-test](https://user-images.githubusercontent.com/13142418/46322905-12b57300-c61e-11e8-81a2-53c69d10140f.gif) ![jump-test](https://user-images.githubusercontent.com/13142418/46322905-12b57300-c61e-11e8-81a2-53c69d10140f.gif)
### Code running
### running code
Base on JavaUnite, you can use `SPC l r c` to run current function or use `SPC l r m` to run the main function of current Class. Base on JavaUnite, you can use `SPC l r c` to run current function or use `SPC l r m` to run the main function of current Class.
![run-main](https://user-images.githubusercontent.com/13142418/46323137-61174180-c61f-11e8-94df-61b6998b8907.gif) ![run-main](https://user-images.githubusercontent.com/13142418/46323137-61174180-c61f-11e8-94df-61b6998b8907.gif)
### Code formatting ### Code formatting
For formatting java code, you also nEed have [uncrustify](https://github.com/uncrustify/uncrustify) or [astyle](http://astyle.sourceforge.net/) in your PATH. Code formatting is provided by `format` layer, which is loaded by default.
BTW, the google's [java formatter](https://github.com/google/google-java-format) also works well with neoformat. The default format engine is `neoformat`, it will run google's [java formatter](https://github.com/google/google-java-format)
asynchronously. The key binding for formatting current file is `SPC b f`.
To use this feature, you need to download the google's java formatter jar, and set the
path of this jar file in layer option.
```toml
[[layers]]
name = 'lang#java'
java_fomatter_jar = 'path/to/google-java-format.jar'
```
![format-java](https://user-images.githubusercontent.com/13142418/46323426-ccadde80-c620-11e8-9726-d99025f3bf76.gif) ![format-java](https://user-images.githubusercontent.com/13142418/46323426-ccadde80-c620-11e8-9726-d99025f3bf76.gif)
@ -172,4 +187,3 @@ BTW, the google's [java formatter](https://github.com/google/google-java-format)
you need to install jdk9 which provide a build-in tools `jshell`, and SpaceVim use the `jshell` as default inferior REPL process: you need to install jdk9 which provide a build-in tools `jshell`, and SpaceVim use the `jshell` as default inferior REPL process:
![REPl-JAVA](https://user-images.githubusercontent.com/13142418/34159605-758461ba-e48f-11e7-873c-fc358ce59a42.gif) ![REPl-JAVA](https://user-images.githubusercontent.com/13142418/34159605-758461ba-e48f-11e7-873c-fc358ce59a42.gif)

View File

@ -11,12 +11,12 @@ lang: zh
- [模块描述](#模块描述) - [模块描述](#模块描述)
- [功能特性](#功能特性) - [功能特性](#功能特性)
- [启用模块](#启用模块) - [启用模块](#启用模块)
- [模块选项](#模块选项)
- [快捷键](#快捷键) - [快捷键](#快捷键)
- [导包相关快捷键](#导包相关快捷键) - [导包相关快捷键](#导包相关快捷键)
- [代码生成相关快捷键](#代码生成相关快捷键) - [代码生成相关快捷键](#代码生成相关快捷键)
- [代码格式化](#代码格式化) - [代码格式化](#代码格式化)
- [Maven](#maven) - [Maven](#maven)
- [Jump](#jump)
- [交互式编程](#交互式编程) - [交互式编程](#交互式编程)
<!-- vim-markdown-toc --> <!-- vim-markdown-toc -->
@ -43,13 +43,40 @@ lang: zh
name = "lang#java" name = "lang#java"
``` ```
## 模块选项
- `format_on_save`: 启用/禁用保存文件时自动格式化,默认的值为 `false`
可以使用如下配置启用该功能:
```toml
[[layers]]
name = 'lang#java'
format_on_save = true
```
- `java_fomatter_jar`: 设置 [谷歌格式化工具](https://github.com/google/google-java-format) 的具体路径。
```toml
[[layers]]
name = 'lang#java'
java_fomatter_jar = 'path/to/google-java-format.jar'
```
- `java_file_head`: 默认的文件头,当新建 Java 文件时自动加入。
```toml
[[layers]]
name = 'lang#java'
java_file_head = [
'/**',
' * @author : `fnamemodify(expand("~"), ":t")`',
' * @created : `strftime("%Y-%m-%d")`',
'**/',
''
]
```
## 快捷键 ## 快捷键
### 导包相关快捷键 ### 导包相关快捷键
| 模式 | 快捷键 | 按键描述 | | 模式 | 快捷键 | 按键描述 |
| ------------- | --------- | ------------------ | | ------------- | --------- | ------------------ |
| Insert/Normal | `<F4>` | 导入光标下的类 |
| Normal | `SPC l I` | 导入所有缺失的类 | | Normal | `SPC l I` | 导入所有缺失的类 |
| Normal | `SPC l R` | 删除多余的导包 | | Normal | `SPC l R` | 删除多余的导包 |
| Normal | `SPC l i` | 智能导入光标下的类 | | Normal | `SPC l i` | 智能导入光标下的类 |
@ -78,12 +105,13 @@ lang: zh
默认的代码格式化快捷键是 `SPC b f`,该快捷键由 `format` 模块定义,同时也可以通过 `g =` 来对齐整个文档。 默认的代码格式化快捷键是 `SPC b f`,该快捷键由 `format` 模块定义,同时也可以通过 `g =` 来对齐整个文档。
为了使 format 模块支持 Java 文件,需要安装 uncrustify 或者下载 [google's formater jar](https://github.com/google/google-java-format)。 为了使 format 模块支持 Java 文件,需要安装 [google's formater jar](https://github.com/google/google-java-format)。
同时,需要设置 SpaceVim 选项`layer_lang_java_formatter` 同时,需要设置模块选项`java_fomatter_jar`
```toml ```toml
[options] [[layers]]
layer_lang_java_formatter = "path/to/google-java-format.jar" name = 'lang#java'
java_fomatter_jar = 'path/to/google-java-format.jar'
``` ```
### Maven ### Maven
@ -97,12 +125,6 @@ lang: zh
| `SPC l m R` | Run one maven goal | | `SPC l m R` | Run one maven goal |
| `SPC l m t` | Run maven test | | `SPC l m t` | Run maven test |
### Jump
| 快捷键 | 描述 |
| ----------- | ---------------------- |
| `SPC l j a` | jump to alternate file |
### 交互式编程 ### 交互式编程
启动 `jshell` 交互进程,快捷键为: `SPC l s i` 启动 `jshell` 交互进程,快捷键为: `SPC l s i`

View File

@ -10,12 +10,14 @@ description: "This layer is for Java development. All the features such as code
- [Description](#description) - [Description](#description)
- [Feature](#feature) - [Feature](#feature)
- [Install](#install) - [Install](#install)
- [Layer options](#layer-options)
- [Key bindings](#key-bindings) - [Key bindings](#key-bindings)
- [Import key bindings](#import-key-bindings) - [Import key bindings](#import-key-bindings)
- [Generate key bindings](#generate-key-bindings) - [Generate key bindings](#generate-key-bindings)
- [Code formatting](#code-formatting) - [Code formatting](#code-formatting)
- [Maven](#maven) - [Maven support](#maven-support)
- [Jump](#jump) - [Gradle support](#gradle-support)
- [Code runner](#code-runner)
- [Inferior REPL process](#inferior-repl-process) - [Inferior REPL process](#inferior-repl-process)
<!-- vim-markdown-toc --> <!-- vim-markdown-toc -->
@ -27,10 +29,11 @@ This layer is for Java development.
## Feature ## Feature
- code completion: `autocomplete` layer - code completion: `autocomplete` layer
- code formatting - code formatting: `format` layer
- refactoring - refactoring
- syntax checking: `checkers` layer - syntax checking: `checkers` layer
- REPL(need java8's jshell) - REPL(requires `jshell`)
- code runner
- debug: check out the `debug` layer - debug: check out the `debug` layer
## Install ## Install
@ -42,19 +45,46 @@ To use this configuration layer, update custom configuration file with:
name = "lang#java" name = "lang#java"
``` ```
## Layer options
- `format_on_save`: Enable/disabled code formatting when saving current file.
The default value is `false`. To enable this feature:
```toml
[[layers]]
name = 'lang#java'
format_on_save = true
```
- `java_fomatter_jar`: Set the full path of [google's formater jar](https://github.com/google/google-java-format).
```toml
[[layers]]
name = 'lang#java'
java_fomatter_jar = 'path/to/google-java-format.jar'
```
- `java_file_head`: The default file header for new java file. by default it is:
```toml
[[layers]]
name = 'lang#java'
java_file_head = [
'/**',
' * @author : `fnamemodify(expand("~"), ":t")`',
' * @created : `strftime("%Y-%m-%d")`',
'**/',
''
]
```
## Key bindings ## Key bindings
### Import key bindings ### Import key bindings
| Key Bindings | Descriptions | | Key Bindings | Descriptions |
| -------------------- | ------------------------------- | | ------------------- | ------------------------------- |
| `<F4>` (Insert/Normal) | Import class under cursor | | `SPC l I` | Import missing classes |
| `SPC l I` | Import missing classes | | `SPC l R` | Remove unused classes |
| `SPC l R` | Remove unused classes | | `SPC l i` | smart import class under cursor |
| `SPC l i` | smart import class under cursor | | `Ctrl-j I` (Insert) | Import missing classes |
| `Ctrl-j I` (Insert) | Import missing classes | | `Ctrl-j R` (Insert) | Remove unused classes |
| `Ctrl-j R` (Insert) | Remove unused classes | | `Ctrl-j i` (Insert) | smart import class under cursor |
| `Ctrl-j i` (Insert) | smart import class under cursor |
### Generate key bindings ### Generate key bindings
@ -65,9 +95,9 @@ To use this configuration layer, update custom configuration file with:
| normal/visual | `SPC l g g` | generate getter accessor | | normal/visual | `SPC l g g` | generate getter accessor |
| normal/visual | `SPC l g a` | generate setter and getter accessor | | normal/visual | `SPC l g a` | generate setter and getter accessor |
| normal | `SPC l g M` | generate abstract methods | | normal | `SPC l g M` | generate abstract methods |
| insert | `Ctrl-j s` | generate setter accessor | | insert | `Ctrl-j s` | generate setter accessor |
| insert | `Ctrl-j g` | generate getter accessor | | insert | `Ctrl-j g` | generate getter accessor |
| insert | `Ctrl-j a` | generate getter and setter accessor | | insert | `Ctrl-j a` | generate getter and setter accessor |
| normal | `SPC l g t` | generate toString function | | normal | `SPC l g t` | generate toString function |
| normal | `SPC l g e` | generate equals and hashcode function | | normal | `SPC l g e` | generate equals and hashcode function |
| normal | `SPC l g c` | generate constructor | | normal | `SPC l g c` | generate constructor |
@ -75,14 +105,14 @@ To use this configuration layer, update custom configuration file with:
### Code formatting ### Code formatting
The default key bindings for format current buffer is `SPC b f`. And this key binding is defined in [format layer](<>). You can also use `g=` to indent current buffer. The default formater of java language is [google's formater jar](https://github.com/google/google-java-format).
You need to download the jar and set the `java_fomatter_jar` layer option.
To make neoformat support Java file, you should install uncrustify. The default key bindings for format current buffer is `SPC b f`.
Or download [google's formater jar](https://github.com/google/google-java-format) And this key binding is defined in [`format`](../layers/format/) layer.
and add `let g:spacevim_layer_lang_java_formatter = 'path/to/google-java-format.jar'` You can also use `g=` to indent current buffer.
to SpaceVim custom configuration file.
### Maven ### Maven support
| Key Bindings | Descriptions | | Key Bindings | Descriptions |
| ------------ | ------------------------------ | | ------------ | ------------------------------ |
@ -93,11 +123,22 @@ to SpaceVim custom configuration file.
| `SPC l m R` | Run one maven goal | | `SPC l m R` | Run one maven goal |
| `SPC l m t` | Run maven test | | `SPC l m t` | Run maven test |
### Jump ### Gradle support
| Key Bindings | Descriptions | | Key Bindings | Descriptions |
| ------------ | ---------------------- | | ------------ | ------------------ |
| `SPC l j a` | jump to alternate file | | `SPC l g b` | gradle build |
| `SPC l g B` | gradle clean build |
| `SPC l g r` | gradle run |
| `SPC l g t` | gradle test |
### Code runner
| Key bindings | Descriptions |
| ------------ | ------------------------------- |
| `SPC l r m` | run main method of current file |
| `SPC l r m` | run current method |
| `SPC l r t` | run all test methods |
### Inferior REPL process ### Inferior REPL process