Skip to content

Commit ba8269d

Browse files
hiredmanstuarthalloway
authored andcommitted
support annotations for constructors generated via gen-class
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
1 parent 9aa3bca commit ba8269d

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

build.xml

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<!--<sysproperty key="clojure.compiler.disable-locals-clearing" value="true"/>-->
9393
<arg value="clojure.test-clojure.protocols.examples"/>
9494
<arg value="clojure.test-clojure.genclass.examples"/>
95+
<arg value="clojure.test-clojure.annotations"/>
9596
</java>
9697
</target>
9798

src/clj/clojure/genclass.clj

+3-1
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,15 @@
301301

302302
;ctors
303303
(doseq [[pclasses super-pclasses] ctor-sig-map]
304-
(let [pclasses (map the-class pclasses)
304+
(let [constructor-annotations (meta pclasses)
305+
pclasses (map the-class pclasses)
305306
super-pclasses (map the-class super-pclasses)
306307
ptypes (to-types pclasses)
307308
super-ptypes (to-types super-pclasses)
308309
m (new Method "<init>" (. Type VOID_TYPE) ptypes)
309310
super-m (new Method "<init>" (. Type VOID_TYPE) super-ptypes)
310311
gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)
312+
_ (add-annotations gen constructor-annotations)
311313
no-init-label (. gen newLabel)
312314
end-label (. gen newLabel)
313315
no-post-init-label (. gen newLabel)

test/clojure/test_clojure/annotations/java_5.clj

+14
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,17 @@
5252
expected-annotations
5353
(into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil)))))))
5454

55+
(gen-class :name foo.Bar
56+
:extends clojure.lang.Box
57+
:constructors {^{Deprecated true} [Object] [Object]}
58+
:init init
59+
:prefix "foo")
60+
61+
(defn foo-init [obj]
62+
[[obj] nil])
63+
64+
(deftest test-annotations-on-constructor
65+
(is (some #(instance? Deprecated %)
66+
(for [ctor (.getConstructors (Class/forName "foo.Bar"))
67+
annotation (.getAnnotations ctor)]
68+
annotation))))

test/clojure/test_clojure/annotations/java_6.clj

+14
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,17 @@
7171
expected-annotations
7272
(into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil)))))))
7373

74+
(gen-class :name foo.Bar
75+
:extends clojure.lang.Box
76+
:constructors {^{Deprecated true} [Object] [Object]}
77+
:init init
78+
:prefix "foo")
79+
80+
(defn foo-init [obj]
81+
[[obj] nil])
82+
83+
(deftest test-annotations-on-constructor
84+
(is (some #(instance? Deprecated %)
85+
(for [ctor (.getConstructors (Class/forName "foo.Bar"))
86+
annotation (.getAnnotations ctor)]
87+
annotation))))

0 commit comments

Comments
 (0)