|
67 | 67 | "Takes a Symbol, String or Class and tires to resolve to a matching Class"
|
68 | 68 | class)
|
69 | 69 |
|
70 |
| -(defn array-class [element-type] |
71 |
| - (RT/classForName |
72 |
| - (str "[" (-> element-type |
73 |
| - maybe-class |
74 |
| - Type/getType |
75 |
| - .getDescriptor |
76 |
| - (.replace \/ \.))))) |
| 70 | +(defn array-class |
| 71 | + ([element-type] (array-class 1 element-type)) |
| 72 | + ([n element-type] |
| 73 | + (RT/classForName |
| 74 | + (str (apply str (repeat n"[")) |
| 75 | + (-> element-type |
| 76 | + maybe-class |
| 77 | + Type/getType |
| 78 | + .getDescriptor |
| 79 | + (.replace \/ \.)))))) |
77 | 80 |
|
78 | 81 | (defn maybe-class-from-string [^String s]
|
79 | 82 | (or (when-let [maybe-class (and (neg? (.indexOf s "."))
|
|
90 | 93 | (defmethod maybe-class String [s]
|
91 | 94 | (maybe-class (symbol s)))
|
92 | 95 |
|
| 96 | +(defn maybe-array-class-sym [x] |
| 97 | + (let [sname (name x)] |
| 98 | + (if-let [c (and (= (count sname) 1) |
| 99 | + (Character/isDigit (first sname)) |
| 100 | + (namespace x))] |
| 101 | + (when-let [c (or (specials c) |
| 102 | + (maybe-class-from-string c))] |
| 103 | + (array-class (Integer/parseInt sname) c))))) |
| 104 | + |
93 | 105 | (defmethod maybe-class Symbol [sym]
|
94 |
| - (when-not (namespace sym) |
95 |
| - (let [sname (name sym) |
96 |
| - snamec (count sname)] |
97 |
| - (if-let [base-type (and (.endsWith sname "<>") |
98 |
| - (maybe-class (subs sname 0 (- snamec 2))))] |
99 |
| - (array-class base-type) |
100 |
| - (if-let [ret (or (specials sname) |
101 |
| - (special-arrays sname))] |
102 |
| - ret |
103 |
| - (maybe-class-from-string sname)))))) |
| 106 | + (let [sname (name sym) |
| 107 | + snamec (count sname)] |
| 108 | + (or (maybe-array-class-sym sym) |
| 109 | + (when-not (namespace sym) |
| 110 | + (if-let [base-type (and (.endsWith sname "<>") |
| 111 | + (maybe-class (subs sname 0 (- snamec 2))))] |
| 112 | + ;; TODO: we're leaking into the syntax |
| 113 | + (array-class base-type) |
| 114 | + (if-let [ret (or (specials sname) |
| 115 | + (special-arrays sname))] |
| 116 | + ret |
| 117 | + (maybe-class-from-string sname))))))) |
104 | 118 |
|
105 | 119 | (defn maybe-class-literal [x]
|
106 | 120 | (cond
|
107 |
| - (class? x) x |
108 |
| - (symbol? x) (and (not (namespace x)) |
109 |
| - (maybe-class-from-string (name x))) |
110 |
| - (string? x) (maybe-class-from-string x))) |
| 121 | + (class? x) x |
| 122 | + (symbol? x) (or (maybe-array-class-sym x) |
| 123 | + (and (not (namespace x)) |
| 124 | + (maybe-class-from-string (name x)))) |
| 125 | + (string? x) (maybe-class-from-string x))) |
111 | 126 |
|
112 | 127 | (def primitive?
|
113 | 128 | "Returns non-nil if the argument represents a primitive Class other than Void"
|
|
0 commit comments