Mercurial > lasercutter
view 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 |
line wrap: on
line source
1 ; Copyright (c) 2010 Stuart Halloway & Contributors. All rights2 ; reserved. The use and distribution terms for this software are3 ; covered by the Eclipse Public License 1.04 ; (http://opensource.org/licenses/eclipse-1.0.php) which can be5 ; found in the file epl-v10.html at the root of this distribution.6 ; By using this software in any fashion, you are agreeing to be7 ; bound by the terms of this license. You must not remove this8 ; notice, or any other, from this software.10 (ns clojure.contrib.reflect)12 (defn call-method13 "Calls a private or protected method.15 params is a vector of classes which correspond to the arguments to16 the method e18 obj is nil for static methods, the instance object otherwise.20 The method-name is given a symbol or a keyword (something Named)."21 [klass method-name params obj & args]22 (-> klass (.getDeclaredMethod (name method-name)23 (into-array Class params))24 (doto (.setAccessible true))25 (.invoke obj (into-array Object args))))27 (defn get-field28 "Access to private or protected field. field-name is a symbol or29 keyword."30 [klass field-name obj]31 (-> klass (.getDeclaredField (name field-name))32 (doto (.setAccessible true))33 (.get obj)))