Hi Folks,

I'm attempting to write a clojure macro that uses gen-class to replace 
several manually written Java classes that all follow a similar pattern.

Yes, in my magic world of unicorns and mermaids, I would just rewrite them 
in pure clojure, but for the context of this question my solution has to 
generate Java classes (I can elaborate if anybody really wants to know).

The problem is that my macro is apparently unable to emit gen-class code 
that will include annotations in the class.  I've boiled my problem down 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 a Test1.class and Test2.class - I 
inspect both with Eclipse, and find that Test1 has both class-level and 
method-level @Deprecated annotations, but Test2.class has no annotations.  
When I use macroexpand, it looks as though 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)) 

Is there something wrong with the way that I attempt to attach the metadata?

Thanks!
Michael Willis

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to