Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns com.banksimple.util.scala-tools
(:require [clojure.contrib [string :as str]]
[def :as deftools]))
(defmacro import-singleton [klass-sym]
(let [singleton-str (str klass-sym "$")
simple-name (symbol (.toLowerCase (last (str/split #"\." (str klass-sym)))))
singleton-sym (symbol singleton-str)
mod-field-sym (symbol (str singleton-str "/MODULE$"))]
`(do (import ~klass-sym ~singleton-sym)
(let [sklass-name# (.getSimpleName ~klass-sym)]
(deftools/defvar ~simple-name ~mod-field-sym)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.