       (goto-char bound-start)
       (kill-forward-chars (- bound-end bound-start))
       (cond
-       ((re-match-p "[a-z_]+$" symbol) (message (insert (underscores-to-camelcase symbol))))
-       ((re-match-p "[a-z]+" symbol) (insert (java-variable-to-type symbol)))
-       ((re-match-p "[A-Z][a-z]+" symbol) (insert (java-type-to-constant symbol)))
-       (t (insert (downcase symbol)))))))
+       ((re-match-p "[a-z_]+$" symbol) (insert (format-symbol symbol 'camelcase-lower)))
+       ((re-match-p "[a-z]+" symbol) (insert (format-symbol symbol 'camelcase)))
+       ((re-match-p "[A-Z][a-z]+" symbol) (insert (format-symbol symbol 'constant)))
+       (t (insert (format-symbol symbol 'variable-underscore)))))))
 
 (define-key java-mode-map (kbd "C-M-c") 'java-cycle-case)
 

        (setq first-char (upcase first-char))
      (setq first-char (downcase first-char)))
    (concat first-char rest)))

(defun underscores-to-camelcase (variable-name)
  "Convert a string  \"foo_bar\" to \"fooBar\"."
  (toggle-case-first-char
   (mapconcat 'toggle-case-first-char (split-string variable-name "_") "")))

(require 'cl); first, second



(require 'regexp-utils); re-find-all

(defun string-contains-p (substring string)
  "Returns t if STRING contains SUBSTRING."
  (re-search-p (regexp-quote substring) string))

(defun format-symbol (string format)
  "Convert a given string to a specified formatting convention.

(format-symbol \"fooBar\" 'constant) => \"FOO_BAR\""
  (let ((components))
    ;; split the string into its word components
    (if (string-contains-p "_" string)
        (setq components (split-string string "_"))
      (setq components (re-find-all "[A-Z]?[a-z]+" string)))
    ;; format each component as a lowercase string
    (setq components (mapcar 'downcase components))
    (cond
     ((eq format 'constant) (mapconcat 'upcase components "_"))
     ((eq format 'camelcase) (mapconcat 'toggle-case-first-char components ""))
     ((eq format 'camelcase-lower) (toggle-case-first-char
                                    (mapconcat 'toggle-case-first-char components "")))
     ((eq format 'variable-underscore) (mapconcat (lambda (x) x) components "_"))
     ((eq format 'variable-hyphen) (mapconcat (lambda (x) x) components "-"))
     (t (error "Unknown symbol format")))))

(defun toggle-case-first-char (string)
  (let ((first-char (substring string 0 1))
