Mercurial > lasercutter
comparison 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 |
comparison
equal
deleted
inserted
replaced
9:35cf337adfcf | 10:ef7dbbd6452c |
---|---|
1 ; Copyright (c) 2010 Stuart Halloway & Contributors. All rights | |
2 ; reserved. The use and distribution terms for this software are | |
3 ; covered by the Eclipse Public License 1.0 | |
4 ; (http://opensource.org/licenses/eclipse-1.0.php) which can be | |
5 ; 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 be | |
7 ; bound by the terms of this license. You must not remove this | |
8 ; notice, or any other, from this software. | |
9 | |
10 (ns clojure.contrib.reflect) | |
11 | |
12 (defn call-method | |
13 "Calls a private or protected method. | |
14 | |
15 params is a vector of classes which correspond to the arguments to | |
16 the method e | |
17 | |
18 obj is nil for static methods, the instance object otherwise. | |
19 | |
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)))) | |
26 | |
27 (defn get-field | |
28 "Access to private or protected field. field-name is a symbol or | |
29 keyword." | |
30 [klass field-name obj] | |
31 (-> klass (.getDeclaredField (name field-name)) | |
32 (doto (.setAccessible true)) | |
33 (.get obj))) |