From f2c6747eeeeb3366ad5aee76e9526b10c2034c9a Mon Sep 17 00:00:00 2001 From: Nicola Mometto Date: Fri, 18 Oct 2024 14:02:09 +0100 Subject: [PATCH] feat: support for understands Class/n --- .../clojure/tools/analyzer/jvm/utils.clj | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/clojure/clojure/tools/analyzer/jvm/utils.clj b/src/main/clojure/clojure/tools/analyzer/jvm/utils.clj index 1332add..678abd4 100644 --- a/src/main/clojure/clojure/tools/analyzer/jvm/utils.clj +++ b/src/main/clojure/clojure/tools/analyzer/jvm/utils.clj @@ -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"