Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

support annotations for constructors generated via gen-class

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information...
commit ba8269d34db04639bd10d0789866ea446a388979 1 parent 9aa3bca
@hiredman hiredman authored stuarthalloway committed
View
1  build.xml
@@ -92,6 +92,7 @@
<!--<sysproperty key="clojure.compiler.disable-locals-clearing" value="true"/>-->
<arg value="clojure.test-clojure.protocols.examples"/>
<arg value="clojure.test-clojure.genclass.examples"/>
+ <arg value="clojure.test-clojure.annotations"/>
</java>
</target>
View
4 src/clj/clojure/genclass.clj
@@ -301,13 +301,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 "<init>" (. Type VOID_TYPE) ptypes)
super-m (new Method "<init>" (. 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)
View
14 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))))
View
14 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))))
Please sign in to comment.
Something went wrong with that request. Please try again.