<commit_before>
;; (require 'eclim)
;; (global-eclim-mode)


;; (require 'eclimd)

;; (set 'eclim-eclipse-dirs '("~/code/eclipse"))
;; (set 'eclim-executable "~/code/eclipse/eclim")
;; (set 'eclimd-wait-for-process nil)

;; ;; don't think we can change this now :(
;; (set 'eclimd-workspace-dir "~/.eclipse-workspace")



;; (require 'ac-emacs-eclim-source)
;; (ac-emacs-eclim-config)

(require 's)
(require 'dash)

(defun java-toggle-test-file ()
  "Try to locate the file containing tests for this file (or vice versa)."
  (interactive)
  (if (s-contains? "test" (buffer-file-name) 't)
      (java-switch-from-test)
    (java-switch-to-test)))

(defun java-switch-to-test ()
  (let* ((bf-dir (file-name-directory (buffer-file-name)))
         (bf-ext (s-concat "." (file-name-extension (buffer-file-name))))
         (bf-fnm (file-name-base (buffer-file-name)))

         (files-to-try
          (list (s-concat bf-fnm "Test" bf-ext)
                (s-concat "Test" bf-fnm bf-ext)))

         (dirs-to-try
          (-distinct (list bf-dir
                           (s-replace "src/" "test/" bf-dir)
                           (s-replace "source/" "test/" bf-dir))))

         (paths-to-try (-table-flat #'s-concat dirs-to-try files-to-try)))

    ;; Open the first file that exists
    (find-file (car (-filter #'file-exists-p paths-to-try)))))

(defun java-switch-from-test ()
  (let* ((bf-dir (file-name-directory (buffer-file-name)))
         (bf-ext (s-concat "." (file-name-extension (buffer-file-name))))
         (bf-fnm (file-name-base (buffer-file-name)))

         (files-to-try
          (list (s-replace "Test" "" (s-concat bf-fnm bf-ext))))

         (dirs-to-try
          (-distinct (list bf-dir
                           (s-replace "test/" "src/" bf-dir)
                           (s-replace "test/" "source/" bf-dir))))

         (paths-to-try (-table-flat #'s-concat dirs-to-try files-to-try)))

    ;; Open the first file that exists
    (find-file (car (-filter #'file-exists-p paths-to-try)))))


(defun java-keys ()
  (interactive)
  ;; (local-set-key (kbd "M-.") 'eclim-java-find-declaration)

  (local-set-key (kbd "C-c") '())
  (local-set-key (kbd "C-\\ o") #'java-toggle-test-file)
  (local-set-key (kbd "C-d") 'nil)


  ;; ;; Fix tab bindings (messed up by yas and/or binding C-i
  ;; (local-set-key (kbd "TAB") '())
  ;; (set-tab)

  )
(add-hook 'java-mode-hook 'java-keys)

;; ;; Run eclimd automatically when we open a java buffer (if not running
;; ;; already).
;; (add-hook 'java-mode-hook
;;           (lambda () (unless (eclimd--running-p)
;;                        (start-eclimd eclimd-workspace-dir)
;;                        (define-key java-mode-map (kbd "C-c") nil))))<commit_msg>Improve java switch to test file<commit_after>
;; (require 'eclim)
;; (global-eclim-mode)


;; (require 'eclimd)

;; (set 'eclim-eclipse-dirs '("~/code/eclipse"))
;; (set 'eclim-executable "~/code/eclipse/eclim")
;; (set 'eclimd-wait-for-process nil)

;; ;; don't think we can change this now :(
;; (set 'eclimd-workspace-dir "~/.eclipse-workspace")



;; (require 'ac-emacs-eclim-source)
;; (ac-emacs-eclim-config)

(require 's)
(require 'dash)

(defun java-toggle-test-file ()
  "Try to locate the file containing tests for this file (or vice versa)."
  (interactive)
  (if (s-contains? "test" (buffer-file-name) 't)
      (java-switch-from-test)
    (java-switch-to-test)))

(defun java-switch-to-test ()
  (let* ((bf-dir (file-name-directory (buffer-file-name)))
         (bf-ext (s-concat "." (file-name-extension (buffer-file-name))))
         (bf-fnm (file-name-base (buffer-file-name)))

         (files-to-try
          (list (s-concat bf-fnm "Test" bf-ext)
                (s-concat "Test" bf-fnm bf-ext)))

         (dirs-to-try
          (-distinct (list bf-dir
                           (s-replace "src/" "test/" bf-dir)
                           (s-replace "source/" "test/" bf-dir))))

         (paths-to-try (-table-flat #'s-concat dirs-to-try files-to-try))

         (path (-first #'file-exists-p paths-to-try)))

    (when (not path) (throw 'no-file-found "No candidate paths found"))

    ;; Open the first file that exists
    (find-file path)))

(defun java-switch-from-test ()
  (let* ((bf-dir (file-name-directory (buffer-file-name)))
         (bf-ext (s-concat "." (file-name-extension (buffer-file-name))))
         (bf-fnm (file-name-base (buffer-file-name)))

         (files-to-try
          (list (s-replace "Test" "" (s-concat bf-fnm bf-ext))))

         (dirs-to-try
          (-distinct (list bf-dir
                           (s-replace "test/" "src/" bf-dir)
                           (s-replace "test/" "source/" bf-dir))))

         (paths-to-try (-table-flat #'s-concat dirs-to-try files-to-try))

         (path (-first #'file-exists-p paths-to-try)))

    (when (not path) (throw 'no-file-found "No candidate paths found"))

    ;; Open the first file that exists
    (find-file path)))


(defun java-keys ()
  (interactive)
  ;; (local-set-key (kbd "M-.") 'eclim-java-find-declaration)

  (local-set-key (kbd "C-c") '())
  (local-set-key (kbd "C-\\ o") #'java-toggle-test-file)
  (local-set-key (kbd "C-d") 'nil)


  ;; ;; Fix tab bindings (messed up by yas and/or binding C-i
  ;; (local-set-key (kbd "TAB") '())
  ;; (set-tab)

  )
(add-hook 'java-mode-hook 'java-keys)

;; ;; Run eclimd automatically when we open a java buffer (if not running
;; ;; already).
;; (add-hook 'java-mode-hook
;;           (lambda () (unless (eclimd--running-p)
;;                        (start-eclimd eclimd-workspace-dir)
;;                        (define-key java-mode-map (kbd "C-c") nil))))
{'fraction_non_alphanumeric': 0.19479369576766425, 'fraction_numerical': 0.0, 'mean_word_length': 2.2761020881670535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '879629', 'n_tokens_mistral': 2148, 'n_tokens_neox': 2030, 'n_words': 454}