(defn desugar-host-expr [form env]
(let [[op & expr] form]
(if (symbol? op)
(let [opname (name op)
opns (namespace op)]
(if-let [target (and opns
(not (resolve-ns (symbol opns) env))
(maybe-class-literal opns))] ; (class/field ..)
(let [op (symbol opname)]
(with-meta (list '. target (if (zero? (count expr))
op
(list* op expr)))
(meta form)))
(cond
(.startsWith opname ".") ; (.foo bar ..)
(let [[target & args] expr
target (if-let [target (maybe-class-literal target)]
(with-meta (list 'do target)
{:tag 'java.lang.Class})
target)
args (list* (symbol (subs opname 1)) args)]
(with-meta (list '. target (if (= 1 (count args)) ;; we don't know if (.foo bar) is
(first args) args)) ;; a method call or a field access
(meta form)))
(.endsWith opname ".") ;; (class. ..)
(with-meta (list* 'new (symbol (subs opname 0 (dec (count opname)))) expr)
(meta form))
:else form)))
form)))