On Sat, 2004-10-09 at 00:32 -0400, Paul Kinnucan wrote:
> Raul Acevedo writes:
>  > Looking at the JDEE source, it looks like it just doesn't know about
>  > symbols in interfaces at all.  In particular, jde-open-jump-to-class
>  > only knows to look in the parent class, but it doesn't consider any
>  > implemented interfaces, either in the current class or in any parent
>  > class.  Is this a known limitation?
>  > 
> 
> Not to me. jde-open-jump-to-class has other limitations as well. I
> plan to work on removing them as soon as possible. If anybody else
> wants to jump in and help with this, feel free.

Here's an implementation that looks through all interfaces in addition
to the parent classes.  It keeps a list of already seen classes lest we
get into an infinite loop somehow.  It also restores buffer positions
after it visits a buffer and doesn't find what it wants, and does a
bury-buffer on all intermediate buffers visited so if the definition you
want is in another buffer, and you do Ctrl-x b, your previous buffer is
right there (instead of the default now being some random file you
haven't explicitly visited).

This method is somewhat complicated so I'm sure I haven't done it the
best way and haven't taken everything into account, but it Works For Me.

Ideally though this would be done entirely differently... rather than
visiting a bunch of files, maybe there's a way to use the jde-usages
plugin data to find the definition directly and more efficiently.

Raul

(defun jde-open-jump-to-class (parsed-symbol class-name java-file-name)
  "Opens JAVA-FILE-NAME and place the cursor in the parsed variable"
  (let* (tokens super-class seen-before old-point (first-time t))
    ;; if the current buffer contains java-file-name do not try to
    ;; open the file
    (if (not (string-equal (buffer-file-name) java-file-name))
        (funcall (or jde-open-cap-ff-function-temp-override
                     jde-open-class-at-point-find-file-function)
                 java-file-name))
    (setq old-point (point))
    (search-forward "{" nil t)
    (setq tokens (append (semantic-tag-type-superclasses 
(semantic-current-tag-of-class 'type))
                         (semantic-tag-type-interfaces (semantic-current-tag-of-class 
'type))))
    (setq super-class (car tokens))
    (when (and (fboundp 'senator-search-forward) (not (string= parsed-symbol "")))
      (beginning-of-buffer)
      (senator-parse)
      (setq parsed-symbol (concat "\\b" parsed-symbol "\\b"))
      (while (and (not (senator-re-search-forward parsed-symbol nil t))
                  (consp tokens))
        (message (format "tokens %s " tokens))
        (let ((token (car tokens)))
          (setq tokens (cdr tokens))
          (if (and (stringp token)
                   (not (member token seen-before)))
              ;; searching for the thing-of-interest has failed 
              ;; let's try in the base class
              (progn
                (setq seen-before (cons token seen-before))
                (goto-char old-point)
                (if (not first-time) (bury-buffer))
                (let ((jde-open-cap-ff-function-temp-override 'find-file))
                  (jde-show-superclass-source-2 (ncons token)))
                (setq old-point (point))
                (beginning-of-buffer)
                (senator-parse)
                (search-forward "{" nil t)
                (setq tokens (append tokens
                                     (semantic-tag-type-superclasses 
(semantic-current-tag-of-class 'type))
                                     (semantic-tag-type-interfaces 
(semantic-current-tag-of-class 'type))))
                ;;if it is the first time try in the class definition
                ;;itself.
                (if first-time
                    (progn 
                      (setq first-time nil)
                      (senator-re-search-forward
                       (progn
                         (string-match ".*\\.\\([^.]+\\)$" (concat "." class-name))
                         (match-string 1 (concat "." class-name)))
                       nil t)))
                (if (not super-class)
                    (error "Method not found"))
                (setq super-class token))))))))


Reply via email to