|
| 1 | +*jc.txt* Java code generation layer over an external jdtls |
| 2 | + |
| 3 | +Author: Artur Shaik |
| 4 | +License: same as the plugin repository |
| 5 | + |
| 6 | +============================================================================== |
| 7 | +CONTENTS *jc-contents* |
| 8 | + |
| 9 | + 1. Introduction ........................... |jc-introduction| |
| 10 | + 2. Requirements ........................... |jc-requirements| |
| 11 | + 3. Setup .................................. |jc-setup| |
| 12 | + 4. Commands ............................... |jc-commands| |
| 13 | + 5. Mappings ............................... |jc-mappings| |
| 14 | + 6. Debugging .............................. |jc-debug| |
| 15 | + 7. Class creation ......................... |jc-class-creation| |
| 16 | + 8. Health ................................. |jc-health| |
| 17 | + |
| 18 | +============================================================================== |
| 19 | +1. INTRODUCTION *jc-introduction* |
| 20 | + |
| 21 | +jc.nvim is a layer on top of an externally managed Eclipse JDT language |
| 22 | +server (jdtls). It never starts or installs the server itself — it hooks |
| 23 | +into whatever `jdtls` LSP client attaches (nvim-java, nvim-jdtls, |
| 24 | +nvim-lspconfig) and provides: |
| 25 | + |
| 26 | +- organize imports with smart selection of remembered classes; |
| 27 | +- code generation: `toString`, `hashCode`/`equals`, constructors, |
| 28 | + accessors, with interactive field selection; |
| 29 | +- adding unimplemented (abstract) methods; |
| 30 | +- debug attach/launch via nvim-dap or vimspector with per-project |
| 31 | + host/port memory; |
| 32 | +- decompiled `jdt://` class contents view; |
| 33 | +- template-based class creation (|jc-class-creation|). |
| 34 | + |
| 35 | +============================================================================== |
| 36 | +2. REQUIREMENTS *jc-requirements* |
| 37 | + |
| 38 | +- Neovim >= 0.10 (0.11+ recommended); |
| 39 | +- a running jdtls managed by nvim-java, nvim-jdtls or lspconfig. The |
| 40 | + server must be started with `extendedClientCapabilities` — notably |
| 41 | + `executeClientCommandSupport` and `advancedOrganizeImportsSupport`. |
| 42 | + nvim-java and nvim-jdtls do this out of the box; |
| 43 | +- for debug attach/launch: the java-debug bundle loaded into jdtls |
| 44 | + (nvim-java bundles it; with nvim-jdtls add it to |
| 45 | + `init_options.bundles`) and nvim-dap or vimspector installed; |
| 46 | +- optional nvim-jdtls for extract refactorings and `JCutil*` commands. |
| 47 | + |
| 48 | +============================================================================== |
| 49 | +3. SETUP *jc-setup* |
| 50 | + |
| 51 | +Call `setup` (or use the `opts` table of lazy.nvim): >lua |
| 52 | + |
| 53 | + require("jc").setup({ |
| 54 | + keys_prefix = "<leader>j", -- prefix for default mappings |
| 55 | + default_mappings = true, -- install default mappings on attach |
| 56 | + autoformat_on_save = false, -- format java buffers on save |
| 57 | + debug_backend = nil, -- "dap" | "vimspector" | nil = auto |
| 58 | + basedir = nil, -- data dir, ~/.local/share/jc.nvim |
| 59 | + on_attach = nil, -- function(client, bufnr) extra hook |
| 60 | + }) |
| 61 | +< |
| 62 | + *jc-legacy-vars* |
| 63 | +The legacy global variables `g:jc_default_mappings`, |
| 64 | +`g:jc_autoformat_on_save`, `g:jc_debug_backend` and `g:jc_basedir` are |
| 65 | +still honored as a fallback when the corresponding option is not passed |
| 66 | +to `setup`. |
| 67 | + |
| 68 | +If `setup` is never called, opening a java file initializes the plugin |
| 69 | +with defaults. |
| 70 | + |
| 71 | +============================================================================== |
| 72 | +4. COMMANDS *jc-commands* |
| 73 | + |
| 74 | + :JCimportsOrganizeSmart organize imports, auto-pick remembered |
| 75 | + candidates |
| 76 | + :JCimportsOrganize organize imports with manual selection |
| 77 | + :JCgenerateToString generate toString() with field selection |
| 78 | + :JCgenerateHashCodeAndEquals generate hashCode() and equals() |
| 79 | + :JCgenerateAccessors choose fields for accessors generation |
| 80 | + :JCgenerateAccessorGetter generate getter for a field |
| 81 | + :JCgenerateAccessorSetter generate setter for a field |
| 82 | + :JCgenerateAccessorSetterGetter generate getter and setter |
| 83 | + :JCgenerateConstructorDefault generate no-arg constructor |
| 84 | + :JCgenerateConstructor choose fields for constructor |
| 85 | + :JCgenerateAbstractMethods generate unimplemented methods |
| 86 | + :JCgenerateClass start class generation prompt |
| 87 | + :JCtoggleAutoformat toggle autoformat on save |
| 88 | + :JCdebugAttach attach debugger (dap or vimspector) |
| 89 | + :JCdebugLaunch launch debug session |
| 90 | + :JCdapAttach attach via nvim-dap explicitly |
| 91 | + :JCvimspectorAttach attach via vimspector explicitly |
| 92 | + :JCdebugWithConfig choose a vimspector configuration |
| 93 | + |
| 94 | +With nvim-jdtls installed: |
| 95 | + |
| 96 | + :JCrefactorExtractVar extract variable |
| 97 | + :JCrefactorExtractMethod extract method |
| 98 | + :JCutilJshell run java shell |
| 99 | + :JCutilBytecode show bytecode for current class |
| 100 | + :JCutilJol analyze object layout (jol) |
| 101 | + :JCutilUpdateConfig update project configuration |
| 102 | + |
| 103 | +============================================================================== |
| 104 | +5. MAPPINGS *jc-mappings* |
| 105 | + |
| 106 | +Installed on jdtls attach when `default_mappings` is enabled. `<p>` is |
| 107 | +`keys_prefix` (default `<leader>j`). |
| 108 | + |
| 109 | + n <p>i organize imports (smart) |
| 110 | + n <p>I organize imports (manual selection) |
| 111 | + i <C-j>i organize imports |
| 112 | + n <p>ts generate toString() |
| 113 | + n <p>eq generate hashCode() and equals() |
| 114 | + n <p>A generate accessors (field selection) |
| 115 | + n <p>s generate setter |
| 116 | + n <p>g generate getter |
| 117 | + n <leader>ja generate getter and setter |
| 118 | + i <C-j>s / <C-j>g / <C-j>a accessor generation |
| 119 | + n <p>c generate constructor (field selection) |
| 120 | + n <p>cc generate default constructor |
| 121 | + n <p>m generate abstract methods |
| 122 | + i <C-j>m generate abstract methods |
| 123 | + n <p>n new class prompt |
| 124 | + n <p>da debug attach |
| 125 | + n <p>dl debug launch |
| 126 | + |
| 127 | +With nvim-jdtls: |
| 128 | + |
| 129 | + v <p>re extract variable |
| 130 | + n <leader>jre extract variable |
| 131 | + v <p>rm extract method |
| 132 | + |
| 133 | +============================================================================== |
| 134 | +6. DEBUGGING *jc-debug* |
| 135 | + |
| 136 | +`JCdebugAttach`/`JCdebugLaunch` route to a backend: |
| 137 | + |
| 138 | +1. `debug_backend` option / `g:jc_debug_backend` if set |
| 139 | + ("dap" or "vimspector"); |
| 140 | +2. auto: nvim-dap installed and vimspector absent -> dap; |
| 141 | +3. fallback: vimspector. |
| 142 | + |
| 143 | +Attach asks for host and port (defaults remembered per project under |
| 144 | +the data dir). The adapter port is resolved from jdtls via |
| 145 | +`vscode.java.startDebugSession`, which requires the java-debug bundle. |
| 146 | + |
| 147 | +============================================================================== |
| 148 | +7. CLASS CREATION *jc-class-creation* |
| 149 | + |
| 150 | +Prompt scheme: > |
| 151 | +
|
| 152 | + template:[subdir]:/package.ClassName extends Super implements If(String s, public Integer i):constructor:toString:equals |
| 153 | +< |
| 154 | +- template (optional): junit, interface, exception, servlet, ...; |
| 155 | +- subdir (optional): e.g. test, androidTest; |
| 156 | +- class name and package; with `/` parent package backsearch is used; |
| 157 | +- extends/implements classes are imported automatically; |
| 158 | +- field list: `private` by default, modifiers can be given; |
| 159 | +- trailing flags: constructor, toString, equals, hashCode. |
| 160 | + |
| 161 | +============================================================================== |
| 162 | +8. HEALTH *jc-health* |
| 163 | + |
| 164 | +Run `:checkhealth jc` to verify: neovim version, attached jdtls client, |
| 165 | +organize-imports and java-debug availability, optional integrations |
| 166 | +(nvim-jdtls, nvim-dap/vimspector), treesitter java parser and data dir |
| 167 | +permissions. |
| 168 | + |
| 169 | +vim:tw=78:ts=8:noet:ft=help:norl: |
0 commit comments