At 05:48 PM 6/13/00 +0300, you wrote: 
>>>>
This applies to both  static / non-static inner classes.   so if i  have
public class Foo  {      public class Bar {      } }  then in imenu i see
'class.Foo', but not 'class.Bar' (also not under class.Foo), or any of its
methods.   This applies to all  kinds of inner classes, static, private
etc.  As I'm not familiar  with either imenu / semantic, I'm asking for
your help.  I'm using JDE 2.1.6,  with the jde-imenu and jde-parse patches
that were posted here a couple of days  ago. I'm running XEmacs 21.2 under
Windows NT.  Thank  you, Ittay 


Replace jde-parse.el and java.bnf in the JDE 2.1.6 lisp directory with the
attached updated versions. The updated files contain fixes to the Java
grammar plus support for including full signatures of methods on the imenu
index (thanks to David Ponce). 

- Paul


------------------------------------------------------------
TECH SUPPORT POLICY

I respond only to requests that contain a complete problem report. The
easiest way to ensure that your report is complete is to include the output
of the JDE->Help->Submit Problem Report command in your request. 

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

JDE website: http://sunsite.auc.dk/jde/

JDE mailing list archive: 
http://www.mail-archive.com/[email protected]/maillist.html


;;; jde-parse.el
;; $Revision: 1.13 $ 

;; Author: Paul Kinnucan <[EMAIL PROTECTED]>
;; Maintainer: Paul Kinnucan
;; Keywords: java, tools

;; Copyright (C) 1997, 1998 Paul Kinnucan.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

