Skip to content

Commit

Permalink
Support import static method
Browse files Browse the repository at this point in the history
  • Loading branch information
mopemope committed Apr 23, 2018
1 parent 2ed2886 commit 1833921
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
27 changes: 21 additions & 6 deletions company-meghanada.el
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@
'type
(nth 0 candidate)
'return-type
(nth 4 candidate))) result))
(nth 4 candidate)
'extra
(nth 5 candidate))) result))

(defun company-meghanada--to-candidates (output)
(when (> (length output) 0)
Expand Down Expand Up @@ -241,9 +243,11 @@
(company-template-c-like-templatify anno)))))

(defun company-meghanada--post-method (arg)
(let ((meta (get-text-property 0 'meta arg))
(anno (company-meghanada--annotation arg))
(return-t (get-text-property 0 'return-type arg)))
(let* ((meta (get-text-property 0 'meta arg))
(desc (get-text-property 0 'desc arg))
(anno (company-meghanada--annotation arg))
(return-t (get-text-property 0 'return-type arg))
(extra (split-string (get-text-property 0 'extra arg))))
(when return-t
(save-excursion
(forward-char -1)
Expand All @@ -254,12 +258,23 @@

(when anno
(insert anno)
(company-template-c-like-templatify anno))))
(company-template-c-like-templatify anno)
(when (and
(> (length extra) 1)
(string= "static-import" (car extra)))
(let* ((class (nth 1 extra))
(imp (format "%s#%s" class arg)))
(if company-meghanada-auto-import
(meghanada--add-import imp (current-buffer))
(when (y-or-n-p
(format "Add import %s ? " (meghanada--import-name class)))
(meghanada--add-import imp (current-buffer)))))))))

(defun company-meghanada--post-field (arg)
(let ((meta (get-text-property 0 'meta arg))
(anno (company-meghanada--annotation arg))
(return-t (get-text-property 0 'return-type arg)))
(return-t (get-text-property 0 'return-type arg))
(extra (split-string (get-text-property 0 'extra arg))))
(when return-t
(save-excursion
(forward-char -1)
Expand Down
24 changes: 19 additions & 5 deletions meghanada.el
Original file line number Diff line number Diff line change
Expand Up @@ -839,20 +839,34 @@ e.g. java.lang.annotation)."
(let ((severity (car result)))
(pcase severity
(`success
(let ((fqcn (car (cdr result))))
(unless (or (meghanada--is-java-lang-package-p fqcn) (meghanada--import-exists-p fqcn))
(let* ((fqcn (car (cdr result)))
(is-static (string-match-p (regexp-quote "#") fqcn))
(imp (if is-static
(replace-regexp-in-string "#" "." fqcn)
fqcn)))

(unless (or (meghanada--is-java-lang-package-p imp)
(meghanada--import-exists-p imp))
(let ((start t))
(save-excursion
(meghanada--goto-imports-start)
(while (and start (re-search-forward "^import .+;" nil t))
(forward-line)
(setq start (/= (point-at-bol) (point-at-eol))))
(insert (format "import %s;\n" fqcn)))))))))))
(if is-static
(insert (format "import static %s;\n" imp))
(insert (format "import %s;\n" imp))))))))))))

(defun meghanada--add-import (imp buf)
"TODO: FIX DOC IMP BUF."
(unless (or (meghanada--is-java-lang-package-p imp) (meghanada--import-exists-p imp))
(meghanada-add-import-async imp #'meghanada--add-import-callback buf)))
(unless
(or
(meghanada--is-java-lang-package-p imp)
(meghanada--import-exists-p imp))
(meghanada-add-import-async
imp
#'meghanada--add-import-callback
buf)))

(defun meghanada-import-all--callback (result buf optimize)
"TODO: FIX DOC OUT BUF OPTIMIZE."
Expand Down

0 comments on commit 1833921

Please sign in to comment.