aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/java_utils.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/clojure/contrib/java_utils.clj')
-rw-r--r--src/clojure/contrib/java_utils.clj17
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)))