1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:00:04 +08:00
SpaceVim/docs/layers/lang/java.md

154 lines
5.1 KiB
Markdown
Raw Permalink Normal View History

2017-07-26 06:39:59 +08:00
---
title: "SpaceVim lang#java layer"
2017-12-19 20:22:19 +08:00
description: "This layer is for Java development. All the features such as code completion, formatting, syntax checking, REPL and debug have be done in this layer."
2017-07-26 06:39:59 +08:00
---
2018-06-23 14:37:41 +08:00
# [Available Layers](../../) >> lang#java
2017-07-26 06:39:59 +08:00
<!-- vim-markdown-toc GFM -->
2017-12-02 23:23:58 +08:00
- [Description](#description)
2017-12-19 20:22:19 +08:00
- [Feature](#feature)
- [Install](#install)
2020-11-16 22:31:00 +08:00
- [Layer options](#layer-options)
2017-12-02 23:23:58 +08:00
- [Key bindings](#key-bindings)
2017-12-19 20:22:19 +08:00
- [Import key bindings](#import-key-bindings)
- [Generate key bindings](#generate-key-bindings)
- [Code formatting](#code-formatting)
2020-11-16 22:31:00 +08:00
- [Maven support](#maven-support)
- [Gradle support](#gradle-support)
- [Code runner](#code-runner)
2017-12-19 20:22:19 +08:00
- [Inferior REPL process](#inferior-repl-process)
2017-07-26 06:39:59 +08:00
<!-- vim-markdown-toc -->
## Description
2017-05-09 22:39:05 +08:00
This layer is for Java development.
2017-12-19 20:22:19 +08:00
## Feature
- code completion: `autocomplete` layer
2020-11-16 22:31:00 +08:00
- code formatting: `format` layer
2017-12-19 20:22:19 +08:00
- refactoring
- syntax checking: `checkers` layer
2020-11-16 22:31:00 +08:00
- REPL(requires `jshell`)
- code runner
2017-12-19 20:22:19 +08:00
- debug: check out the `debug` layer
## Install
2017-05-09 22:39:05 +08:00
2021-06-21 20:39:29 +08:00
To use this configuration layer, update your custom configuration file with:
2018-06-23 14:37:41 +08:00
```toml
[[layers]]
name = "lang#java"
```
2017-05-09 22:39:05 +08:00
2020-11-16 22:31:00 +08:00
## 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_formatter_jar`: Set the full path of [google's formater jar](https://github.com/google/google-java-format).
2020-11-16 22:31:00 +08:00
```toml
[[layers]]
name = 'lang#java'
java_formatter_jar = 'path/to/google-java-format.jar'
2020-11-16 22:31:00 +08:00
```
- `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")`',
'**/',
''
]
```
2017-07-26 06:39:59 +08:00
## Key bindings
2017-12-19 20:22:19 +08:00
### Import key bindings
2017-07-26 06:39:59 +08:00
2020-11-16 22:31:00 +08:00
| Key Bindings | Descriptions |
| ------------------- | ------------------------------- |
| `SPC l I` | Import missing classes |
| `SPC l R` | Remove unused classes |
| `SPC l i` | smart import class under cursor |
| `Ctrl-j I` (Insert) | Import missing classes |
| `Ctrl-j R` (Insert) | Remove unused classes |
| `Ctrl-j i` (Insert) | smart import class under cursor |
2017-07-26 06:39:59 +08:00
2017-12-19 20:22:19 +08:00
### Generate key bindings
2017-07-26 06:39:59 +08:00
2019-02-03 20:51:01 +08:00
| Mode | Key Bindings | Descriptions |
| ------------- | ------------ | ------------------------------------- |
| normal | `SPC l g A` | generate accessors |
| normal/visual | `SPC l g s` | generate setter accessor |
| normal/visual | `SPC l g g` | generate getter accessor |
| normal/visual | `SPC l g a` | generate setter and getter accessor |
| normal | `SPC l g M` | generate abstract methods |
2020-11-16 22:31:00 +08:00
| insert | `Ctrl-j s` | generate setter accessor |
| insert | `Ctrl-j g` | generate getter accessor |
| insert | `Ctrl-j a` | generate getter and setter accessor |
2019-02-03 20:51:01 +08:00
| normal | `SPC l g t` | generate toString function |
| normal | `SPC l g e` | generate equals and hashcode function |
| normal | `SPC l g c` | generate constructor |
| normal | `SPC l g C` | generate default constructor |
2017-07-26 06:39:59 +08:00
2017-12-19 20:22:19 +08:00
### Code formatting
2017-07-26 06:39:59 +08:00
2020-11-16 22:31:00 +08:00
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_formatter_jar` layer option.
2017-05-09 22:39:05 +08:00
2020-11-16 22:31:00 +08:00
The default key bindings for format current buffer is `SPC b f`.
And this key binding is defined in [`format`](../layers/format/) layer.
You can also use `g=` to indent current buffer.
2017-07-26 06:39:59 +08:00
2020-11-16 22:31:00 +08:00
### Maven support
2017-07-26 06:39:59 +08:00
2019-02-03 20:51:01 +08:00
| Key Bindings | Descriptions |
| ------------ | ------------------------------ |
| `SPC l m i` | Run maven clean install |
| `SPC l m I` | Run maven install |
| `SPC l m p` | Run one already goal from list |
| `SPC l m r` | Run maven goals |
| `SPC l m R` | Run one maven goal |
| `SPC l m t` | Run maven test |
2017-07-26 06:39:59 +08:00
2020-11-16 22:31:00 +08:00
### Gradle support
| Key Bindings | Descriptions |
| ------------ | ------------------ |
| `SPC l a b` | gradle build |
| `SPC l a B` | gradle clean build |
| `SPC l a r` | gradle run |
| `SPC l a t` | gradle test |
2020-11-16 22:31:00 +08:00
### Code runner
2017-07-29 17:16:23 +08:00
2020-11-16 22:31:00 +08:00
| Key bindings | Descriptions |
| ------------ | ------------------------------- |
| `SPC l r m` | run main method of current file |
2021-06-21 20:39:29 +08:00
| `SPC l r m` | run the current method |
2020-11-16 22:31:00 +08:00
| `SPC l r t` | run all test methods |
2017-07-29 17:16:23 +08:00
2017-12-19 20:22:19 +08:00
### Inferior REPL process
2019-01-07 21:15:22 +08:00
Start a `jshell` inferior REPL process with `SPC l s i`.
2017-12-19 20:22:19 +08:00
Send code to inferior process commands:
2017-05-09 22:39:05 +08:00
2019-02-03 20:51:01 +08:00
| Key Bindings | Descriptions |
| ------------ | ------------------------------------------------ |
| `SPC l s b` | send buffer and keep code buffer focused |
| `SPC l s l` | send line and keep code buffer focused |
| `SPC l s s` | send selection text and keep code buffer focused |