For the sake of posterity, here is the elisp finction I ended up writing to
add calls to a Timer class that we have.  Perhaps it will be useful to other
or serve as a simple example for other elisp beginners.  I couldn't find a
good jde-parse function that returned the current method name.   Thanks for
the help from members of this list.


(defun add-timer()
  (interactive)
  "Instrument java method by adding calls to a class Timer "
  (let* (
         (package-name (jde-parse-get-package-name))
         (class-name (jde-parse-get-class-at-point))
         (method-name 
          (progn 
            (save-excursion
              (senator-beginning-of-defun)
              (re-search-forward "\\([a-zA-Z0-9_]*\\)[ \t\n\r]*\(")
              (buffer-substring (match-beginning 1) (match-end 1) )
              )
            )
          )
         (timer-name (concat package-name "." class-name "." method-name))
         )
    (senator-beginning-of-defun)
    (re-search-forward "\{")
    (re-search-forward "\n")
    (insert "try {Timer.startTimer(\"" timer-name "\");\n")
    (next-line -1)
    (indent-according-to-mode)    
    (senator-end-of-defun)
    (re-search-backward "}")
    (beginning-of-line)
    (insert "} finally {Timer.stopTimer(\"" timer-name "\");}\n")
    (next-line -1)
    (indent-according-to-mode)    
    )
)

Reply via email to