Skip to content

Commit 0f1954e

Browse files
committed
Add reflect from clojure 1.3 for 1.2.1 compatability
1 parent 67179d0 commit 0f1954e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/clj_ssh/reflect.clj

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
;;;; taken from clojure.contrib.reflect 1.2.0
2+
3+
;;; Copyright (c) 2010 Stuart Halloway & Contributors. All rights
4+
;;; reserved. The use and distribution terms for this software are
5+
;;; covered by the Eclipse Public License 1.0
6+
;;; (http://opensource.org/licenses/eclipse-1.0.php) which can be
7+
;;; found in the file epl-v10.html at the root of this distribution.
8+
;;; By using this software in any fashion, you are agreeing to be
9+
;;; bound by the terms of this license. You must not remove this
10+
;;; notice, or any other, from this software.
11+
12+
(ns clj-ssh.reflect)
13+
14+
(defn call-method
15+
"Calls a private or protected method.
16+
17+
params is a vector of classes which correspond to the arguments to
18+
the method e
19+
20+
obj is nil for static methods, the instance object otherwise.
21+
22+
The method-name is given a symbol or a keyword (something Named)."
23+
[klass method-name params obj & args]
24+
(-> klass (.getDeclaredMethod (name method-name)
25+
(into-array Class params))
26+
(doto (.setAccessible true))
27+
(.invoke obj (into-array Object args))))
28+
29+
(defn get-field
30+
"Access to private or protected field. field-name is a symbol or
31+
keyword."
32+
[klass field-name obj]
33+
(->
34+
klass
35+
(.getDeclaredField (name field-name))
36+
(doto (.setAccessible true))
37+
(.get obj)))

0 commit comments

Comments
 (0)