(require 'semantic)
(require 'semantic-sb)
(require 'semantic-bnf)

(defcustom jde-enable-classes-index-menu t
  "Enables creation of a classes index menu in the Emacs menubar."
  :group 'jde-project
  :type 'boolean)

(defcustom jde-enable-full-method-signatures-index-menu t
  "If non-nil the \"Classes\" imenu displays full method signatures.
Use \"*rescan*\" to update the imenu when this option is changed."
  :group 'jde-project
  :type 'boolean)


(defvar jde-parse-bovine-java-grammar
  `((bovine-toplevel
     ( package)
     ( import)
     ( class)
     ( interface)
     ) ; end bovine-toplevel
    (qualified-name
     ( symbol punctuation "\\." qualified-name
              ,(lambda (vals start end)
                 (append  (list ( concat (nth 0 vals) (nth 1 vals) ( car (nth 2 
vals))))
                          (list start end))))
     ( symbol
       ,(lambda (vals start end)
          (append  (list (nth 0 vals))
                   (list start end))))
     ) ; end qualified-name
    (package
     ( symbol "package" qualified-name punctuation ";"
              ,(lambda (vals start end)
                 (append  (nth 1 vals) (list 'package nil)
                          (list start end))))
     ) ; end package
    (import
     ( symbol "import" qualified-name punctuation ";"
              ,(lambda (vals start end)
                 (append  (nth 1 vals) (list 'include nil)
                          (list start end))))
     ( symbol "import" qualified-name punctuation "\\." punctuation "\\*" punctuation 
";"
              ,(lambda (vals start end)
                 (append  (list ( concat ( car (nth 1 vals)) (nth 2 vals) (nth 3 
vals)) 'include nil)
                          (list start end))))
     ) ; end import
    (qualified-name-list
     ( qualified-name punctuation "," qualified-name-list)
     ( qualified-name)
     ) ; end qualified-name-list
    (method-modifier
     ( symbol 
"\\(public\\|protected\\|private\\|static\\|synchronized\\|native\\|abstract\\|final\\)")
     ) ; end method-modifier
    (method-modifiers
     ( method-modifier method-modifiers)
     ( method-modifier)
     ()
     ) ; end method-modifiers
    (scalar-type
     ( symbol "\\(void\\|int\\|long\\|char\\|float\\|double\\|byte\\|boolean\\)"
              ,(lambda (vals start end)
                 (append  (list (nth 0 vals))
                          (list start end))))
     ( qualified-name
       ,(lambda (vals start end)
          (append  (nth 0 vals)
                   (list start end))))
     ) ; end scalar-type
    (object-type
     ( scalar-type opt-array
                   ,(lambda (vals start end)
                      (append  (list ( concat ( car (nth 0 vals)) ( car (nth 1 vals))))
                               (list start end))))
     ) ; end object-type
    (variable-modifier
     ( symbol 
"\\(public\\|protected\\|private\\|static\\|final\\|transient\\|volatile\\)")
     ) ; end variable-modifier
    (variable-modifier-list
     ( variable-modifier variable-modifier-list)
     ( variable-modifier)
     ()
     ) ; end variable-modifier-list
    (opt-array
     ( semantic-list "\\[.*]" opt-array
                     ,(lambda (vals start end)
                        (append  (list ( concat (nth 0 vals) ( car (nth 1 vals))))
                                 (list start end))))
     (
      ,(lambda (vals start end)
         (append  (list nil)
                  (list start end))))
     ) ; end opt-array
    (parameter
     ( variable-modifier-list object-type symbol opt-array
                              ,(lambda (vals start end)
                                 (append  (list (nth 2 vals) 'variable ( car (nth 1 
vals)))
                                          (list start end))))
     ) ; end parameter
    (argument-list
     ( open-paren "(" close-paren ")"
                  ,(lambda (vals start end)
                     (append  (list nil)
                              (list start end))))
     ( open-paren "(" argument-list
                  ,(lambda (vals start end)
                     (append  (nth 1 vals)
                              (list start end))))
     ( parameter punctuation "," argument-list
                 ,(lambda (vals start end)
                    (append  ( cons (nth 0 vals) (nth 2 vals))
                             (list start end))))
     ( parameter close-paren ")"
                 ,(lambda (vals start end)
                    (append  (list (nth 0 vals))
                             (list start end))))
     ) ; end argument-list
    (method-arguments
     ( semantic-list
       ,(lambda (vals start end)
          
          (semantic-bovinate-from-nonterminal (car (nth 0 vals)) (cdr (nth 0 vals)) 
'argument-list)
          ))
     ) ; end method-arguments
    (method-body
     ( semantic-list
       ,(lambda (vals start end)
          (append  (list nil)
                   (list start end))))
     ) ; end method-body
    (throws
     ( symbol "throws" qualified-name-list
              ,(lambda (vals start end)
                 (append  (nth 1 vals)
                          (list start end))))
     ()
     ) ; end throws
    (method
     ( method-modifiers object-type symbol method-arguments throws method-body
                        ,(lambda (vals start end)
                           (append  (list (nth 2 vals) 'function) (nth 1 vals) (list 
(nth 3 vals) nil)
                                    (list start end))))
     ( method-modifiers object-type symbol method-arguments throws punctuation ";"
                        ,(lambda (vals start end)
                           (append  (list (nth 2 vals) 'function) (nth 1 vals) (list 
(nth 3 vals) nil)
                                    (list start end))))
     ) ; end method
    (constructor-modifier
     ( symbol "\\(public\\|protected\\|private\\)")
     ) ; end constructor-modifier
    (constructor
     ( constructor-modifier symbol method-arguments throws method-body
                            ,(lambda (vals start end)
                               (append  (list (nth 1 vals) 'function nil (nth 2 vals) 
nil)
                                        (list start end))))
     ) ; end constructor
    (class-modifier
     ( symbol "\\(public\\|private\\|abstract\\)")
     ) ; end class-modifier
    (class-modifiers
     ( class-modifier class-modifiers)
     ( class-modifier)
     ()
     ) ; end class-modifiers
    (expression
     ( symbol "new" qualified-name semantic-list "\\(.*\\)"
              ,(lambda (vals start end)
                 (append  (list nil)
                          (list start end))))
     ( symbol semantic-list
              ,(lambda (vals start end)
                 (append  (list nil)
                          (list start end))))
     ( symbol
       ,(lambda (vals start end)
          (append  (list nil)
                   (list start end))))
     ) ; end expression
    (opt-expression
     ( expression)
     (
      ,(lambda (vals start end)
         (append  (list nil)
                  (list start end))))
     ) ; end opt-expression
    (opt-assign
     ( punctuation "=" expression
                   ,(lambda (vals start end)
                      (append  (list (nth 1 vals))
                               (list start end))))
     (
      ,(lambda (vals start end)
         (append  (list nil)
                  (list start end))))
     ) ; end opt-assign
    (field
     ( variable-modifier-list object-type symbol opt-assign punctuation ";"
                              ,(lambda (vals start end)
                                 (append  (list (nth 2 vals) 'variable) (nth 1 vals) 
(list nil)
                                          (list start end))))
     ) ; end field
    (class-members
     ( class
       ,(lambda (vals start end)
          (append  (nth 0 vals)
                   (list start end))))
     ( constructor
       ,(lambda (vals start end)
          (append  (nth 0 vals)
                   (list start end))))
     ( method
       ,(lambda (vals start end)
          (append  (nth 0 vals)
                   (list start end))))
     ( field
       ,(lambda (vals start end)
          (append  (nth 0 vals)
                   (list start end))))
     ) ; end class-members
    (class-body
     ( semantic-list
       ,(lambda (vals start end)
          (append 
           (semantic-bovinate-from-nonterminal-full (car (nth 0 vals)) (cdr (nth 0 
vals)) 'class-members)
           
           (list start end))))
     ) ; end class-body
    (extends
     ( symbol "extends" qualified-name
              ,(lambda (vals start end)
                 (append  (nth 1 vals)
                          (list start end))))
     ()
     ) ; end extends
    (implements
     ( symbol "implements" qualified-name-list
              ,(lambda (vals start end)
                 (append  (nth 1 vals)
                          (list start end))))
     ()
     ) ; end implements
    (class
     ( class-modifiers symbol "class" qualified-name extends implements class-body
                       ,(lambda (vals start end)
                          (append  (nth 2 vals) (list 'type "class" (nth 5 vals) (nth 
3 vals) nil)
                                   (list start end))))
     ( class-modifiers symbol "class" qualified-name implements extends class-body
                       ,(lambda (vals start end)
                          (append  (nth 2 vals) (list 'type "class" (nth 5 vals) (nth 
4 vals) nil)
                                   (list start end))))
     ) ; end class
    (method-prototype
     ( method-modifiers object-type symbol method-arguments throws method-body
                        ,(lambda (vals start end)
                           (append  (list (nth 2 vals) 'function) (nth 1 vals) (list 
(nth 3 vals) nil)
                                    (list start end))))
     ( method-modifiers object-type symbol method-arguments throws punctuation ";"
                        ,(lambda (vals start end)
                           (append  (list (nth 2 vals) 'function) (nth 1 vals) (list 
(nth 3 vals) nil)
                                    (list start end))))
     ) ; end method-prototype
    (interface-members
     ( method-prototype
       ,(lambda (vals start end)
          (append  (nth 0 vals)
                   (list start end))))
     ) ; end interface-members
    (interface-body
     ( semantic-list
       ,(lambda (vals start end)
          (append 
           (semantic-bovinate-from-nonterminal-full (car (nth 0 vals)) (cdr (nth 0 
vals)) 'interface-members)
           
           (list start end))))
     ) ; end interface-body
    (interface
     ( symbol "interface" qualified-name extends interface-body
              ,(lambda (vals start end)
                 (append  (nth 1 vals) (list 'type (nth 0 vals) (nth 3 vals) (nth 2 
vals) nil)
                          (list start end))))
     ) ; end interface
    )
"Grammar used by the semantic library to parse Java source
buffers. This grammar is a Lisp version of the BNF grammar stored in
java.bnf. The Lisp grammar is generated automatically from the BNF
source. For this reason, you should never modify this variable
directly.  See `bovinate' for more information.")

(defun jde-imenu-index-class  (tokens)
  "Creates an imenu index for a class. Displays full method signatures
if `jde-enable-full-method-signatures-index-menu' is non-nil."
  (let ((methods (semantic-find-nonterminal-by-token 'function tokens))
        (fields  (semantic-find-nonterminal-by-token 'variable tokens))
        (classes (semantic-find-nonterminal-by-token 'type     tokens))
        index)

    (while methods
      (let* ((method-token (car methods))
             (method-name  (semantic-token-name method-token))
             (method-pos   (semantic-token-start method-token))
             method-sig)
        (if jde-enable-full-method-signatures-index-menu
            (let ((method-type  (semantic-token-type method-token))
                  (method-args  (semantic-token-function-args method-token)))
              (setq method-sig (if method-type
                                   (format "%s %s(" method-type method-name)
                                 (format "%s(" method-name)))
              (while method-args
                (let ((method-arg-token (car method-args))
                      method-arg-type)
                  (when method-arg-token
                    (setq method-arg-type (semantic-token-type method-arg-token))
                    (setq method-sig (concat method-sig method-arg-type))))
                (setq method-args (cdr method-args))
                (if method-args (setq method-sig (concat method-sig ","))))
              (setq method-sig (concat method-sig ")")))
          (setq method-sig (format "%s()" method-name)))
        (setq index
              (append
               index (list (cons method-sig method-pos)))))
      (setq methods (cdr methods)))
    
    (while fields
      (let* ((field-token (car fields))
             (field-name  (semantic-token-name  field-token))
             (field-pos   (semantic-token-start field-token)))
        (setq index 
              (append 
               index (list (cons field-name field-pos)))))
      (setq fields (cdr fields)))

    (while classes
      (let* ((class-token  (car classes))
             (class-name   (semantic-token-name       class-token))
             (parts        (semantic-token-type-parts class-token))
             (class-index  (jde-imenu-index-class parts)))
        (setq index 
              (append 
               index 
               (list (cons (concat "class " class-name) class-index)))))
      (setq classes (cdr classes)))
    index))

(defun jde-create-imenu-index ()
  "Creates an imenu index for a Java source buffer.
This function uses the semantic bovinator to index the buffer."

  ;; The following clears the toplevel bovin cache for the current
  ;; buffer and forces *rescan* to work even if the current buffer has
  ;; not been modifified. This is needed to rebuild the "Classes" imenu when
  ;; `jde-enable-full-method-signatures-index-menu' option is changed.
  (semantic-clear-toplevel-cache)
  
  (let* ((tokens   (semantic-bovinate-toplevel))
         (packages (semantic-find-nonterminal-by-token 'package tokens))
         (depends  (semantic-find-nonterminal-by-token 'include tokens))
         (classes  (semantic-find-nonterminal-by-token 'type tokens))
         depend-index
         index)

    (while classes
      (let* ((class-token (car classes))
             (class-name  (semantic-token-name       class-token))
             (parts       (semantic-token-type-parts class-token))
             (class-index (jde-imenu-index-class parts)))
        (setq index 
              (append 
               index 
               (list (cons (concat "class " class-name) class-index)))))
      (setq classes (cdr classes)))

    (while depends
      (let* ((depend-token (car depends))
             (depend-name  (semantic-token-name  depend-token))
             (depend-pos   (semantic-token-start depend-token)))
        (setq depend-index (append depend-index (list (cons depend-name depend-pos)))))
      (setq depends (cdr depends)))
    (if depend-index
        (setq index (append index (list (cons "Imports" depend-index)))))

    (while packages
      (let* ((package-token (car packages))
             (package-name  (semantic-token-name  package-token))
             (package-pos   (semantic-token-start package-token)))
        (setq index 
              (append 
               index 
               (list (cons (concat "package " package-name) package-pos)))))
      (setq packages (cdr packages)))
    index))


(add-hook 
 'jde-mode-hook
 (lambda ()
   (make-local-variable 'semantic-toplevel-bovine-table)
   (setq semantic-toplevel-bovine-table jde-parse-bovine-java-grammar)
   (when jde-enable-classes-index-menu
     (setq imenu-create-index-function 'jde-create-imenu-index)
     (imenu-add-to-menubar "Classes"))))


(defun jde-get-java-source-buffers ()
  "Get a list of the Java source buffers open in the
current session."
  (mapcan (lambda (buffer)
          (save-excursion
            (set-buffer buffer)
            (if (string= mode-name "JDE")
                (list buffer))))
          (buffer-list)))

(defun jde-parse-get-package-name ()
  "Gets the name of the package in which the Java source file in the
current buffer resides."
  (let ((package-re "package[ \t]+\\(.*\\)[ \t]*;"))
    (save-excursion
      (goto-char (point-max))
      (when (re-search-backward package-re (point-min) t)
        (looking-at package-re)
        (buffer-substring-no-properties
                       (match-beginning 1)
                       (match-end 1))))))

(defun jde-parse-get-package-from-name (class-name)
  "Gets the package portion of a qualified class name."
  (substring 
   class-name 0
   (let ((pos  (position ?. class-name :from-end t)))
     (if pos
         pos
       0))))

(defun jde-parse-get-unqualified-name (name)
"Gets the last name in a qualified name." 
  (string-match "[^.]+$" name)
  (substring name (match-beginning 0) (match-end 0)))


(defun jde-parse-get-class-at-point ()
  (let ((class-re "class[ \t]+\\([a-zA-z]+[a-zA-Z0-9._]*\\).*[ \n]*"))
    (save-excursion
      (let ((open-brace-pos
             (scan-lists (point) -1 1)))
        (when open-brace-pos
          (goto-char open-brace-pos)
          (when (re-search-backward class-re (point-min) t)
            (looking-at class-re)
            (buffer-substring-no-properties
                     (match-beginning 1)
                     (match-end 1))))))))


(defun jde-parse-in-comment-p () 
  
)

(defun jde-parse-get-innermost-class-at-point ()
"Get the innermost class containing point.
If point is in a class, this function returns 
(CLASS_NAME . CLASS_POSITION), where CLASS_NAME is the 
name of the class and CLASS_POSITION is the position
of the first character of the class keyword. Otherwise,
this function returns nil."
  ;; (interactive)
  (let ((left-paren-pos (c-parse-state)))
    (if left-paren-pos
        (save-excursion
          (catch 'class-found
            (let ((left-paren-index 0)
                  (left-paren-count (length left-paren-pos)))
              (while (< left-paren-index left-paren-count)
                (let ((paren-pos (nth left-paren-index left-paren-pos)))
                  (unless (consp paren-pos)
                    (goto-char paren-pos)
                    (if (looking-at "{")
                        (let* ((search-end-pos
                               (if (< left-paren-index (1- left-paren-count))
                                   (let ((pos (nth (1+ left-paren-index) 
left-paren-pos)))
                                     (if (consp pos)
                                         (cdr pos)
                                       pos))
                                 (point-min)))
                              (case-fold-search nil)
                              (class-re "^[ 
\t]*\\(\\(public\\|abstract\\|final\\|static\\|strictfp\\|protected\\)[ \t]+\\)*[ 
\t]*class[ \t]+\\([^ \t\n{]*\\).*")
                              (class-pos (re-search-backward class-re search-end-pos 
t)))      
                           (if class-pos
                              (progn
                                (looking-at class-re)
                                (throw
                                 'class-found
                                 (cons
                                  (buffer-substring-no-properties
                                   (match-beginning 3)
                                   (match-end 3))
                                  class-pos))))))))
                  (setq left-paren-index (1+ left-paren-index)))))))))

(defun jde-parse-test ()
  (interactive)
  (message (car (jde-parse-get-innermost-class-at-point))))
      
 

(defun jde-parse-get-class-at-point () 
  (let ((class-info (jde-parse-get-innermost-class-at-point))
        class-name)
    (while class-info
      (let ((name (car class-info))
            (pos (cdr class-info)))
        (if (not class-name)
            (setq class-name name)
          (setq class-name (concat name "." class-name)))
        (save-excursion
          (goto-char pos)
          (setq class-info (jde-parse-get-innermost-class-at-point)))))
    class-name)) 


(defun jde-parse-get-classes-at-point ()
  (interactive)
  (let ((class (jde-parse-get-innermost-class-at-point)))
    (if class (message "%s %s" (car class) (cdr class) ) (message "no class")))
;; (goto-char (aref (c-search-uplist-for-classkey (c-parse-state)) 0))
)


(defun jde-parse-qualified-name-at-point ()
  "Returns (cons QUALIFIER NAME) where NAME is the symbol at point and
QUALIFIER is the symbol's qualifier. For example, suppose the name at
point is

     int i = error.msg.length()
                   ^
In this case, this function returns (cons \"error.msg\" \"length\").
This function works only for qualified names that do not contain
white space. It returns null if there is no qualified name at point."
  (let ((symbol-at-point (thing-at-point 'symbol)))
    (when symbol-at-point
      (thing-at-point-looking-at "[^ \n\t();,:+]+")
      (let ((qualified-name 
              (buffer-substring-no-properties
               (match-beginning 0)
               (match-end 0))))
        (string-match "\\(.+[.]\\)*\\([^.]+\\)" qualified-name)
        (let ((qualifier (if (match-beginning 1)
                             (substring qualified-name 
                                        (match-beginning 1) (match-end 1))))
              (name (substring qualified-name 
                                    (match-beginning 2) (match-end 2))))
          (if qualifier
              (setq qualifier (substring qualifier 0 (1- (length qualifier)))))
          (cons qualifier name))))))


(defun jde-parse-double-backslashes (name)
  (mapconcat (lambda (x) (if (eq x ?\\)
                 "\\\\"
               (string x)))
             name ""))

(defun jde-parse-valid-declaration-at (point varname)
  "Verify that a POINT starts a valid java declaration
for the VARNAME variable."
  (save-excursion
    (goto-char point)
    (if (looking-at (concat "\\([A-Za-z0-9_.\177-\377]+\\)[ \t\n\r]+" 
                            (jde-parse-double-backslashes varname) 
                            "[ \t\n\r]*[;=]"))
        (match-string 1)
      nil)))

(defun jde-parse-declared-type-of (name)
  "Find in the current buffer the java type of the variable NAME.  The
function returns a string containing the name of the class, or nil
otherwise. This function does not give the fully-qualified java class
name, it just returns the type as it is declared."
  (save-excursion
    (let (found res pos orgpt resname)

      (setq orgpt (point))

      (while (and (not found)
                  (search-backward name nil t))
        (setq pos (point))
        (backward-word 1)
        (setq resname (jde-parse-valid-declaration-at (point) name))
        (goto-char pos)
        (forward-char -1)
        (if (not (null resname))
            (progn (setq res resname)
                   (setq found t))))
      
      (goto-char orgpt)

      (while (and (not found)
                  (search-forward name nil t))
        (setq pos (point))
        (backward-word 2)
        (setq resname (jde-parse-valid-declaration-at (point) name))
        (goto-char pos)
        (forward-char 1)
        (if (not (null resname))
            (progn (setq res resname)
                   (setq found t))))
      res)))


(defun jde-display-parse-error (error)
  (let* ((parser-buffer-name "*Java Parser*")
         (buf (get-buffer parser-buffer-name))) 
    (if (not buf)
        (setq buf (get-buffer-create parser-buffer-name)))
    (set-buffer buf)
    (erase-buffer)
    (insert error)
    (pop-to-buffer buf)))

(defun jde-parse ()
"*Parses the Java source file displayed in the current buffer.
If the source file parses successfully, this command displays
a success message in the minibuffer. Otherwise, it displays an error
message in the Java Parser buffer. If the Java Parser buffer does
not exist, this command creates it.

Note. This command uses an external Java parser implemented in
Java to parse Java source files. This command uses the JDE's integrated
Java source interpreter, the BeanShell, to invoke the parser. If the
BeanShell is not running, this command starts the BeanShell. Thus,
the first time you invoke the parser you may notice a slight delay
before getting a response. Thereafter, the response should be very
fast."
  (interactive)
  (save-some-buffers (not compilation-ask-about-save) nil)
  (let ((parse-error
         (bsh-eval-r (concat "jde.parser.ParserMain.parseFile(\"" (buffer-file-name) 
"\");"))))
    (if parse-error
        (jde-display-parse-error parse-error)
      (message "Parsed %s successfully" (buffer-name)))))


;; Thanks to Eric D. Friedman <[EMAIL PROTECTED]> for this function.
(defun jde-parse-comment-or-quoted-p ()
  "Returns t if point is in a comment or a quoted string. nil otherwise"
  (interactive "p")
  ;; limit our analysis to the current line.
  (let ((beg (save-excursion (beginning-of-line) (point))))
    (if
        (or
         ;; are we in a javadoc comment?
         (save-excursion
           (re-search-backward
            "^[ \t]*/?\\*"
            beg t))
         ;; are we in a '//' or a '/*' style comment?
         ;; note that /* or /** on a line with only leading whitespace
         ;; will have matched in the previous regex.  We check again here
         ;; because the above case needs to allow for a line with
         ;; the continuation of a comment (using only a '*') whereas this
         ;; requires the presence of a '/' in front of the '*' so as to
         ;; distinguish a comment from a '*' operator.
         ;; To make a long story short,
         ;; the first regex matches
         ;;   /* a comment */
         ;; and
         ;; /**
         ;;  * a comment
         ;;  */
         ;; while the second one matches
         ;; System.out.println(foo); /* a comment */
         ;; but not
         ;; i = 3 * 5;
         ;; if you do something like following, you're on your own:
         ;; i = 3
         ;;       * 5; 
         ;; Suggestions for improving the robustness of this algorithm
         ;; gratefully accepted.
         (save-excursion
           (re-search-backward
            "\\(//\\|/\\*\\)"
            beg t))
         ;; are we in a quoted string?
         (save-excursion
           (re-search-backward
            "\"" ;;
            beg t)))
        t ;; return true if we had any matches; nil otherwise
      nil)))

(provide 'jde-parse)

;; $Log: jde-parse.el,v $
;; Revision 1.13  2000/06/09 05:07:06  paulk
;; Classes index menu now shows full signatures of methods. Thanks to Ittay Freiman 
<[EMAIL PROTECTED]> for suggesting this enhancement and to David Ponce 
<[EMAIL PROTECTED]> for implementing it.
;;
;; Revision 1.12  2000/05/26 09:14:10  paulk
;; Updated grammar to handle argument variables with modifiers and array arguments.
;;
;; Revision 1.11  2000/05/16 04:08:55  paulk
;; Adds a Classes index menu to the Emacs menubar.
;;
;; Revision 1.10  2000/05/11 03:07:17  paulk
;; Updated bovinator grammar.
;;
;; Revision 1.9  2000/05/11 01:24:40  paulk
;; Added support for Eric Ludlam's semantic bovinator. Moved regular expression-based 
imenu indexer to this file.
;;
;; Revision 1.8  2000/03/16 05:18:11  paulk
;; Miscellaneous small bug fixes and enhancements.
;;
;; Revision 1.7  2000/03/08 03:47:02  paulk
;; Fixed regular expression in jde-parse-get-innermost-class-at-point to handle more 
cases. Thanks to Steve Haflich <[EMAIL PROTECTED]> for reporting the problem and providing 
a starting point for the fix.
;;
;; Revision 1.6  2000/02/16 04:40:33  paulk
;; Implemented Cygwin/XEmacs compatiblity fixes provided by Fred Hart
;; <[EMAIL PROTECTED]> in bsh-internal.
;;
;; Revision 1.5  2000/02/14 06:21:32  paulk
;; Fixed find innermost class regular expression.
;;
;; Revision 1.4  2000/02/09 05:18:10  paulk
;; Added methods for parsing symbol at point.
;;
;; Revision 1.3  2000/02/01 04:10:48  paulk
;; Fixed regular expression for classes to handle case where point is in
;; a constructor. Thanks to Francois Cogne <[EMAIL PROTECTED]>.
;;
;; Revision 1.2  1999/08/20 00:52:14  paulk
;; Added jde-parse-get-package-from-name function.
;;
;; Revision 1.1  1999/04/27 16:25:46  paulk
;; Initial revision
;;
# BNF grammar for Java
#
# Copyright (C) 2000 Paul F. Kinnucan, Jr.
#
# Author: Paul F. Kinnucan, Jr. <[EMAIL PROTECTED]>
# $Id: java.bnf,v 1.6 2000/06/09 04:08:43 paulk Exp $
#
# java.bnf is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Emacs; see the file COPYING.  If not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

# TABLE: jde-parse.el:jde-parse-bovine-java-grammar
# MODE: jde-mode

bovine-toplevel : package
                | import
                | class
                | interface
                ;

qualified-name : symbol punctuation "\\." qualified-name
                 ((concat $1 $2 (car $3)))
               | symbol
                 ($1)
               ;

package : symbol "package" qualified-name punctuation ";"
          (,$2 package nil)
        ;

import : symbol "import" qualified-name punctuation ";"
         (,$2 include nil)
       | symbol "import" qualified-name punctuation "\\." punctuation "\\*" 
         punctuation ";"
         ((concat (car $2) $3 $4) include nil)
       ;

qualified-name-list : qualified-name punctuation "," qualified-name-list
                    | qualified-name
                    ;

method-modifier : symbol 
"\\(public\\|protected\\|private\\|static\\|synchronized\\|native\\|abstract\\|final\\)"
                ;

method-modifiers : method-modifier method-modifiers
                 | method-modifier
                 | EMPTY
                 ;

scalar-type : symbol "\\(void\\|int\\|long\\|char\\|float\\|double\\|byte\\|boolean\\)"
              ($1)
            | qualified-name  # user-defined type
              (,$1)
            ;

object-type : scalar-type opt-array
              ((concat (car $1) (car $2)))
            ;

variable-modifier : symbol 
"\\(public\\|protected\\|private\\|static\\|final\\|transient\\|volatile\\)"
                  ;

variable-modifier-list : variable-modifier variable-modifier-list
                       | variable-modifier
                       | EMPTY
                       ;

opt-array : semantic-list "\\[.*]" opt-array
          # Eventually we want to replace the 1 below with a size
          # (if available)
            ( (concat $1 (car ,$2) ) )
          | EMPTY
            ( nil )
          ;

parameter : variable-modifier-list object-type symbol opt-array
            ($3 variable (car $2))
          ;

argument-list : open-paren "(" close-paren ")"
                (nil)
              | open-paren "(" argument-list
                (,$2)
              | parameter punctuation "," argument-list
                (,(cons ,$1 ,$3))
              | parameter close-paren ")"
                ($1)
              ;
    
method-arguments : semantic-list
                   (EXPAND $1 argument-list)
                 ;

method-body : semantic-list
              (nil)
            ;

throws : symbol "throws" qualified-name-list
         (,$2)
       | EMPTY
       ;

method : method-modifiers object-type symbol method-arguments throws method-body
         ($3 function ,$2 $4 nil)
       | method-modifiers object-type symbol method-arguments throws punctuation ";"
         ($3 function ,$2 $4 nil)
       ;

constructor-modifier : symbol "\\(public\\|protected\\|private\\)"
                ;

constructor : constructor-modifier symbol method-arguments throws method-body
              ($2 function nil $3 nil)
            ;

class-modifier : symbol "\\(public\\|private\\|abstract\\)"
               ;

class-modifiers : class-modifier class-modifiers
                | class-modifier
                | EMPTY
                ;                     

# Use expressiosn for parsing only.  Don't actually return anything
# for now.  Hopefully we can't fix this later.
expression : symbol "new" qualified-name semantic-list "\\(.*\\)"
             ( nil )
           | symbol semantic-list
             (nil)
           | symbol
             (nil)
           # | expression "+-*/%^|&" expression
           #  ( nil )
           ;

opt-expression : expression
               | EMPTY ( nil )
               ;

opt-assign : punctuation "=" expression
             ( $2 )
           | EMPTY
             ( nil )
           ;

field : variable-modifier-list object-type symbol opt-assign punctuation ";"
        ($3 variable ,$2 nil)
      ;

class-members : class
                (,$1)
              | constructor
                (,$1)
              | method
                (,$1)
              | field
                (,$1)
              ;

class-body  : semantic-list
              (EXPANDFULL $1 class-members)
            ;

extends : symbol "extends" qualified-name
         (,$2)
       | EMPTY
       ;

implements : symbol "implements" qualified-name-list
             (,$2)
           | EMPTY
           ;

class : class-modifiers symbol "class" qualified-name extends implements class-body
        (,$3 type "class" $6 $4 nil)
      | class-modifiers symbol "class" qualified-name implements extends class-body
        (,$3 type "class" $6 $5 nil)
      ;


method-prototype : method-modifiers object-type symbol method-arguments throws 
method-body
                   ($3 function ,$2 $4 nil)
                 | method-modifiers object-type symbol method-arguments throws 
punctuation ";"
                   ($3 function ,$2 $4 nil)
                 ;

interface-members : method-prototype
                    (,$1)
                  ;

interface-body : semantic-list
                 (EXPANDFULL $1 interface-members)
               ;

interface : symbol "interface" qualified-name extends interface-body
            (,$2 type $1 $4 $3 nil)
          ;

# $Log: java.bnf,v $
# Revision 1.6  2000/06/09 04:08:43  paulk
# Added volatile to list of variable modifiers. Thanks to David Ponce and Mike Bowler.
#
# Revision 1.5  2000/05/26 09:14:10  paulk
# Updated grammar to handle argument variables with modifiers and array arguments.
#
# Revision 1.4  2000/05/16 04:41:28  paulk
# *** empty log message ***
#
# Revision 1.3  2000/05/11 04:41:05  paulk
# Now handles native method declarations.
#
# Revision 1.2  2000/05/11 02:49:41  paulk
# Now parses constructors.
#
# Revision 1.1  2000/05/02 04:10:23  paulk
# Initial revision.
#

# End of java.bnf

Reply via email to