2020-02-19 23:07:30 +00:00
|
|
|
|
;;; funcs.el --- Java functions File for Spacemacs
|
2015-07-04 04:29:25 +00:00
|
|
|
|
;;
|
2021-03-22 20:11:29 +00:00
|
|
|
|
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
|
2015-07-04 04:29:25 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: Lukasz Klich <klich.lukasz@gmail.com>
|
2016-01-12 02:40:54 +00:00
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
2015-07-04 04:29:25 +00:00
|
|
|
|
;;
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
2021-03-24 03:31:44 +00:00
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
;;
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
;;
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2015-07-04 04:29:25 +00:00
|
|
|
|
|
2017-02-09 22:22:38 +00:00
|
|
|
|
(defun spacemacs//java-setup-backend ()
|
|
|
|
|
"Conditionally setup java backend."
|
2021-03-18 04:16:40 +00:00
|
|
|
|
(pcase java-backend
|
|
|
|
|
('meghanada (spacemacs//java-setup-meghanada))
|
|
|
|
|
('lsp (spacemacs//java-setup-lsp))))
|
2017-02-09 22:22:38 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-setup-company ()
|
|
|
|
|
"Conditionally setup company based on backend."
|
2021-03-18 04:16:40 +00:00
|
|
|
|
(when (eq java-backend 'meghanada)
|
|
|
|
|
(spacemacs//java-setup-meghanada-company)))
|
2017-02-09 22:22:38 +00:00
|
|
|
|
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(defun spacemacs//java-setup-dap ()
|
|
|
|
|
"Conditionally setup elixir DAP integration."
|
|
|
|
|
;; currently DAP is only available using LSP
|
2021-03-18 04:16:40 +00:00
|
|
|
|
(when (eq java-backend 'lsp)
|
|
|
|
|
(spacemacs//java-setup-lsp-dap)))
|
2019-09-30 01:30:53 +00:00
|
|
|
|
|
2017-02-09 22:22:38 +00:00
|
|
|
|
(defun spacemacs//java-setup-flycheck ()
|
|
|
|
|
"Conditionally setup flycheck based on backend."
|
2021-03-18 04:16:40 +00:00
|
|
|
|
(pcase java-backend
|
|
|
|
|
('meghanada (spacemacs//java-setup-meghanada-flycheck))
|
|
|
|
|
('lsp (spacemacs//java-setup-lsp-flycheck))))
|
2017-02-09 22:22:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; meghanada
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-setup-meghanada ()
|
|
|
|
|
"Setup Meghanada."
|
|
|
|
|
(require 'meghanada)
|
|
|
|
|
;; jump handler
|
|
|
|
|
(add-to-list 'spacemacs-jump-handlers
|
|
|
|
|
'(meghanada-jump-declaration
|
|
|
|
|
:async spacemacs//java-meghanada-server-livep))
|
|
|
|
|
;; auto-install meghanada server
|
|
|
|
|
(let ((dest-jar (meghanada--locate-server-jar)))
|
|
|
|
|
(unless dest-jar
|
|
|
|
|
(meghanada-install-server)))
|
|
|
|
|
;; enable meghanada
|
|
|
|
|
(meghanada-mode))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-setup-meghanada-company ()
|
|
|
|
|
"Setup Meghanada auto-completion."
|
|
|
|
|
(meghanada-company-enable))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-setup-meghanada-flycheck ()
|
|
|
|
|
"Setup Meghanada syntax checking."
|
2018-05-14 02:39:17 +00:00
|
|
|
|
(when (spacemacs/enable-flycheck 'java-mode)
|
|
|
|
|
(require 'flycheck-meghanada)
|
|
|
|
|
(add-to-list 'flycheck-checkers 'meghanada)
|
|
|
|
|
(flycheck-mode)))
|
2017-02-09 22:22:38 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-meghanada-server-livep ()
|
|
|
|
|
"Return non-nil if the Meghanada server is up."
|
|
|
|
|
(and meghanada--client-process (process-live-p meghanada--client-process)))
|
|
|
|
|
|
2017-02-09 21:45:27 +00:00
|
|
|
|
|
|
|
|
|
;; Maven
|
2015-07-19 09:50:50 +00:00
|
|
|
|
|
2017-12-17 23:39:55 +00:00
|
|
|
|
(defun spacemacs/mvn-clean-compile ()
|
|
|
|
|
"Recompile using maven."
|
2015-05-20 21:06:46 +00:00
|
|
|
|
(interactive)
|
2017-12-17 23:39:55 +00:00
|
|
|
|
(mvn-clean)
|
|
|
|
|
(mvn-compile))
|
2015-05-20 21:06:46 +00:00
|
|
|
|
|
2017-02-09 21:45:27 +00:00
|
|
|
|
|
|
|
|
|
;; Misc
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-delete-horizontal-space ()
|
|
|
|
|
(when (s-matches? (rx (+ (not space)))
|
|
|
|
|
(buffer-substring (line-beginning-position) (point)))
|
|
|
|
|
(delete-horizontal-space t)))
|
2018-08-21 18:47:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; LSP Java
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//java-setup-lsp ()
|
|
|
|
|
"Setup LSP Java."
|
|
|
|
|
(if (configuration-layer/layer-used-p 'lsp)
|
|
|
|
|
(progn
|
|
|
|
|
(require 'lsp-java)
|
2021-06-06 20:25:00 +00:00
|
|
|
|
(lsp-deferred))
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
|
2018-08-21 18:47:48 +00:00
|
|
|
|
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(defun spacemacs//java-setup-lsp-dap ()
|
|
|
|
|
"Setup DAP integration."
|
2019-12-29 09:42:00 +00:00
|
|
|
|
(require 'dap-java)
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'java-mode
|
|
|
|
|
;; debug
|
|
|
|
|
"ddj" 'dap-java-debug
|
|
|
|
|
"dtt" 'dap-java-debug-test-method
|
|
|
|
|
"dtc" 'dap-java-debug-test-class
|
|
|
|
|
;; run
|
|
|
|
|
"tt" 'dap-java-run-test-method
|
|
|
|
|
"tc" 'dap-java-run-test-class))
|
2019-09-30 01:30:53 +00:00
|
|
|
|
|
2018-08-21 18:47:48 +00:00
|
|
|
|
(defun spacemacs//java-setup-lsp-flycheck ()
|
|
|
|
|
"Setup LSP Java syntax checking."
|
2020-07-03 16:19:38 +00:00
|
|
|
|
(unless (configuration-layer/layer-used-p 'lsp)
|
2018-08-21 18:47:48 +00:00
|
|
|
|
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
|
2021-06-16 14:30:52 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/lsp-java-super-type ()
|
|
|
|
|
"Show super type hierarchy."
|
|
|
|
|
(interactive)
|
|
|
|
|
(lsp-java-type-hierarchy 1))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/lsp-java-sub-type ()
|
|
|
|
|
"Show sub type hierarchy."
|
|
|
|
|
(interactive)
|
|
|
|
|
(lsp-java-type-hierarchy 0))
|