diff options
author | Kevin Downey <redchin@gmail.com> | 2009-11-06 22:14:59 -0800 |
---|---|---|
committer | Chouser <chouser@n01se.net> | 2009-11-07 01:21:20 -0500 |
commit | cc4e2ec2bf558f059330ebc97a031d7806a1e364 (patch) | |
tree | 48d33493a001e90645cd93fb60b2f645ce09b8bd /src/clojure/contrib/java_utils.clj | |
parent | 12e935b5ed1d462a4a48f647e17315a0bb25b48b (diff) |
add wall-hack-method and wall-hack-field. fixes #43
Signed-off-by: Chouser <chouser@n01se.net>
Diffstat (limited to 'src/clojure/contrib/java_utils.clj')
-rw-r--r-- | src/clojure/contrib/java_utils.clj | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/clojure/contrib/java_utils.clj b/src/clojure/contrib/java_utils.clj index 7af4bc93..e8d93782 100644 --- a/src/clojure/contrib/java_utils.clj +++ b/src/clojure/contrib/java_utils.clj @@ -204,3 +204,20 @@ Raise an exception if any deletion fails unless silently is true." (defmethod as-url String [#^String x] (URL. x)) (defmethod as-url File [#^File x] (.toURL x)) + +(defn wall-hack-method + "Calls a private or protected method. + params is a vector of class which correspond to the arguments to the method + obj is nil for static methods, the instance object otherwise + the method name is given as a symbol or a keyword (something Named)" + [class-name method-name params obj & args] + (-> class-name (.getDeclaredMethod (name method-name) (into-array Class params)) + (doto (.setAccessible true)) + (.invoke obj (into-array Object args)))) + +(defn wall-hack-field + "Access to private or protected field." + [class-name field-name obj] + (-> class-name (.getDeclaredField (name field-name)) + (doto (.setAccessible true)) + (.get obj))) |