From 5db93083a72839a75fce2cf82945714d34aced95 Mon Sep 17 00:00:00 2001 From: Kevin Downey Date: Mon, 5 Mar 2012 15:33:39 -0500 Subject: [PATCH] support annotations for constructors generated via gen-class --- build.xml | 1 + src/clj/clojure/genclass.clj | 4 +++- test/clojure/test_clojure/annotations/java_5.clj | 14 ++++++++++++++ test/clojure/test_clojure/annotations/java_6.clj | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 1 deletions(-) diff --git a/build.xml b/build.xml index 56cc788..57ac17b 100644 --- a/build.xml +++ b/build.xml @@ -88,6 +88,7 @@ + diff --git a/src/clj/clojure/genclass.clj b/src/clj/clojure/genclass.clj index 93fa438..a99387d 100644 --- a/src/clj/clojure/genclass.clj +++ b/src/clj/clojure/genclass.clj @@ -288,13 +288,15 @@ ;ctors (doseq [[pclasses super-pclasses] ctor-sig-map] - (let [pclasses (map the-class pclasses) + (let [constructor-annotations (meta pclasses) + pclasses (map the-class pclasses) super-pclasses (map the-class super-pclasses) ptypes (to-types pclasses) super-ptypes (to-types super-pclasses) m (new Method "" (. Type VOID_TYPE) ptypes) super-m (new Method "" (. Type VOID_TYPE) super-ptypes) gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv) + _ (add-annotations gen constructor-annotations) no-init-label (. gen newLabel) end-label (. gen newLabel) no-post-init-label (. gen newLabel) diff --git a/test/clojure/test_clojure/annotations/java_5.clj b/test/clojure/test_clojure/annotations/java_5.clj index 28daae1..060ea72 100644 --- a/test/clojure/test_clojure/annotations/java_5.clj +++ b/test/clojure/test_clojure/annotations/java_5.clj @@ -52,3 +52,17 @@ expected-annotations (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil))))))) +(gen-class :name foo.Bar + :extends clojure.lang.Box + :constructors {^{Deprecated true} [Object] [Object]} + :init init + :prefix "foo") + +(defn foo-init [obj] + [[obj] nil]) + +(deftest test-annotations-on-constructor + (is (some #(instance? Deprecated %) + (for [ctor (.getConstructors (Class/forName "foo.Bar")) + annotation (.getAnnotations ctor)] + annotation)))) diff --git a/test/clojure/test_clojure/annotations/java_6.clj b/test/clojure/test_clojure/annotations/java_6.clj index 49d2404..f8e06ac 100644 --- a/test/clojure/test_clojure/annotations/java_6.clj +++ b/test/clojure/test_clojure/annotations/java_6.clj @@ -71,3 +71,17 @@ expected-annotations (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil))))))) +(gen-class :name foo.Bar + :extends clojure.lang.Box + :constructors {^{Deprecated true} [Object] [Object]} + :init init + :prefix "foo") + +(defn foo-init [obj] + [[obj] nil]) + +(deftest test-annotations-on-constructor + (is (some #(instance? Deprecated %) + (for [ctor (.getConstructors (Class/forName "foo.Bar")) + annotation (.getAnnotations ctor)] + annotation)))) -- 1.7.5.1