Skip to content

Commit d491bae

Browse files
committed
yes
1 parent 22df738 commit d491bae

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

notebooks/qualified_methods.clj

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ Integer/parseInt ;; method value
1010

1111
String/CASE_INSENSITIVE_ORDER ;; field
1212

13-
;; TODO:
14-
;; (String/new "dude")
13+
(String/new "dude") ;; constructor
1514

16-
;; TODO
17-
;; (map String/new ["dude"])
15+
String/new
1816

19-
;; TODO
20-
;; (map Integer/parseInt ["1" "2" "3"])
17+
(map String/new ["dude"])
18+
19+
(map Integer/parseInt ["1" "2" "3"])

tools-analyzer/nextjournal/clerk/clojure/tools/analyzer/jvm.clj

+22-11
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,23 @@
133133
(if (and (= (count opname) 1)
134134
(Character/isDigit ^Character (first opname)))
135135
form ;; Array/<n>
136-
(if (or (.startsWith opname ".")
137-
(let [members (u/members target)]
138-
;; TODO: only pick non-methods!
139-
(some #(when (and (= opname-sym (:name %))
140-
(not (instance? clojure.reflect.Field %)))
141-
%) members)))
136+
(cond
137+
(= "new" opname)
138+
`(fn
139+
([x#] (new ~(symbol sym-ns) x#))
140+
;; TODO: analyze method and return properly expanded fn
141+
)
142+
(or (.startsWith opname ".")
143+
(let [members (u/members target)]
144+
;; TODO: only pick non-methods!
145+
(some #(when (and (= opname-sym (:name %))
146+
(not (instance? clojure.reflect.Field %)))
147+
%) members)))
142148
`(fn
143149
([x#] (~form x#))
144150
;; TODO: analyze method and return properly expanded fn
145151
)
152+
:else
146153
(with-meta (list '. target (symbol (str "-" opname))) ;; transform to (. Class -field)
147154
(meta form)))))
148155
form)))
@@ -158,10 +165,13 @@
158165
(when-not (.startsWith opname ".")
159166
opns-class))] ; (class/field ..)
160167
(let [op (symbol opname)]
161-
(with-meta (list '. target (if (zero? (count expr))
162-
op
163-
(list* op expr)))
164-
(meta form)))
168+
(if (= 'new op)
169+
(with-meta (list* 'new (symbol opns) expr)
170+
(meta form))
171+
(with-meta (list '. target (if (zero? (count expr))
172+
op
173+
(list* op expr)))
174+
(meta form))))
165175

166176
(cond
167177
(.startsWith opname ".") ; (.foo bar ..)
@@ -181,7 +191,6 @@
181191
(.endsWith opname ".") ;; (class. ..)
182192
(with-meta (list* 'new (symbol (subs opname 0 (dec (count opname)))) expr)
183193
(meta form))
184-
185194
:else form)))
186195
form)))
187196

@@ -659,4 +668,6 @@
659668
(String/.length x))))
660669

661670
(macroexpand-1 'clojure.lang.Compiler/LOADER)
671+
(macroexpand-1 '(String/new "foo"))
672+
(macroexpand-1 'String/new)
662673
)

0 commit comments

Comments
 (0)