Initial Commit
[packages] / xemacs-packages / semantic / wisent / wisent-java.el
1 ;;; wisent-java.el --- Java LALR parser for Emacs
2
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 David Ponce
4
5 ;; Author: David Ponce <david@dponce.com>
6 ;; Maintainer: David Ponce <david@dponce.com>
7 ;; Created: 19 June 2001
8 ;; Keywords: syntax
9 ;; X-RCS: $Id: wisent-java.el,v 1.1 2007-11-26 15:12:33 michaels Exp $
10
11 ;; This file is not part of GNU Emacs.
12
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
17
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 ;; General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program; see the file COPYING.  If not, write to
25 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
27
28 ;;; Commentary:
29 ;;
30
31 ;;; History:
32 ;; 
33
34 ;;; Code:
35
36 (require 'semantic-wisent)
37 (require 'wisent-java-wy)
38 (require 'semantic-java)
39 (eval-when-compile
40   (require 'semantic-util)
41   (require 'semantic-ctxt)
42   (require 'semantic-imenu)
43   (require 'senator)
44   (require 'document))
45
46 ;;; Enable Semantic in `java-mode'.
47 ;;
48 (defun wisent-java-init-parser-context ()
49   "Initialize context of the LR parser engine.
50 Used as a local `wisent-pre-parse-hook' to cleanup the stack of enum
51 names in scope."
52   (setq wisent-java-wy--enums nil))
53
54 (defun wisent-java-default-setup ()
55   "Hook run to setup Semantic in `java-mode'."
56   ;; Use the Wisent LALR(1) parser to analyze Java sources.
57   (wisent-java-wy--install-parser)
58   (semantic-make-local-hook 'wisent-pre-parse-hook)
59   (add-hook 'wisent-pre-parse-hook
60             'wisent-java-init-parser-context nil t)
61   (setq
62    ;; Lexical analysis
63    semantic-lex-number-expression semantic-java-number-regexp
64    semantic-lex-depth nil
65    semantic-lex-analyzer 'wisent-java-lexer
66    ;; Parsing
67    semantic-tag-expand-function 'semantic-java-expand-tag
68    ;; Environment
69    semantic-imenu-summary-function 'semantic-format-tag-prototype
70    semantic-imenu-expandable-tag-classes '(type variable)
71    imenu-create-index-function 'semantic-create-imenu-index
72    semantic-type-relation-separator-character '(".")
73    semantic-command-separation-character ";"
74    document-comment-start "/**"
75    document-comment-line-prefix " *"
76    document-comment-end " */"
77    ;; speedbar and imenu buckets name
78    semantic-symbol->name-assoc-list-for-type-parts
79    ;; in type parts
80    '((type     . "Classes")
81      (variable . "Variables")
82      (function . "Methods"))
83    semantic-symbol->name-assoc-list
84    ;; everywhere
85    (append semantic-symbol->name-assoc-list-for-type-parts
86            '((include  . "Imports")
87              (package  . "Package")))
88    ;; navigation inside 'type children
89    senator-step-at-tag-classes '(function variable)
90    )
91   ;; Setup javadoc stuff
92   (semantic-java-doc-setup))
93
94 (add-hook 'java-mode-hook 'wisent-java-default-setup)
95
96 ;;; Overridden Semantic API.
97 ;;
98 (define-mode-local-override semantic-tag-components java-mode (tag)
99   "Return a list of components for TAG."
100   (if (semantic-tag-of-class-p tag 'function)
101       (semantic-tag-function-arguments tag)
102     ;; Simply return the value of the :members attribute.
103     (semantic-tag-get-attribute tag :members)))
104
105 (define-mode-local-override semantic-get-local-variables
106   java-mode ()
107   "Get local variable declarations from the current context."
108   (let (result
109         ;; Ignore funny syntax while doing this.
110         semantic-unmatched-syntax-hook)
111     (while (not (semantic-up-context (point) 'function))
112       (save-excursion
113         (forward-char 1)
114         (push (semantic-parse-region
115                (point)
116                (save-excursion (semantic-end-of-context) (point))
117                ;; See this production in wisent-java.wy.
118                'block_statement
119                nil t)
120               result)))
121     (apply 'append result)))
122
123 (provide 'wisent-java)
124
125 ;;; wisent-java.el ends here