Skip to content

Commit aabca01

Browse files
committed
feat: add extract_field command
1 parent f722d0d commit aabca01

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,12 @@ Yep! That's all :)
123123

124124
### Refactor
125125

126-
- `JavaRefactorExtractVariable` - Create a variable from value at cursor
126+
- `JavaRefactorExtractVariable` - Create a variable from value at cursor/selection
127127
- `JavaRefactorExtractVariableAllOccurrence` - Create a variable for all
128-
occurrences from value at cursor
129-
- `JavaRefactorExtractConstant` - Create a constant from the value at cursor
130-
- `JavaRefactorExtractMethod` - Create method from the value at cursor
128+
occurrences from value at cursor/selection
129+
- `JavaRefactorExtractConstant` - Create a constant from the value at cursor/selection
130+
- `JavaRefactorExtractMethod` - Create a method from the value at cursor/selection
131+
- `JavaRefactorExtractField` - Create a field from the value at cursor/selection
131132

132133
### Settings
133134

@@ -220,31 +221,37 @@ require('java').profile.ui()
220221

221222
### Refactor
222223

223-
- `extract_variable` - Create a variable from value at cursor
224+
- `extract_variable` - Create a variable from value at cursor/selection
224225

225226
```lua
226227
require('java').refactor.extract_variable()
227228
```
228229

229230
- `extract_variable_all_occurrence` - Create a variable for all occurrences from
230-
value at cursor
231+
value at cursor/selection
231232

232233
```lua
233234
require('java').refactor.extract_variable_all_occurrence()
234235
```
235236

236-
- `extract_constant` - Create a constant from the value at cursor
237+
- `extract_constant` - Create a constant from the value at cursor/selection
237238

238239
```lua
239240
require('java').refactor.extract_constant()
240241
```
241242

242-
- `extract_method` - Create method from the value at cursor
243+
- `extract_method` - Create method from the value at cursor/selection
243244

244245
```lua
245246
require('java').refactor.extract_method()
246247
```
247248

249+
- `extract_field` - Create a field from the value at cursor/selection
250+
251+
```lua
252+
require('java').refactor.extract_field()
253+
```
254+
248255
### Settings
249256

250257
- `change_runtime` - Change the JDK version to another

lua/java.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ M.refactor = {}
8686
M.refactor.extract_variable = refactor.extract_variable
8787
M.refactor.extract_constant = refactor.extract_constant
8888
M.refactor.extract_method = refactor.extract_method
89+
M.refactor.extract_field = refactor.extract_field
8990
M.refactor.extract_variable_all_occurrence =
9091
refactor.extract_variable_all_occurrence
9192

lua/java/api/refactor.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ function M.extract_method()
2121
M.extract('extractMethod')
2222
end
2323

24+
function M.extract_field()
25+
M.extract('extractField')
26+
end
27+
2428
---
2529
---@param refactor_command jdtls.CodeActionCommand
2630
function M.extract(refactor_command)

lua/java/utils/ui.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local M = {}
88
---@generic T
99
---@param prompt string
1010
---@param values T[]
11-
---@param format_item fun(item: T): string
11+
---@param format_item? fun(item: T): string
1212
---@return T
1313
function M.select(prompt, values, format_item)
1414
return await(function(callback)

plugin/java.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ local cmd_map = {
3333

3434
JavaRefactorExtractMethod = {
3535
java.refactor.extract_method,
36+
{ range = 2 },
3637
},
3738

3839
JavaRefactorExtractConstant = {
@@ -44,6 +45,11 @@ local cmd_map = {
4445
java.refactor.extract_variable_all_occurrence,
4546
{ range = 2 },
4647
},
48+
49+
JavaRefactorExtractField = {
50+
java.refactor.extract_field,
51+
{ range = 2 },
52+
},
4753
}
4854

4955
for cmd, details in pairs(cmd_map) do

0 commit comments

Comments
 (0)