Function: gud-find-class

gud-find-class is a byte-compiled function defined in gud.el.gz.

Signature

(gud-find-class F LINE)

Documentation

Find fully qualified class in file F at line LINE.

This function uses the gud-jdb-classpath (and optional gud-jdb-sourcepath) list(s) to derive a file pathname relative to its classpath directory. The values in gud-jdb-classpath are assumed to have been converted to absolute pathname standards using file-truename. If F is visited by a buffer and its mode is CC-mode(Java), syntactic information of LINE is used to find the enclosing (nested) class string which is appended to the top level class of the file (using s to separate nested class ids).

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/gud.el.gz
(defun gud-find-class (f _line)
  "Find fully qualified class in file F at line LINE.
This function uses the `gud-jdb-classpath' (and optional
`gud-jdb-sourcepath') list(s) to derive a file
pathname relative to its classpath directory.  The values in
`gud-jdb-classpath' are assumed to have been converted to absolute
pathname standards using `file-truename'.
If F is visited by a buffer and its mode is CC-mode(Java),
syntactic information of LINE is used to find the enclosing (nested)
class string which is appended to the top level
class of the file (using s to separate nested class ids)."
  ;; Convert f to a standard representation and remove suffix
  (if (and gud-jdb-use-classpath (or gud-jdb-classpath gud-jdb-sourcepath))
      (save-match-data
        (let ((cplist (append gud-jdb-sourcepath gud-jdb-classpath))
              (fbuffer (get-file-buffer f))
              class-found
              ;; Syntax-symbol returns the symbol of the *first* element
              ;; in the syntactical analysis result list, syntax-point
              ;; returns the buffer position of same
              (syntax-symbol (lambda (x) (c-langelem-sym (car x))))
              (syntax-point (lambda (x) (c-langelem-pos (car x)))))
          (setq f (file-name-sans-extension (file-truename f)))
          ;; Search through classpath list for an entry that is
          ;; contained in f
          (while (and cplist (not class-found))
            (if (string-match (car cplist) f)
                (setq class-found
		      (mapconcat #'identity
                                 (split-string
                                   (substring f (+ (match-end 0) 1))
                                   "/")
                                 ".")))
            (setq cplist (cdr cplist)))
          ;; if f is visited by a java(cc-mode) buffer, walk up the
          ;; syntactic information chain and collect any 'inclass
          ;; symbols until 'topmost-intro is reached to find out if
          ;; point is within a nested class
	  ;; FIXME: Yuck!!!  cc-mode should provide a function instead.
          (if (and fbuffer (equal (symbol-file 'java-mode) "cc-mode"))
              (with-current-buffer fbuffer
                (let ((nclass) (syntax))
                  ;; While the c-syntactic information does not start
                  ;; with the 'topmost-intro symbol, there may be
                  ;; nested classes...
                  (while (not (eq 'topmost-intro
                                  (funcall syntax-symbol (c-guess-basic-syntax))))
                    ;; Check if the current position c-syntactic
                    ;; analysis has 'inclass
                    (setq syntax (c-guess-basic-syntax))
                    (while
                        (and (not (eq 'inclass (funcall syntax-symbol syntax)))
                             (cdr syntax))
                      (setq syntax (cdr syntax)))
                    (if (eq 'inclass (funcall syntax-symbol syntax))
                        (progn
                          (goto-char (funcall syntax-point syntax))
                          ;; Now we're at the beginning of a class
                          ;; definition.  Find class name
                          (looking-at
                           "[A-Za-z0-9 \t\n]*?class[ \t\n]+\\([^ \t\n]+\\)")
                          (setq nclass
                                (append (list (match-string-no-properties 1))
                                        nclass)))
                      (setq syntax (c-guess-basic-syntax))
                      (while (and (not (funcall syntax-point syntax)) (cdr syntax))
                        (setq syntax (cdr syntax)))
                      (goto-char (funcall syntax-point syntax))
                      ))
                  (string-match (concat (car nclass) "$") class-found)
                  (setq class-found
                        (replace-match (mapconcat #'identity nclass "$")
                                       t t class-found)))))
          (if (not class-found)
              (message "gud-find-class: class for file %s not found!" f))
          class-found))
    ;; Not using classpath - try class/source association list
    (let ((class-found (rassoc f gud-jdb-class-source-alist)))
      (if class-found
	  (car class-found)
	(message "gud-find-class: class for file %s not found in gud-jdb-class-source-alist!" f)
	nil))))