aboutsummaryrefslogtreecommitdiff
path: root/modules/reflect
diff options
context:
space:
mode:
Diffstat (limited to 'modules/reflect')
-rw-r--r--modules/reflect/pom.xml16
-rw-r--r--modules/reflect/src/main/clojure/clojure/contrib/reflect.clj33
2 files changed, 49 insertions, 0 deletions
diff --git a/modules/reflect/pom.xml b/modules/reflect/pom.xml
new file mode 100644
index 00000000..a936806a
--- /dev/null
+++ b/modules/reflect/pom.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http//www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.clojure.contrib</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ <relativePath>../parent</relativePath>
+ </parent>
+ <artifactId>reflect</artifactId>
+ <dependencies>
+ </dependencies>
+</project> \ No newline at end of file
diff --git a/modules/reflect/src/main/clojure/clojure/contrib/reflect.clj b/modules/reflect/src/main/clojure/clojure/contrib/reflect.clj
new file mode 100644
index 00000000..8d254c31
--- /dev/null
+++ b/modules/reflect/src/main/clojure/clojure/contrib/reflect.clj
@@ -0,0 +1,33 @@
+; Copyright (c) 2010 Stuart Halloway & Contributors. All rights
+; reserved. The use and distribution terms for this software are
+; covered by the Eclipse Public License 1.0
+; (http://opensource.org/licenses/eclipse-1.0.php) which can be
+; found in the file epl-v10.html at the root of this distribution.
+; By using this software in any fashion, you are agreeing to be
+; bound by the terms of this license. You must not remove this
+; notice, or any other, from this software.
+
+(ns clojure.contrib.reflect)
+
+(defn call-method
+ "Calls a private or protected method.
+
+ params is a vector of classes which correspond to the arguments to
+ the method e
+
+ obj is nil for static methods, the instance object otherwise.
+
+ The method-name is given a symbol or a keyword (something Named)."
+ [klass method-name params obj & args]
+ (-> klass (.getDeclaredMethod (name method-name)
+ (into-array Class params))
+ (doto (.setAccessible true))
+ (.invoke obj (into-array Object args))))
+
+(defn get-field
+ "Access to private or protected field. field-name is a symbol or
+ keyword."
+ [klass field-name obj]
+ (-> klass (.getDeclaredField (name field-name))
+ (doto (.setAccessible true))
+ (.get obj)))