Commit | Line | Data |
---|---|---|
07a79ce4 | 1 | ;;; srecode/java.el --- Srecode Java support |
4d902e6f | 2 | |
ba318903 | 3 | ;; Copyright (C) 2009-2014 Free Software Foundation, Inc. |
4d902e6f CY |
4 | |
5 | ;; Author: Eric M. Ludlam <eric@siege-engine.com> | |
6 | ||
7 | ;; This file is part of GNU Emacs. | |
8 | ||
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. | |
13 | ||
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. | |
18 | ||
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/>. | |
21 | ||
22 | ;;; Commentary: | |
23 | ;; | |
24 | ;; Special support for the Java language. | |
25 | ||
26 | ;;; Code: | |
27 | ||
28 | (require 'srecode/dictionary) | |
3f2a848d | 29 | (require 'semantic/find) |
e677c726 | 30 | (require 'ede) |
4d902e6f CY |
31 | |
32 | ;;;###autoload | |
33 | (defun srecode-semantic-handle-:java (dict) | |
34 | "Add macros into the dictionary DICT based on the current java file. | |
35 | Adds the following: | |
36 | FILENAME_AS_PACKAGE - file/dir converted into a java package name. | |
37 | FILENAME_AS_CLASS - file converted to a Java class name." | |
62a81506 | 38 | ;; Symbols needed by empty files. |
4d902e6f CY |
39 | (let* ((fsym (file-name-nondirectory (buffer-file-name))) |
40 | (fnox (file-name-sans-extension fsym)) | |
41 | (dir (file-name-directory (buffer-file-name))) | |
42 | (fpak fsym) | |
43 | ) | |
44 | (while (string-match "\\.\\| " fpak) | |
45 | (setq fpak (replace-match "_" t t fpak))) | |
e8cc7880 DE |
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)) | |
51 | (pth) | |
52 | (res)) | |
53 | (while (and (not res) | |
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))) | |
58 | (setq dir res))) | |
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))))) | |
62a81506 | 64 | (setq dir (directory-file-name dir)) |
4d902e6f | 65 | (while (string-match "/" dir) |
62a81506 CY |
66 | (setq dir (replace-match "." t t dir))) |
67 | (srecode-dictionary-set-value dict "FILENAME_AS_PACKAGE" dir) | |
4d902e6f | 68 | (srecode-dictionary-set-value dict "FILENAME_AS_CLASS" fnox) |
62a81506 CY |
69 | ) |
70 | ;; Symbols needed for most other files with stuff in them. | |
71 | (let ((pkg (semantic-find-tags-by-class 'package (current-buffer)))) | |
72 | (when pkg | |
73 | (srecode-dictionary-set-value dict "CURRENT_PACKAGE" (semantic-tag-name (car pkg))) | |
74 | )) | |
75 | ) | |
4d902e6f CY |
76 | |
77 | (provide 'srecode/java) | |
78 | ||
79 | ;; Local variables: | |
80 | ;; generated-autoload-file: "loaddefs.el" | |
4d902e6f CY |
81 | ;; generated-autoload-load-name: "srecode/java" |
82 | ;; End: | |
83 | ||
84 | ;;; srecode/java.el ends here |