1 ;;; srecode/java.el --- Srecode Java support
3 ;; Copyright (C) 2009-2017 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; Special support for the Java language.
28 (require 'srecode
/dictionary
)
29 (require 'semantic
/find
)
33 (defun srecode-semantic-handle-:java
(dict)
34 "Add macros into the dictionary DICT based on the current java file.
36 FILENAME_AS_PACKAGE - file/dir converted into a java package name.
37 FILENAME_AS_CLASS - file converted to a Java class name."
38 ;; Symbols needed by empty files.
39 (let* ((fsym (file-name-nondirectory (buffer-file-name)))
40 (fnox (file-name-sans-extension fsym
))
41 (dir (file-name-directory (buffer-file-name)))
43 (proj (ede-current-project))
44 (pths (ede-source-paths proj
'java-mode
))
46 (while (string-match "\\.\\| " fpak
)
47 (setq fpak
(replace-match "_" t t fpak
)))
48 ;; We can extract package from:
49 ;; 1) a java EDE project source paths,
50 (cond ((and proj pths
)
53 (setq pth
(expand-file-name (car pths
))))
54 (when (string-match pth dir
)
55 (setq res
(substring dir
(match-end 0))))
56 (setq pths
(cdr pths
)))
58 ;; 2) a simple heuristic
59 ((string-match "src/" dir
)
60 (setq dir
(substring dir
(match-end 0))))
61 ;; 3) outer directory as a fallback
62 (t (setq dir
(file-name-nondirectory (directory-file-name dir
)))))
63 (setq dir
(directory-file-name dir
))
64 (while (string-match "/" dir
)
65 (setq dir
(replace-match "." t t dir
)))
66 (srecode-dictionary-set-value dict
"FILENAME_AS_PACKAGE" dir
)
67 (srecode-dictionary-set-value dict
"FILENAME_AS_CLASS" fnox
)
69 ;; Symbols needed for most other files with stuff in them.
70 (let ((pkg (semantic-find-tags-by-class 'package
(current-buffer))))
72 (srecode-dictionary-set-value dict
"CURRENT_PACKAGE" (semantic-tag-name (car pkg
)))
76 (provide 'srecode
/java
)
79 ;; generated-autoload-file: "loaddefs.el"
80 ;; generated-autoload-load-name: "srecode/java"
83 ;;; srecode/java.el ends here