[OT] Buffer loading magic?>James Higginbotham writes
>Can someone point me to something that would allow me to toggle between the
source and unit test for a class, if
wrote this a long time ago, the code sucks but it works ( i no longer use it)..
just set the two variables to the source and test directories for the project,
and bind the function my-java-toggle-test-buffers to a key and away you go.. if
you want the test/source directory variables to change when a project changes
then you will need to rename them so they have a prefix of "jde-"
(defcustom my-java-test-directory "."
"test case directory"
:type 'directory)
(defcustom my-java-source-directory "."
"directory for java classes"
:type 'directory)
(defun my-java-toggle-test-buffers ()
"jumps back and forth from a test buffer to the class buffer"
(interactive)
(if (string-match "\\([A-z]*\\)Test" (my-java-class-name))
(my-java-jump-to-class-for-test-case)
(my-java-jump-to-test-case)))
(defun my-java-jump-to-class-for-test-case ()
"jumps to a buffer containg the test case for the specified class name"
(interactive)
(if (not (or (jde-find-class-source (my-java-class-name-for-test))
(get-buffer (concat (my-java-class-name-for-test) ".java"))))
(progn
(find-file (concat (file-name-directory (concat (file-name-directory
my-java-source-directory) (subst-char-in-string ?. ?/ (jde-db-get-package))))
"/" (my-java-class-name-for-test) ".java"))
(jde-gen-class))
(switch-to-buffer (get-buffer (concat (my-java-class-name-for-test)
".java")))
(make-directory default-directory 't)))
(defun my-java-jump-to-test-case ()
"jumps to a buffer containg the test case for the class in the current buffer"
(interactive)
(if (not (or (jde-find-class-source (my-java-testcase-name-with-package))
(get-buffer (concat (my-java-testcase-name) ".java"))))
(progn
(find-file (concat (file-name-directory (concat (file-name-directory
my-java-test-directory) (subst-char-in-string ?. ?/ (jde-db-get-package))))
(my-java-testcase-name) ".java"))
(jde-gen-class))
(switch-to-buffer (get-buffer (concat (my-java-testcase-name) ".java")))
(make-directory default-directory 't)))
(defun my-java-class-name-for-test ()
"the class name that the current buffer is writing a test for"
(if (string-match "\\([A-z]*\\)Test" (my-java-class-name))
(match-string 1 (my-java-class-name))
(my-java-class-name)))
(defun my-java-testcase-name ()
"name of the current class's testcase sans the package prefix"
(concat
(my-java-class-name)
(if (not (string-match "Test" (my-java-class-name)))
"Test")))
(defun my-java-testcase-name-with-package ()
"the name of the current classe's TestCase"
(concat (jde-db-get-package)
(my-java-testcase-name)))
(defun my-java-class-name ()
"the name of the current class sans the package prefix"
(file-name-sans-extension
(file-name-nondirectory (buffer-file-name))))
;; and if you also want to easily run the current classe's test case...
(defun my-java-run-associated-testcase ()
"run the associated test case for the class specified"
(interactive)
;;prepend test to the class name, and keep the current package context...
(let* ((jde-run-application-class "junit.textui.TestRunner")
(jde-run-option-application-args (list
(my-java-testcase-name-with-package))))
(jde-run-main-class)
)
)
(defun my-java-testcase-name-with-package ()
"returns the name of the current classes TestCase"
(concat (jde-db-get-package)
(my-java-testcase-name))
)
-b
----- Original Message -----
From: James Higginbotham
To: [EMAIL PROTECTED]
Sent: Wednesday, October 30, 2002 6:22 PM
Subject: [OT] Buffer loading magic?
Totally offtopic to JDE but related to emacs and Java:
Can someone point me to something that would allow me to toggle between the
source and unit test for a class, if my directory structure is usually something
like:
src
com
mycompany
foo
Bar.java
test
com
mycompany
foo
BarTest.java
.and my tests always end in 'Test.java'?
Just wondering if someone has done this or something similar. If found an elisp
snippet for C to header, but that assumes the same dir and I'm not elisp
literate enough to determine how best to mod the code.
Thanks,
James