diff options
author | Daniel Solano Gómez <clojure@sattvik.com> | 2010-04-27 11:12:51 -0500 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-05-07 18:45:05 -0400 |
commit | 8b1ea574a61b105b9cbe9ffa3b05785cec0b3bc0 (patch) | |
tree | 333801b218fb2ba2e9efeb252d7e44d90956bbe9 /src | |
parent | 40f3dc93b926721e94b75a10a9c88815ea4691aa (diff) |
Add annotations support to gen-class, plus tests. See #318.
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/clj/clojure/genclass.clj | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/clj/clojure/genclass.clj b/src/clj/clojure/genclass.clj index 35cbf21d..fbc7dfe8 100644 --- a/src/clj/clojure/genclass.clj +++ b/src/clj/clojure/genclass.clj @@ -95,6 +95,7 @@ {:keys [name extends implements constructors methods main factory state init exposes exposes-methods prefix load-impl-ns impl-ns post-init]} (merge default-options options-map) + name-meta (meta name) name (str name) super (if extends (the-class extends) Object) interfaces (map the-class implements) @@ -157,8 +158,10 @@ impl-pkg-name "/" prefix (.getName m) " not defined?)")))) emit-forwarding-method - (fn [mname pclasses rclass as-static else-gen] - (let [pclasses (map the-class pclasses) + (fn [name pclasses rclass as-static else-gen] + (let [mname (str name) + pmetas (map meta pclasses) + pclasses (map the-class pclasses) rclass (the-class rclass) ptypes (to-types pclasses) rtype ^Type (totype rclass) @@ -169,6 +172,9 @@ found-label (. gen (newLabel)) else-label (. gen (newLabel)) end-label (. gen (newLabel))] + (add-annotations gen (meta name)) + (dotimes [i (count pmetas)] + (add-annotations gen (nth pmetas i) i)) (. gen (visitCode)) (if (> (count pclasses) 18) (else-gen gen m) @@ -219,6 +225,9 @@ cname nil (iname super) (when-let [ifc (seq interfaces)] (into-array (map iname ifc))))) + + ; class annotations + (add-annotations cv name-meta) ;static fields for vars (doseq [v var-fields] @@ -381,7 +390,7 @@ mm (mapcat #(.getMethods ^Class %) interfaces)) ;extra methods (doseq [[mname pclasses rclass :as msig] methods] - (emit-forwarding-method (str mname) pclasses rclass (:static (meta msig)) + (emit-forwarding-method mname pclasses rclass (:static (meta msig)) emit-unsupported)) ;expose specified overridden superclass methods (doseq [[local-mname ^java.lang.reflect.Method m] (reduce (fn [ms [[name _ _] m]] |