JDE for Emacs

JDEE Resources

My JDEE emacs lisp functions

#!lisp (-)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                                               ;;
;;    ToString Wizard - yoonforh edition                                         ;;
;;                                                                               ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defcustom jde-wiz-tostring-sort-variables nil
  "*Specifies whether or not to sort the list of variables in the
  generated method or list them in the order defined in the file."
  :group 'jde-wiz
  :type 'boolean)

(defcustom jde-wiz-tostring-stringbuffer-size "100"
  "*Specifies the initial size of the StringBuffer used to create the
  result for the toString().  It is best to set this to a value large
  enough for most of your work to prevent expansion of the
  StringBuffer at runtime.  You can always change the value in the
  generated code to a smaller or larger one as needed."
  :group 'jde-wiz-tostring
  :type 'string)

(defcustom jde-wiz-tostring-variable-separator "\", \""
  "*Specifies the string between each variable to separate them.
  Examples: 2 spaces (the default), a comma and a space, newline, or a
  method call (as long as the return value is a String).

  Note: Remember this must result in a String in Java!"
  :group 'jde-wiz-tostring
  :type 'string)

(defcustom jde-wiz-tostring-static-members nil
  "If on (nonnil), `jde-wiz-tostring' generates information of 
 static members of the class in the current buffer."
  :group 'jde-wiz
  :type 'boolean)

(defun jde-wiz-tostring()
  "Generates a toString() method for tbe class at point. The method
returns a string comprising the values of the member variables defined
by the class. The string lists the variables in alphabetical 
order if `jde-wiz-tostring-sort-variables' is on. The string uses the
string specified by `jde-wiz-tostring-variable-separator' to separate
the variables. The generated method uses a string buffer of the size
specified by `jde-wiz-tostring-stringbuffer-size' to build the string."
 (interactive)
 (let* ((class-name 
         (jde-parse-get-unqualified-name
          (jde-parse-get-class-at-point)))
        (variables 
         (semantic-find-nonterminal-by-token 
          'variable 
          (jde-wiz-get-class-parts 
           class-name 
           (semantic-find-nonterminal-by-token 
            'type 
            (semantic-bovinate-toplevel t)
            ))))
        (method
         (concat
          "/**\n"
          " * {@inheritDoc}\n"
          " */\n"
          "public String toString()"
          (if jde-gen-k&r " {\n" "\n{\n")
          "return \"" class-name "(")))
;;        "final int sbSize = " jde-wiz-tostring-stringbuffer-size  ";\n"
;;        "final String variableSeparator = " jde-wiz-tostring-variable-separator ";\n"
;;        "final StringBuffer sb = new StringBuffer(sbSize);\n\n")))

   (setq variables (jde-wiz-filter-variables-by-typemodifier variables))

   (if jde-wiz-tostring-sort-variables
       (setq variables (semantic-sort-tokens-by-name-increasing variables)))

   (setq size (length variables))

   (while variables
     (let* ((var (car variables))
           (name (semantic-token-name var)) ;;variable name
           (type (semantic-token-type var)) ;;variable type i.e. boolean
           (staticp
            (member "static"
                    (semantic-token-variable-modifiers var))) ;;is it static
           (finalp
            (member "final"
                   (semantic-token-variable-modifiers var)))) ;;is it final

       (if (or (not staticp) jde-wiz-tostring-static-members)
           (if (> (length variables) 1)
               (setq method (concat method name " - \" + " name "\n+ \", "))
             (setq method 
                   (concat method name " - \" + " name "\n+ \")\";\n}\n")))
         (setq size (- size 1))
         )

       (setq variables (cdr variables))))
;;   (setq method (concat method "[" (number-to-string size) "]"))
   (if (= size 0)
       (setq method 
             (concat method ")\";\n}\n")))

   (insert method))

 (jde-wiz-indent (point)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                                               ;;
;;    jde-wiz-constructor - by yoonforh                                          ;;
;;                                                                               ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun jde-wiz-constructor()
  "Generates a constructor() method for tbe class at point. The method
returns a string comprising the values of the member variables defined
by the class."
 (interactive)
 (let* ((class-name 
         (jde-parse-get-unqualified-name
          (jde-parse-get-class-at-point)))
        (variables 
         (semantic-find-nonterminal-by-token 
          'variable 
          (jde-wiz-get-class-parts 
           class-name 
           (semantic-find-nonterminal-by-token 
            'type 
            (semantic-bovinate-toplevel t)
            ))))
        (method
         (concat
          "public " class-name "("))
        (body)
        )

   (setq variables (jde-wiz-filter-variables-by-typemodifier variables))

   (if jde-wiz-tostring-sort-variables
       (setq variables (semantic-sort-tokens-by-name-increasing variables)))

   (setq size (length variables))

   (while variables
     (let* ((var (car variables))
           (name (semantic-token-name var)) ;;variable name
           (type (semantic-token-type var)) ;;variable type i.e. boolean
           (staticp
            (member "static"
                    (semantic-token-variable-modifiers var))) ;;is it static
           (finalp
            (member "final"
                   (semantic-token-variable-modifiers var)))) ;;is it final

       (if (or (not staticp) jde-wiz-tostring-static-members)
           (progn 
                   (if (> (length variables) 1)
                       (setq method (concat method type " " name ", "))
                     (setq method 
                           (concat method type " " name (if jde-gen-k&r ") {\n" ")\n{\n")))
                     )
                   (setq body (concat body "this." name " = " name ";\n"))
                   ))
       (if staticp (setq size (- size 1)))
       (if finalp (setq size (- size 1)))

       (setq variables (cdr variables))))
;;   (setq method (concat method "[" (number-to-string size) "]"))
   (if (= size 0)
       (setq method 
             (concat method (if jde-gen-k&r ") {\n" ")\n{\n"))))
   (setq method 
         (concat method body "}\n"))

   (insert method))

 (jde-wiz-indent (point)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                                               ;;
;;    jde-wiz-log-method - by yoonforh                                           ;;
;;                                                                               ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;###autoload
(defun jde-wiz-log-method()
  "insert logger statement of a method or constructor"
  (interactive)
  (if (not (eq major-mode 'jde-mode))
      (error "Major mode must be 'jde-mode'"))
  (let ((found (jde-javadoc-nonterminal-at-line)))
    (if (not found)
        (error "No tag found at point")
      (let* ((modifiers  (semantic-tag-modifiers found))
            (type       (semantic-tag-type               found))
            (name       (semantic-tag-name               found))
            (arguments       (semantic-tag-function-arguments found))
            (throws     (semantic-tag-function-throws    found))
        (string
         (concat
          "if (logger.isLoggable(Level.FINEST))"
          (if jde-gen-k&r " {\n" "\n{\n")
          "logger.finest(\""
          name
          "(")))

        (setq size (length arguments))

        (while arguments
          (let* ((arg (car arguments))
                 (name (semantic-tag-name arg)) ;;argument name
                 (type (semantic-tag-type arg)) ;;argument type i.e. boolean
                 )

            (if (> (length arguments) 1)
                (setq string (concat string name " - \" + " name " + \", "))
              (setq string 
                    (concat string name " - \" + " name " + \")\");\n}\n\n")))

            (setq arguments (cdr arguments))))
;;        (setq string (concat string "[" (number-to-string size) "]"))
        (if (= size 0)
            (setq string
                  (concat string ")\");\n}\n\n")))
        (insert string)
        ))

    (jde-wiz-indent (point))
    ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                                               ;;
;;    jde-wiz-logger-decl - by yoonforh                                          ;;
;;                                                                               ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun jde-wiz-logger-decl()
  "insert logger declaration statement of current class"
  (interactive)
  (if (not (eq major-mode 'jde-mode))
      (error "Major mode must be 'jde-mode'"))
  (let* ((class-name 
         (jde-parse-get-unqualified-name
          (jde-parse-get-class-at-point)))
        (package (jde-wiz-get-package-name)))
    (progn
      (if (not package)
          (setq string (concat "private static Logger logger = Logger.getLogger(" class-name ".class.getName());\n\n"))
        (setq string (concat "private static Logger logger = Logger.getLogger(\"" package "\");\n\n"))
      (insert string)
      (jde-wiz-indent (point)))
    ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                                               ;;
;;    jde-wiz-assign-args - by yoonforh                                          ;;
;;                                                                               ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;###autoload
(defun jde-wiz-assign-args()
  "insert assign statements for each args of a method or constructor"
  (interactive)
  (if (not (eq major-mode 'jde-mode))
      (error "Major mode must be 'jde-mode'"))
  (let ((found (jde-yoonforh-nonterminal-at-line)))
    (if (not found)
        (error "No tag found at point")
      (let* ((modifiers  (semantic-tag-modifiers found))
            (type       (semantic-tag-type               found))
            (name       (semantic-tag-name               found))
            (arguments       (semantic-tag-function-arguments found))
            (throws     (semantic-tag-function-throws    found)))
        (while arguments
          (let* ((arg (car arguments))
                 (name (semantic-tag-name arg)) ;;argument name
                 (type (semantic-tag-type arg)) ;;argument type i.e. boolean
                 )

            (insert (concat "this." name " = " name ";\n"))
            (setq arguments (cdr arguments))))
;;        (setq string (concat string "[" (number-to-string size) "]"))
        ))

    (jde-wiz-indent (point))
    ))


(global-set-key [?\C-c?\C-v?l] 'jde-wiz-log-method)
(global-set-key [?\C-c?\C-v?s] 'jde-wiz-tostring)
(global-set-key [?\C-c?\C-v?a] 'jde-wiz-assign-args)
(global-set-key [?\C-c?\C-v?c] 'jde-wiz-constructor)
(global-set-key [?\C-c?\C-v?p] 'jde-wiz-logger-decl)

Binding for keymap jde-mode-map

As of JDEE 2.3.4

key             binding
---             -------

<f4>            html-script-release-region
C-c             Prefix Command
/               c-electric-slash
*               c-electric-star
,               c-electric-semi&comma
DEL             c-electric-backspace
C-d             c-electric-delete-forward
TAB             c-indent-command
ESC             Prefix Command
)               c-electric-paren
(               c-electric-paren
:               c-electric-colon
#               c-electric-pound
;               c-electric-semi&comma
}               c-electric-brace
{               c-electric-brace

C-c C-v         Prefix Command
C-c .           c-set-style
C-c C-t         c-toggle-auto-hungry-state
C-c C-s         c-show-syntactic-information
C-c C-o         c-set-offset
C-c C-d         c-toggle-hungry-state
C-c C-c         comment-region
C-c C-b         c-submit-bug-report
C-c C-a         c-toggle-auto-state
C-c C-\         c-backslash-region
C-c C-q         c-indent-defun
C-c C-u         c-up-conditional
C-c C-p         c-backward-conditional
C-c C-n         c-forward-conditional

ESC q           c-fill-paragraph
ESC j           c-indent-new-comment-line
ESC C-j         c-indent-new-comment-line
ESC e           c-end-of-statement
ESC a           c-beginning-of-statement
ESC C-q         c-indent-exp
ESC C-h         c-mark-function

C-c C-v .       jde-complete-in-line
C-c C-v C-.     jde-complete
C-c C-v C-]     jde-run-etrace-next
C-c C-v ESC     jde-run-etrace-prev
C-c C-v z       jde-import-all
C-c C-v t       jde-gen-try-catch-wrapper
C-c C-v o       jde-wiz-override-method
C-c C-v j       jde-javadoc-autodoc-at-line
C-c C-v i       jde-wiz-implement-interface
C-c C-v f       jde-gen-try-finally-wrapper
C-c C-v e       jde-wiz-extend-abstract-class
C-c C-v C-z     jde-import-find-and-import
C-c C-v C-y     jde-open-class-at-point
C-c C-v C-x     jde-show-superclass-source
C-c C-v C-w     jde-help-symbol
C-c C-v C-t     jde-jdb-menu-debug-applet
C-c C-v C-s     speedbar-frame-mode
C-c C-v C-r     jde-run
C-c C-v C-q     jde-wiz-update-class-list
C-c C-v C-p     jde-save-project
C-c C-v C-n     jde-help-browse-jdk-doc
C-c C-v C-l     jde-gen-println
C-c C-v C-k     jde-bsh-run
C-c C-v C-g     jde-open-class-at-point
C-c C-v C-f     jde-find
C-c C-v C-d     jde-debug
C-c C-v C-c     jde-compile
C-c C-v C-b     jde-build
C-c C-v C-a     jde-run-menu-run-applet