I am trying to write a clojure macro that will be used to create several Java classes at compile time. I found that I can add annotations to the class when I call the gen class outside of the macro. However, when I try to use a gen class inside a macro, the compiled class has no annotations.
I threw my problem back to this example:
(gen-class
:name ^{Deprecated true} Test1
:prefix Test1-
:methods [[^{Deprecated true} getValue [] Integer]])
(defn Test1-getValue [] 42)
(defmacro create-test-class [name x]
(let [prefix (str name "-")]
`(do
(gen-class
:name ~(with-meta name {Deprecated true})
:prefix ~(symbol prefix)
:methods [[~(with-meta 'getValue {Deprecated true}) [] Integer]])
(defn ~(symbol (str prefix "getValue")) [] ~x))))
(create-test-class Test2 56)
When I compile this file, it creates Test1.class and Test2.class - I check both with Eclipse and find that Test1 has both class level annotations and @Deprecated method level, but Test2.class which has no annotations. When I use macroexpand, it seems to me that my Test2.class should be annotated:
user=> (set! *print-meta* true)
true
user=> (macroexpand '(create-test-class Test2 56))
(do (clojure.core/gen-class :name ^{java.lang.Deprecated true} Test2 :prefix Test2- :methods [[^{java.lang.Deprecated true} getValue [] java.lang.Integer]]) (user/defn Test2-getValue [] 56))
What am I doing wrong here?