Mercurial > lasercutter
annotate src/clojure/contrib/reflect.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
rev | line source |
---|---|
rlm@10 | 1 ; Copyright (c) 2010 Stuart Halloway & Contributors. All rights |
rlm@10 | 2 ; reserved. The use and distribution terms for this software are |
rlm@10 | 3 ; covered by the Eclipse Public License 1.0 |
rlm@10 | 4 ; (http://opensource.org/licenses/eclipse-1.0.php) which can be |
rlm@10 | 5 ; found in the file epl-v10.html at the root of this distribution. |
rlm@10 | 6 ; By using this software in any fashion, you are agreeing to be |
rlm@10 | 7 ; bound by the terms of this license. You must not remove this |
rlm@10 | 8 ; notice, or any other, from this software. |
rlm@10 | 9 |
rlm@10 | 10 (ns clojure.contrib.reflect) |
rlm@10 | 11 |
rlm@10 | 12 (defn call-method |
rlm@10 | 13 "Calls a private or protected method. |
rlm@10 | 14 |
rlm@10 | 15 params is a vector of classes which correspond to the arguments to |
rlm@10 | 16 the method e |
rlm@10 | 17 |
rlm@10 | 18 obj is nil for static methods, the instance object otherwise. |
rlm@10 | 19 |
rlm@10 | 20 The method-name is given a symbol or a keyword (something Named)." |
rlm@10 | 21 [klass method-name params obj & args] |
rlm@10 | 22 (-> klass (.getDeclaredMethod (name method-name) |
rlm@10 | 23 (into-array Class params)) |
rlm@10 | 24 (doto (.setAccessible true)) |
rlm@10 | 25 (.invoke obj (into-array Object args)))) |
rlm@10 | 26 |
rlm@10 | 27 (defn get-field |
rlm@10 | 28 "Access to private or protected field. field-name is a symbol or |
rlm@10 | 29 keyword." |
rlm@10 | 30 [klass field-name obj] |
rlm@10 | 31 (-> klass (.getDeclaredField (name field-name)) |
rlm@10 | 32 (doto (.setAccessible true)) |
rlm@10 | 33 (.get obj))) |