diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-04-12 13:26:23 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-04-12 13:26:23 +0000 |
commit | 166982205692046dae7d14200d85bfeb80e6517c (patch) | |
tree | 32e9d0cfce9967925ff085e3da73b0df742f4ff4 | |
parent | 2d6dc41d0f5985b278969131edbce4703d674a8f (diff) |
:exposes should expose static fields as static methods [issue 2], patch from Chouser
-rw-r--r-- | src/clj/clojure/genclass.clj | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/clj/clojure/genclass.clj b/src/clj/clojure/genclass.clj index 0452e04c..57c7140c 100644 --- a/src/clj/clojure/genclass.clj +++ b/src/clj/clojure/genclass.clj @@ -405,22 +405,32 @@ ;field exposers (doseq [[f {getter :get setter :set}] exposes] (let [fld (find-field super (str f)) - ftype (totype (.getType fld))] + ftype (totype (.getType fld)) + static? (Modifier/isStatic (.getModifiers fld)) + acc (+ Opcodes/ACC_PUBLIC (if static? Opcodes/ACC_STATIC 0))] (when getter (let [m (new Method (str getter) ftype (to-types [])) - gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)] + gen (new GeneratorAdapter acc m nil nil cv)] (. gen (visitCode)) - (. gen loadThis) - (. gen getField ctype (str f) ftype) + (if static? + (. gen getStatic ctype (str f) ftype) + (do + (. gen loadThis) + (. gen getField ctype (str f) ftype))) (. gen (returnValue)) (. gen (endMethod)))) (when setter - (let [m (new Method (str setter) (. Type VOID_TYPE) (into-array [ftype])) - gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)] + (let [m (new Method (str setter) Type/VOID_TYPE (into-array [ftype])) + gen (new GeneratorAdapter acc m nil nil cv)] (. gen (visitCode)) - (. gen loadThis) - (. gen loadArgs) - (. gen putField ctype (str f) ftype) + (if static? + (do + (. gen loadArgs) + (. gen putStatic ctype (str f) ftype)) + (do + (. gen loadThis) + (. gen loadArgs) + (. gen putField ctype (str f) ftype))) (. gen (returnValue)) (. gen (endMethod)))))) ;finish class def |