diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2010-02-03 12:20:07 -0500 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2010-02-11 16:05:44 -0500 |
commit | 91582e13e7b93b23fb53f821caa73fd23368d551 (patch) | |
tree | 895490b687ce4ac89940876b4669406506bcb4b6 | |
parent | 7a0e744c9f40280f1f28619102fe9f7dfb05401a (diff) |
Add c.c.reflect, taking 2 functions from c.c.java
-rw-r--r-- | src/main/clojure/clojure/contrib/reflect.clj | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main/clojure/clojure/contrib/reflect.clj b/src/main/clojure/clojure/contrib/reflect.clj new file mode 100644 index 00000000..8d254c31 --- /dev/null +++ b/src/main/clojure/clojure/contrib/reflect.clj @@ -0,0 +1,33 @@ +; Copyright (c) 2010 Stuart Halloway & Contributors. All rights +; reserved. The use and distribution terms for this software are +; covered by the Eclipse Public License 1.0 +; (http://opensource.org/licenses/eclipse-1.0.php) which can be +; found in the file epl-v10.html at the root of this distribution. +; By using this software in any fashion, you are agreeing to be +; bound by the terms of this license. You must not remove this +; notice, or any other, from this software. + +(ns clojure.contrib.reflect) + +(defn call-method + "Calls a private or protected method. + + params is a vector of classes which correspond to the arguments to + the method e + + obj is nil for static methods, the instance object otherwise. + + The method-name is given a symbol or a keyword (something Named)." + [klass method-name params obj & args] + (-> klass (.getDeclaredMethod (name method-name) + (into-array Class params)) + (doto (.setAccessible true)) + (.invoke obj (into-array Object args)))) + +(defn get-field + "Access to private or protected field. field-name is a symbol or + keyword." + [klass field-name obj] + (-> klass (.getDeclaredField (name field-name)) + (doto (.setAccessible true)) + (.get obj))) |