Re: Something missing from the clojure compiler's java annotation support for gen-class and defrecord? Am I driving while bouncing off the guard rails?
what about code using 1.2, and clojure-contrib, how to make transition. -- 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
Re: Something missing from the clojure compiler's java annotation support for gen-class and defrecord? Am I driving while bouncing off the guard rails?
I'm not sure deftype handles annotations on *parameters* of constructors. I'd be pleasantly surprised to be shown it does though. I think Stuart's workaround should work, though I think I might have to make my Java adaptor extend my Clojure gen-class rather than the other way around. On Sep 23, 3:42 pm, Tarantoga d.bushe...@gmail.com wrote: Deftype handles annotations and all the other features of java classes. Have a look here for an example:http://translate.google.com/translate?sl=autotl=enjs=nprev=_thl=e... On Sep 23, 10:11 pm, Warren Wood warrenthomasw...@yahoo.com wrote: Excellent, thanks! And thanks for sharing the taxi from Strange Loop to STL tuesday night! :) On Sep 23, 2:07 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: Hi Warren, Clojure doesn't try to be support every possible feature of Java when generating Java classes, it just provides enough for interop purposes. Annotations have always been a weak area. I don't know if annotations on constructor arguments in `gen-class` are supported, but my suspicion is they are not. A patch would be possible - the `gen-class` code is written mostly in Clojure. But the easier solution for now would be to write a small class in Java and `:extend` it in your gen-class. -Stuart Sierra clojure.com -- 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
Something missing from the clojure compiler's java annotation support for gen-class and defrecord? Am I driving while bouncing off the guard rails?
Ideally when generating a java class from Clojure for interop purposes, we should be able to generate any annotations that the equivalent java code could generate. Thus if a java class can annotate a constructor parameter, then gen-class and defrecord should be able to do that too. (I'm trying to interoperate with some Spring Framework stuff that expects to inject stuff into my class via an annotated constructor parameter. I'm trying to gradually introduce clojure code into the project starting with this one class that has that requirement. Maybe that's not a good idea to begin with, but I always find it very tempting. It's probably a case of driving while bouncing off the guard rails. :)) Did I put my constructor annotation in the wrong place in my example below? I also tried putting directly on the parameter of the -init function. If this is truly missing functionality, I may try to level up enough to patch the clojure compiler, send in a CA, submit a pull request... But I think I have a ways to go to level up my clojure to that level. Many thanks in advance for any insights/feedback from the wonderful clojure community. (ns com.warrenthomaswood.MyGenClass (:gen-class :methods [[foo [^{Deprecated true} String] void]] :init init :constructors {[^{Deprecated true} String] []})) (defn -init [word] (println word)) (defn -foo [this word] (println word)) ;;; given the above clojure-generated class MyGenClass, and a plain java class MyClass with a ;;; constructor parameter annotation as follows: package com.warrenthomaswood; public class MyClass { public MyClass(@Deprecated String s) { } } ;;; when I try to retrieve the annotations in a JUnit test, I can retrieve the method parameter ;;; annotation from the clojure generated class using MyGenClass.class.getMethods() and then calling ;;; getAnnotations() on the method. ;;; I can retrieve the constructor parameter annotation from the java generated class using ;;; MyClass.class.getConstructors() and then calling getAnnotations on the constructor ;;; but the clojure compiler does not seem to have a way of getting the constructor parameter ;;; annotation into the byte code. I can get annotations on the whole constructor I think, but ;;; not on the individual parameters of the construct. -- 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
Re: Something missing from the clojure compiler's java annotation support for gen-class and defrecord? Am I driving while bouncing off the guard rails?
Hi Warren, Clojure doesn't try to be support every possible feature of Java when generating Java classes, it just provides enough for interop purposes. Annotations have always been a weak area. I don't know if annotations on constructor arguments in `gen-class` are supported, but my suspicion is they are not. A patch would be possible - the `gen-class` code is written mostly in Clojure. But the easier solution for now would be to write a small class in Java and `:extend` it in your gen-class. -Stuart Sierra clojure.com -- 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
Re: Something missing from the clojure compiler's java annotation support for gen-class and defrecord? Am I driving while bouncing off the guard rails?
Excellent, thanks! And thanks for sharing the taxi from Strange Loop to STL tuesday night! :) On Sep 23, 2:07 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: Hi Warren, Clojure doesn't try to be support every possible feature of Java when generating Java classes, it just provides enough for interop purposes. Annotations have always been a weak area. I don't know if annotations on constructor arguments in `gen-class` are supported, but my suspicion is they are not. A patch would be possible - the `gen-class` code is written mostly in Clojure. But the easier solution for now would be to write a small class in Java and `:extend` it in your gen-class. -Stuart Sierra clojure.com -- 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
Re: Something missing from the clojure compiler's java annotation support for gen-class and defrecord? Am I driving while bouncing off the guard rails?
Deftype handles annotations and all the other features of java classes. Have a look here for an example: http://translate.google.com/translate?sl=autotl=enjs=nprev=_thl=enie=UTF-8layout=2eotf=1u=http%3A%2F%2Fmy-clojure.blogspot.com%2F2011%2F06%2Fweb-clojure.html On Sep 23, 10:11 pm, Warren Wood warrenthomasw...@yahoo.com wrote: Excellent, thanks! And thanks for sharing the taxi from Strange Loop to STL tuesday night! :) On Sep 23, 2:07 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: Hi Warren, Clojure doesn't try to be support every possible feature of Java when generating Java classes, it just provides enough for interop purposes. Annotations have always been a weak area. I don't know if annotations on constructor arguments in `gen-class` are supported, but my suspicion is they are not. A patch would be possible - the `gen-class` code is written mostly in Clojure. But the easier solution for now would be to write a small class in Java and `:extend` it in your gen-class. -Stuart Sierra clojure.com -- 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