1 ;;; srecode/java.el --- Srecode Java support
3 ;; Copyright (C) 2009-2014 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)))
44 (while (string-match "\\.\\| " fpak
)
45 (setq fpak
(replace-match "_" t t fpak
)))
46 ;; We can extract package from:
47 ;; 1) a java EDE project source paths,
48 (cond ((ede-current-project)
49 (let* ((proj (ede-current-project))
50 (pths (ede-source-paths proj
'java-mode
))
54 (setq pth
(expand-file-name (car pths
))))
55 (when (string-match pth dir
)
56 (setq res
(substring dir
(match-end 0))))
57 (setq pths
(cdr pths
)))
59 ;; 2) a simple heuristic
60 ((string-match "src/" dir
)
61 (setq dir
(substring dir
(match-end 0))))
62 ;; 3) outer directory as a fallback
63 (t (setq dir
(file-name-nondirectory (directory-file-name dir
)))))
64 (setq dir
(directory-file-name dir
))
65 (while (string-match "/" dir
)
66 (setq dir
(replace-match "." t t dir
)))
67 (srecode-dictionary-set-value dict
"FILENAME_AS_PACKAGE" dir
)
68 (srecode-dictionary-set-value dict
"FILENAME_AS_CLASS" fnox
)
70 ;; Symbols needed for most other files with stuff in them.
71 (let ((pkg (semantic-find-tags-by-class 'package
(current-buffer))))
73 (srecode-dictionary-set-value dict
"CURRENT_PACKAGE" (semantic-tag-name (car pkg
)))
77 (provide 'srecode
/java
)
80 ;; generated-autoload-file: "loaddefs.el"
81 ;; generated-autoload-load-name: "srecode/java"
84 ;;; srecode/java.el ends here