Hi,
I'm new to Clojure. How can I add @ChannelPipelineCoverage("one")
annotation to a proxy as in?
http://viewvc.jboss.org/cgi-bin/viewvc.cgi/netty/trunk/src/main/java/org/jboss/netty/example/http/snoop/HttpResponseHandler.java?view=markup
I tried:
(def handler
(proxy [SimpleChannelUpstreamHandler] []
(messageReceived [ctx e]
((.println System/out) "hello"))))
(with-meta handler {:annotations ["ChannelPipelineCoverage" "one"]})
But there is error:
Exception in thread "main" java.lang.ClassCastException:
clojure.proxy.org.jboss.netty.channel.SimpleChannelUpstreamHandler
cannot be cast to clojure.lang.IObj
Thanks.
---------- Forwarded message ----------
From: Matt Revelle <[email protected]>
Date: Mar 25, 1:15 am
Subject: Annotations and gen-class
To: Clojure
On Mar 24, 10:19 am, Sean <[email protected]> wrote:
> Some working code would make it a lot easier to understand *exactly*
> what you're looking for. Do you think you could post a few quick
> methods on github?
No need for gist, this will do as an example:
(ns some.namespace
(:gen-class
:methods [^#{:annotations [SomeAnnotation]} [aMethod [T] S]]
...)
This adds an annotation, SomeAnnotation, to the gen-class'd method,
aMethod.
> If memory serves, the reflections package should
> be a good place to start.
> However, you'd need to ask *why* you need this.
> If the answer is "I need to work with and modify a pre-existing, pre-
> tested, needs-to-stay-in-production application", then this is a great
> idea. Clojrue should help you glue your components together.
> If your answer is "I'm making a brand new application", or "This is
> for a side project", this might be a bad approach. Annotations
> generally are used to make up for a weakness in the Java language.
> Some Clojure language features could probably do the job better
> * Dynamic Typing
> * First class functions
> * Sequence functions. such as map/reduce/filter etc.
> * Macros
> Specifically, I think Guice (and other DI tools) should be avoided.
> They are the antithesis of functional programming, and first class
> functions will make your life much easier. Try re-thinking about a
> problem in a functional style. I'm willing to bet that you'll have a
> solution that is easier to write, easier to test, and will scale
> better.
You're preaching to the choir. The reasoning behind supporting
annotations in gen-class is the
same as providing gen-class in the first place. Generating classes
usable in Java code is
sometimes necessary and as gen-class' feature set becomes more
complete the better it serves users.
> On Mar 24, 9:57 am, Matt Revelle <[email protected]> wrote:
> > Support for using JVM annotations with Clojure code has come up
> > several times before,
> > I'd like a feature request issue to be created and to start discussing
> > the implementation.
> > It seems that an "annotations" metadata tag could contain all
> > annotations for an object,
> > and any annotations that persist to runtime would need bytecode
> > emitted. This appears straightforward,
> > but I wonder if there will be a problem using Method or Parameter
> > annotations.
> > The motivation for this is to support Java libraries which depend on
> > annotations at runtime for discovery and metadata persistence.
> > Being able to integrate a class generated by gen-class with, for
> > example, a Java project using Guice would be handy.
> > Thoughts?
> > -Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---