Skip to content

Commit

Permalink
feat: support for understands Class/n
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronsa committed Oct 18, 2024
1 parent d74645c commit f2c6747
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/main/clojure/clojure/tools/analyzer/jvm/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,36 @@
(defmethod maybe-class String [s]
(maybe-class (symbol s)))

(defn maybe-array-class-sym [x]
(let [sname (name x)]
(if-let [c (and (= (count sname) 1)
(Character/isDigit (first sname))
(namespace x))]
(when-let [c (or (specials c)
(maybe-class-from-string c))]
(array-class (Integer/parseInt sname) c)))))

(defmethod maybe-class Symbol [sym]
(when-not (namespace sym)
(let [sname (name sym)
snamec (count sname)]
(if-let [base-type (and (.endsWith sname "<>")
(maybe-class (subs sname 0 (- snamec 2))))]
(array-class base-type)
(if-let [ret (or (specials sname)
(special-arrays sname))]
ret
(maybe-class-from-string sname))))))
(let [sname (name sym)
snamec (count sname)]
(or (maybe-array-class-sym sym)
(when-not (namespace sym)
(if-let [base-type (and (.endsWith sname "<>")
(maybe-class (subs sname 0 (- snamec 2))))]
;; TODO: we're leaking into the syntax
(array-class base-type)
(if-let [ret (or (specials sname)
(special-arrays sname))]
ret
(maybe-class-from-string sname)))))))

(defn maybe-class-literal [x]
(cond
(class? x) x
(symbol? x) (and (not (namespace x))
(maybe-class-from-string (name x)))
(string? x) (maybe-class-from-string x)))
(class? x) x
(symbol? x) (or (maybe-array-class-sym x)
(and (not (namespace x))
(maybe-class-from-string (name x))))
(string? x) (maybe-class-from-string x)))

(def primitive?
"Returns non-nil if the argument represents a primitive Class other than Void"
Expand Down

0 comments on commit f2c6747

Please sign in to comment.