On Mon, Jan 19, 2009 at 1:09 PM, Stuart Sierra
<the.stuart.sie...@gmail.com> wrote:
>
> On Jan 19, 11:59 am, Chouser <chou...@gmail.com> wrote:
>> But my version also only allows matches on the method name (not on
>> return value or argument class names).  At first I thought this was
>> also good, but now I'm less sure.  How often do you think you'd want
>> to be able to search on a method's argument names, vs. how many
>> unhelpful matches you'd get doing (show String "string") ?  Opintions?
>
>  Would it be possible to separate "show" into two functions, one of
> which returns a sequence of method signatures and another which prints
> them?  Then you could filter the sequence however you like.

As of SVN 397, show accepts a string, regex, or predicate in addition
to still accepting a number for its second arg.  The number works as
before, returning the member object itself.

A string or regex will act as a case-insensitive filter on the name of
the member:

user=> (show Thread "stop") ; all members named "stop"
===  public java.lang.Thread  ===
[54] stop : void ()
[55] stop : void (Throwable)
nil

user=> (show Thread #"^\w{5}$") ; all members with 5-letter names
===  public java.lang.Thread  ===
[12] static sleep : void (long)
[13] static sleep : void (long,int)
[14] static yield : void ()
[29] getId : long ()
[53] start : void ()
nil

I find it very unlikely that anyone would bother being any more
specific than this.  But just in case, you can also provide a
predicate function:

; all methods that take exactly two ints
user=> (show Integer #(re-seq #"\(int,int\)" (:text %)))
===  public final java.lang.Integer  ===
[17] static rotateLeft : int (int,int)
[18] static rotateRight : int (int,int)
[24] static toString : String (int,int)
nil

The predicate takes a map based on the 'bean' of the member object,
but with :text and :member keys added.  The :text is what will be
printed, the :member is the original member object itself. It ends up
looking like this:

{:name "intValue",
 :text "intValue : int ()",
 :class java.lang.reflect.Method,
 :member #<Method public int java.lang.Integer.intValue()>,
 :returnType int,
 :accessible false,
 :annotations #<Annotation[] [Ljava.lang.annotation.Annotation;@46d228>,
 :bridge false,
 :declaredAnnotations #<Annotation[] [Ljava.lang.annotation.Annotation;@46d228>,
 :declaringClass java.lang.Integer,
 :defaultValue nil,
 :exceptionTypes #<Class[] [Ljava.lang.Class;@182ef6b>,
 :genericExceptionTypes #<Class[] [Ljava.lang.Class;@1980630>,
 :genericParameterTypes #<Class[] [Ljava.lang.Class;@e34726>,
 :genericReturnType int,
 :modifiers 1,
 :parameterAnnotations #<Annotation[][]
[[Ljava.lang.annotation.Annotation;@e99681>,
 :parameterTypes #<Class[] [Ljava.lang.Class;@1d32e45>,
 :sort-val [true true "intValue : int ()0000"],
 :synthetic false,
 :typeParameters #<TypeVariable[] [Ljava.lang.reflect.TypeVariable;@1e12f6d>,
 :varArgs false}

Thank you all for you input.
--Chouser

--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to