yeet
This commit is contained in:
50
.config/emacs/modules/lang/java/+eclim.el
Normal file
50
.config/emacs/modules/lang/java/+eclim.el
Normal file
@@ -0,0 +1,50 @@
|
||||
;;; lang/java/+eclim.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +eclim)
|
||||
|
||||
;; NOTE This submodule is incomplete
|
||||
|
||||
(use-package! eclim
|
||||
:hook (java-mode . eclim-mode)
|
||||
:config
|
||||
(set-lookup-handlers! 'java-mode
|
||||
:definition #'eclim-java-find-declaration
|
||||
:references #'eclim-java-find-references
|
||||
:documentation #'eclim-java-show-documentation-for-current-element)
|
||||
|
||||
(require 'eclimd)
|
||||
(setq help-at-pt-display-when-idle t
|
||||
help-at-pt-timer-delay 0.1)
|
||||
(help-at-pt-set-timer)
|
||||
|
||||
(map! :localleader
|
||||
:map java-mode-map
|
||||
(:prefix ("r" . "refactor")
|
||||
"gc" #'eclim-java-constructor
|
||||
"gg" #'eclim-java-generate-getter-and-setter
|
||||
"oi" #'eclim-java-import-organize
|
||||
"f" #'eclim-java-format
|
||||
"r" #'eclim-java-refactor-rename-symbol-at-point)
|
||||
(:prefix ("h" . "help")
|
||||
"." #'eclim-java-show-documentation-for-current-element
|
||||
"r" #'eclim-java-find-references
|
||||
"c" #'eclim-java-call-hierarchy
|
||||
"h" #'eclim-java-hierarchy
|
||||
"p" #'eclim-problems
|
||||
"r" #'meghanada-reference
|
||||
"t" #'meghanada-typeinfo)
|
||||
(:prefix ("b" . "build")
|
||||
"b" #'eclim-project-build
|
||||
"c" #'eclim-project-create
|
||||
"d" #'eclim-project-delete
|
||||
"g" #'eclim-project-goto
|
||||
"i" #'eclim-project-import
|
||||
"k" #'eclim-project-close
|
||||
"o" #'eclim-project-open
|
||||
"u" #'eclim-project-update)))
|
||||
|
||||
|
||||
(use-package! company-emacs-eclim
|
||||
:when (featurep! :completion company)
|
||||
:after java-mode
|
||||
:config
|
||||
(set-company-backend! 'java-mode '(company-emacs-eclim)))
|
||||
26
.config/emacs/modules/lang/java/+lsp.el
Normal file
26
.config/emacs/modules/lang/java/+lsp.el
Normal file
@@ -0,0 +1,26 @@
|
||||
;;; lang/java/+lsp.el -*- lexical-binding: t; -*-
|
||||
;;;###if (and (featurep! +lsp) (not (featurep! :tools lsp +eglot)))
|
||||
|
||||
(use-package! lsp-java
|
||||
:after lsp-mode
|
||||
:preface
|
||||
(setq lsp-java-workspace-dir (concat doom-etc-dir "java-workspace"))
|
||||
(add-hook 'java-mode-local-vars-hook #'lsp!)
|
||||
:config
|
||||
(when (featurep! :tools debugger +lsp)
|
||||
(setq lsp-jt-root (concat lsp-java-server-install-dir "java-test/server/")
|
||||
dap-java-test-runner (concat lsp-java-server-install-dir "test-runner/junit-platform-console-standalone.jar"))))
|
||||
|
||||
|
||||
(use-package! dap-java
|
||||
:when (featurep! :tools debugger +lsp)
|
||||
:commands dap-java-run-test-class dap-java-debug-test-class
|
||||
:init
|
||||
(map! :after cc-mode ; where `java-mode' is defined
|
||||
:map java-mode-map
|
||||
:localleader
|
||||
(:prefix ("t" . "Test")
|
||||
:desc "Run test class or method" "t" #'+java/run-test
|
||||
:desc "Run all tests in class" "a" #'dap-java-run-test-class
|
||||
:desc "Debug test class or method" "d" #'+java/debug-test
|
||||
:desc "Debug all tests in class" "D" #'dap-java-debug-test-class)))
|
||||
38
.config/emacs/modules/lang/java/+meghanada.el
Normal file
38
.config/emacs/modules/lang/java/+meghanada.el
Normal file
@@ -0,0 +1,38 @@
|
||||
;;; lang/java/+meghanada.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +meghanada)
|
||||
|
||||
(use-package! meghanada
|
||||
:hook (java-mode-local-vars . meghanada-mode)
|
||||
:init
|
||||
(setq meghanada-server-install-dir (concat doom-etc-dir "meghanada-server/")
|
||||
meghanada-use-company (featurep! :completion company)
|
||||
meghanada-use-flycheck (featurep! :checkers syntax)
|
||||
meghanada-use-eldoc t
|
||||
meghanada-use-auto-start t)
|
||||
|
||||
:config
|
||||
(set-lookup-handlers! 'java-mode
|
||||
:definition #'meghanada-jump-declaration
|
||||
:references #'meghanada-reference)
|
||||
|
||||
(defadvice! +java-meghanada-fail-gracefully-a (fn &rest args)
|
||||
"Toggle `meghanada-mode'. Fail gracefully if java is unavailable."
|
||||
:around #'meghanada-mode
|
||||
(if (executable-find meghanada-java-path)
|
||||
(apply fn args)
|
||||
(message "Can't find %S binary. Is java installed? Aborting `meghanada-mode'."
|
||||
meghanada-java-path)))
|
||||
|
||||
(map! :localleader
|
||||
:map java-mode-map
|
||||
(:prefix ("r" . "refactor")
|
||||
"ia" #'meghanada-import-all
|
||||
"io" #'meghanada-optimize-import
|
||||
"l" #'meghanada-local-variable
|
||||
"f" #'meghanada-code-beautify)
|
||||
(:prefix ("h" . "help")
|
||||
"r" #'meghanada-reference
|
||||
"t" #'meghanada-typeinfo)
|
||||
(:prefix ("b" . "build")
|
||||
"f" #'meghanada-compile-file
|
||||
"p" #'meghanada-compile-project)))
|
||||
148
.config/emacs/modules/lang/java/README.org
Normal file
148
.config/emacs/modules/lang/java/README.org
Normal file
@@ -0,0 +1,148 @@
|
||||
#+TITLE: lang/java
|
||||
#+DATE: January 16, 2017
|
||||
#+SINCE: v1.3
|
||||
#+STARTUP: inlineimages
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#openjdk-11][OpenJDK 11]]
|
||||
- [[#ubuntu][Ubuntu]]
|
||||
- [[#fedora][Fedora]]
|
||||
- [[#oracle-jdk-11][Oracle JDK 11]]
|
||||
- [[#ubuntu-1][Ubuntu]]
|
||||
- [[#fedora-1][Fedora]]
|
||||
- [[#multiple-java-versions][Multiple Java Versions]]
|
||||
- [[#features][Features]]
|
||||
- [[#lsp-features][=+lsp= features]]
|
||||
- [[#meghanada-features][=+meghanada= features]]
|
||||
- [[#configuration][Configuration]]
|
||||
- [[#lsp][=+lsp=]]
|
||||
|
||||
* Description
|
||||
This module adds [[https://www.java.com][java]] support to Doom Emacs, including =android-mode= and
|
||||
=groovy-mode=.
|
||||
|
||||
** Module Flags
|
||||
+ =+lsp= Enables integration for the eclipse.jdt.ls LSP server.
|
||||
+ =+meghanada= Enables the [[https://github.com/mopemope/meghanada-emacs/tree/master][meghanada-mode]]
|
||||
|
||||
The =+lsp= and =+meghanada= packages are mutually exclusive and do not work
|
||||
together. At the time of writing the =+meghanada= is already configured whereas
|
||||
=+lsp= needs to manual configuring.
|
||||
|
||||
The =lsp= test runner requires that =:tools (debugger +lsp)= is enabled, as this
|
||||
provides =dap-mode= which contains the Java test runner.
|
||||
|
||||
* Prerequisites
|
||||
This module requires the Java SDK.
|
||||
|
||||
** OpenJDK 11
|
||||
*** Ubuntu
|
||||
#+BEGIN_SRC sh
|
||||
sudo apt-get install openjdk-11-jdk-headless
|
||||
#+END_SRC
|
||||
*** Fedora
|
||||
#+BEGIN_SRC sh
|
||||
sudo dnf install java-11-openjdk
|
||||
#+END_SRC
|
||||
|
||||
** Oracle JDK 11
|
||||
*** Ubuntu
|
||||
#+BEGIN_SRC sh
|
||||
sudo add-apt-repository ppa:linuxuprising/java
|
||||
sudo apt update
|
||||
sudo apt install oracle-java11-installer
|
||||
sudo apt install oracle-java11-set-default
|
||||
#+END_SRC
|
||||
*** Fedora
|
||||
#+BEGIN_SRC sh
|
||||
curl -O https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
|
||||
tar zxvf openjdk-11.0.2_linux-x64_bin.tar.gz
|
||||
sudo mv jdk-11.0.2/ /usr/local/
|
||||
#+END_SRC
|
||||
|
||||
Open =/etc/profile.d/jdk11.sh= as root and add
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
export JAVA_HOME=/usr/local/jdk-11.0.2
|
||||
export PATH=$PATH:$JAVA_HOME/bin
|
||||
#+END_SRC
|
||||
|
||||
Save the file and source the file
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
source /etc/profile.d/jdk11.sh
|
||||
java -version
|
||||
#+END_SRC
|
||||
|
||||
** Multiple Java Versions
|
||||
It is common to need support for multiple Java versions. You can use a generic
|
||||
tool like [[https://github.com/shyiko/jabba][jabba]] to install and manage multiple Java versions on any OS.
|
||||
|
||||
To switch between Java versions in Doom, you can use [[https://github.com/direnv/direnv][direnv]] and the [[file:~/.emacs.d/modules/tools/direnv/README.org::+TITLE: tools/direnv][direnv module]]. To set a
|
||||
Java version for a particular project, create a =.envrc= pointing to the Java
|
||||
installation in the root of the project:
|
||||
|
||||
#+BEGIN_SRC conf-unix
|
||||
PATH_add ~/.jabba/jdk/adopt@1.11.0-3
|
||||
JAVA_HOME=~/.jabba/jdk/adopt@1.11.0-3
|
||||
#+END_SRC
|
||||
|
||||
And then run =direnv allow .= in the project directory. If the =direnv= module
|
||||
is enabled, then Doom will automatically source this environment before
|
||||
executing the LSP server.
|
||||
|
||||
* Features
|
||||
** =+lsp= features
|
||||
According to [[https://github.com/emacs-lsp/lsp-java]] it adds
|
||||
|
||||
+ As you type reporting of parsing and compilation errors (via flycheck/[[https://github.com/emacs-lsp/lsp-ui][lsp-ui]])
|
||||
+ Code completion - using [[https://github.com/tigersoldier/company-lsp][company-lsp]] or builtin complete-at-point
|
||||
+ Javadoc hovers - using [[https://github.com/emacs-lsp/lsp-ui][lsp-ui]]
|
||||
+ Code actions - using [[https://github.com/emacs-lsp/lsp-ui][lsp-ui]]
|
||||
+ Code outline - using builtin [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Imenu.html][imenu]]
|
||||
+ Code navigation - using builtin [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html][xref]]
|
||||
+ Code lens (references/implementations) - using builtin [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html][xref]]
|
||||
+ Highlights
|
||||
+ Code formatting
|
||||
+ Maven pom.xml project support
|
||||
+ Limited Gradle support
|
||||
+ Visual debugger - [[https://github.com/yyoncho/dap-mode/][dap-mode]]
|
||||
+ Test runner - [[https://github.com/yyoncho/dap-mode/][dap-mode]]
|
||||
+ Project explorer integration - [[https://github.com/Alexander-Miller/treemacs][treemacs]]
|
||||
+ Integration with [[https://start.spring.io/][Spring Initializr]]
|
||||
|
||||
** =+meghanada= features
|
||||
According to [[https://github.com/mopemope/meghanada-emacs/]] it adds
|
||||
|
||||
+ Auto-update server module
|
||||
+ [[https://gradle.org/][Gradle]] and [[http://maven.apache.org/][Maven]] and Eclipse project support
|
||||
+ No need build tool's plugin
|
||||
+ Run build tool task
|
||||
+ Compile your project
|
||||
+ Syntax check and analyze java source (=flycheck-meghanada=)
|
||||
+ Support =Generic Types=
|
||||
+ Code completion with [[http://company-mode.github.io/][company-mode]] (=company-meghanada=)
|
||||
+ Optimize import and sort
|
||||
+ Jump declaration
|
||||
+ Run [[http://www.junit.org/][JUnit]] test (include test runner)
|
||||
+ Diagnostic reporting with [[http://flycheck.org/][flycheck]] (=flycheck-meghanada=)
|
||||
+ Show symbol's type info with =el-doc=
|
||||
+ Search references
|
||||
+ Full-featured text search
|
||||
|
||||
* Configuration
|
||||
** =+lsp=
|
||||
Install the eclipse server by executing =M-x lsp-install-server= and selecting
|
||||
=jdtls=. After that any newly opened =java= files should start the LSP server
|
||||
automatically.
|
||||
|
||||
To update the server, perform =SPC u M-x lsp-install-server=.
|
||||
|
||||
Note that if you change Java version you may need to remove the LSP server and
|
||||
install it again. You can do this with =M-x +lsp/uninstall-server= followed by
|
||||
=M-x lsp-install-server=.
|
||||
|
||||
Enable the =:tools (debugger +lsp)= module to get test runner support.
|
||||
80
.config/emacs/modules/lang/java/autoload/java.el
Normal file
80
.config/emacs/modules/lang/java/autoload/java.el
Normal file
@@ -0,0 +1,80 @@
|
||||
;;; lang/java/autoload/java.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; yasnippet defuns
|
||||
;;;###autoload
|
||||
(defun +java-android-mode-is-layout-file ()
|
||||
(and android-mode
|
||||
(eq major-mode 'nxml-mode)
|
||||
(string-equal (file-name-base (directory-file-name default-directory)) "layout")))
|
||||
|
||||
;;;###autoload
|
||||
(defun +java-android-mode-in-tags (&rest tags)
|
||||
(cl-find (android-mode-tag-name) tags))
|
||||
|
||||
;;;###autoload
|
||||
(defun +java-android-mode-tag-name ()
|
||||
(save-excursion
|
||||
(let (beg end)
|
||||
(nxml-backward-up-element)
|
||||
(evil-forward-word-begin)
|
||||
(setq beg (point))
|
||||
(evil-forward-WORD-end)
|
||||
(setq end (1+ (point)))
|
||||
(buffer-substring-no-properties beg end))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +java-android-mode-maybe-h ()
|
||||
"Enable `android-mode' if this looks like an android project.
|
||||
|
||||
It determines this by the existence of AndroidManifest.xml or
|
||||
src/main/AndroidManifest.xml."
|
||||
(when (project-file-exists-p! (or "AndroidManifest.xml"
|
||||
"src/main/AndroidManifest.xml"))
|
||||
(android-mode +1)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +java-current-package ()
|
||||
"Converts the current file's path into a namespace.
|
||||
|
||||
For example: ~/some/project/src/net/lissner/game/MyClass.java
|
||||
Is converted to: net.lissner.game
|
||||
|
||||
It does this by ignoring everything before the nearest package root (see
|
||||
`+java-project-package-roots' to control what this function considers a package
|
||||
root)."
|
||||
(unless (eq major-mode 'java-mode)
|
||||
(user-error "Not in a java-mode buffer"))
|
||||
(let* ((project-root (file-truename (doom-project-root)))
|
||||
(file-path (file-name-sans-extension
|
||||
(file-truename (or buffer-file-name
|
||||
default-directory))))
|
||||
(src-root (cl-loop for root in +java-project-package-roots
|
||||
if (and (stringp root)
|
||||
(locate-dominating-file file-path root))
|
||||
return (file-name-directory (file-relative-name file-path (expand-file-name root it)))
|
||||
if (and (integerp root)
|
||||
(> root 0)
|
||||
(let* ((parts (split-string (file-relative-name file-path project-root) "/"))
|
||||
(fixed-parts (reverse (nbutlast (reverse parts) root))))
|
||||
(when fixed-parts
|
||||
(string-join fixed-parts "/"))))
|
||||
return it)))
|
||||
(when src-root
|
||||
(string-remove-suffix "." (replace-regexp-in-string "/" "." src-root)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +java-current-class ()
|
||||
"Get the class name for the current file."
|
||||
(unless (eq major-mode 'java-mode)
|
||||
(user-error "Not in a java-mode buffer"))
|
||||
(unless buffer-file-name
|
||||
(user-error "This buffer has no filepath; cannot guess its class name"))
|
||||
(or (file-name-sans-extension (file-name-base (buffer-file-name)))
|
||||
"ClassName"))
|
||||
|
||||
;;;###autoload
|
||||
(defun +java/open-groovy-repl ()
|
||||
"Open a Groovy REPL."
|
||||
(interactive)
|
||||
(call-interactively #'run-groovy)
|
||||
(get-buffer groovy-buffer))
|
||||
22
.config/emacs/modules/lang/java/autoload/lsp.el
Normal file
22
.config/emacs/modules/lang/java/autoload/lsp.el
Normal file
@@ -0,0 +1,22 @@
|
||||
;;; lang/java/autoload/lsp.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! :tools debugger +lsp)
|
||||
|
||||
;;;###autoload
|
||||
(defun +java/run-test ()
|
||||
"Runs test at point.
|
||||
If in a method, runs the test method, otherwise runs the entire test class."
|
||||
(interactive)
|
||||
(require 'dap-java)
|
||||
(condition-case nil
|
||||
(dap-java-run-test-method)
|
||||
(user-error (dap-java-run-test-class))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +java/debug-test ()
|
||||
"Runs test at point in a debugger.
|
||||
If in a method, runs the test method, otherwise runs the entire test class."
|
||||
(interactive)
|
||||
(require 'dap-java)
|
||||
(condition-case nil
|
||||
(call-interactively #'dap-java-debug-test-method)
|
||||
(user-error (call-interactively #'dap-java-debug-test-class))))
|
||||
51
.config/emacs/modules/lang/java/config.el
Normal file
51
.config/emacs/modules/lang/java/config.el
Normal file
@@ -0,0 +1,51 @@
|
||||
;;; lang/java/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +java-project-package-roots (list "java/" "test/" "main/" "src/" 1)
|
||||
"A list of relative directories (strings) or depths (integer) used by
|
||||
`+java-current-package' to delimit the namespace from the current buffer's full
|
||||
file path. Each root is tried in sequence until one is found.
|
||||
|
||||
If a directory is encountered in the file path, everything before it (including
|
||||
it) will be ignored when converting the path into a namespace.
|
||||
|
||||
An integer depth is how many directories to pop off the start of the relative
|
||||
file path (relative to the project root). e.g.
|
||||
|
||||
Say the absolute path is ~/some/project/src/java/net/lissner/game/MyClass.java
|
||||
The project root is ~/some/project
|
||||
If the depth is 1, the first directory in src/java/net/lissner/game/MyClass.java
|
||||
is removed: java.net.lissner.game.
|
||||
If the depth is 2, the first two directories are removed: net.lissner.game.")
|
||||
|
||||
(after! projectile
|
||||
(pushnew! projectile-project-root-files "gradlew" "build.gradle"))
|
||||
|
||||
|
||||
;;
|
||||
;;; java-mode
|
||||
|
||||
(add-hook 'java-mode-hook #'rainbow-delimiters-mode)
|
||||
|
||||
(cond ((featurep! +meghanada) (load! "+meghanada"))
|
||||
((featurep! :tools lsp +eglot))
|
||||
((featurep! +lsp) (load! "+lsp")))
|
||||
|
||||
|
||||
;;
|
||||
;;; Common packages
|
||||
|
||||
(use-package! android-mode
|
||||
:commands android-mode
|
||||
:init
|
||||
(add-hook! '(java-mode-hook groovy-mode-hook nxml-mode-hook)
|
||||
#'+java-android-mode-maybe-h)
|
||||
:config
|
||||
(set-yas-minor-mode! 'android-mode))
|
||||
|
||||
|
||||
(use-package! groovy-mode
|
||||
:mode "\\.g\\(?:radle\\|roovy\\)$"
|
||||
:config
|
||||
(set-docsets! 'groovy-mode "Groovy" "Groovy_JDK")
|
||||
(set-eval-handler! 'groovy-mode "groovy")
|
||||
(set-repl-handler! 'groovy-mode #'+java/open-groovy-repl))
|
||||
13
.config/emacs/modules/lang/java/doctor.el
Normal file
13
.config/emacs/modules/lang/java/doctor.el
Normal file
@@ -0,0 +1,13 @@
|
||||
;; -*- lexical-binding: t; no-byte-compile: t; -*-
|
||||
;;; lang/java/doctor.el
|
||||
|
||||
(assert! (or (not (featurep! +lsp))
|
||||
(featurep! :tools lsp))
|
||||
"This module requires (:tools lsp)")
|
||||
|
||||
(unless (executable-find "javac")
|
||||
(warn! "Couldn't find the javac executable, are you sure the JDK is installed?"))
|
||||
|
||||
(when (featurep! :editor format)
|
||||
(unless (executable-find "clang-format")
|
||||
(warn! "Couldn't find clang-format. Code formatting will not work.")))
|
||||
17
.config/emacs/modules/lang/java/packages.el
Normal file
17
.config/emacs/modules/lang/java/packages.el
Normal file
@@ -0,0 +1,17 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/java/packages.el
|
||||
|
||||
(package! android-mode :pin "d5332e339a1f5e30559a53feffb8442ca79265d6")
|
||||
(package! groovy-mode :pin "84f89b68ec8f79bce0b3f5b29af155a85124e3a6")
|
||||
|
||||
(when (featurep! +meghanada)
|
||||
(package! meghanada :pin "59c46cabb7eee715fe810ce59424934a1286df84"))
|
||||
|
||||
(when (featurep! +eclim)
|
||||
(package! eclim :pin "222ddd48fcf0ee01592dec77c58e0cf3f2ea1100")
|
||||
(when (featurep! :completion company)
|
||||
(package! company-emacs-eclim :pin "222ddd48fcf0ee01592dec77c58e0cf3f2ea1100")))
|
||||
|
||||
(when (featurep! +lsp)
|
||||
(unless (featurep! :tools lsp +eglot)
|
||||
(package! lsp-java :pin "ce03cb6574566e334c3ce5735458cc3ec1989486")))
|
||||
Reference in New Issue
Block a user