summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-03-01 22:02:10 +0000
committerRich Hickey <richhickey@gmail.com>2008-03-01 22:02:10 +0000
commiteef883786dee479c4c2e30c950527e91221da309 (patch)
treeaa67f9d1b558743ae96d878bb4499e3edda0f88b /src
parent80163d0baf5ad3ce8ab5b52342bab22c869e9d91 (diff)
doc reformatting
Diffstat (limited to 'src')
-rw-r--r--src/proxy.clj67
-rw-r--r--src/zip.clj58
2 files changed, 84 insertions, 41 deletions
diff --git a/src/proxy.clj b/src/proxy.clj
index 61cb27d4..33b8e5f2 100644
--- a/src/proxy.clj
+++ b/src/proxy.clj
@@ -16,9 +16,12 @@
(def *proxy-classes* (ref {}))
(defn
- #^{:doc "Takes an optional single class followed by zero or more interfaces. If not supplied class defaults to Object.
- Creates an returns an instance of a proxy class derived from the supplied classes. The resulting value is
- cached and used for any subsequent requests for the same class set. Returns a Class object."}
+ #^{:doc "Takes an optional single class followed by zero or more
+ interfaces. If not supplied class defaults to Object.
+ Creates an returns an instance of a proxy class derived
+ from the supplied classes. The resulting value is cached
+ and used for any subsequent requests for the same class
+ set. Returns a Class object."}
get-proxy-class [& bases]
(let [bases (if (. (first bases) (isInterface))
(cons Object bases)
@@ -182,17 +185,22 @@ get-proxy-class [& bases]
c)))))
(defn
- #^{:doc "Takes a proxy class and any arguments for its superclass ctor and creates and returns an instance
- of the proxy."}
+ #^{:doc "Takes a proxy class and any arguments for its superclass ctor
+ and creates and returns an instance of the proxy."}
construct-proxy [c & ctor-args]
(. Reflector (invokeConstructor c (to-array ctor-args))))
(defn
- #^{:doc "Takes a proxy instance and a map of symbols (whose names must correspond to methods of the proxy
- superclass/superinterfaces) to fns (which must take arguments matching the corresponding method, plus an
- additional (explicit) first arg corresponding to this, and updates (via assoc) the proxy's fn map. nil can be
- passed instead of a fn, in which case the corresponding method will revert to the default behavior. Note that this
- function can be used to update the behavior of an existing instance without changing its identity."}
+ #^{:doc "Takes a proxy instance and a map of symbols (whose names must
+ correspond to methods of the proxy
+ superclass/superinterfaces) to fns (which must take
+ arguments matching the corresponding method, plus an
+ additional (explicit) first arg corresponding to this, and
+ updates (via assoc) the proxy's fn map. nil can be passed
+ instead of a fn, in which case the corresponding method
+ will revert to the default behavior. Note that this
+ function can be used to update the behavior of an existing
+ instance without changing its identity."}
update-proxy [#^IProxy proxy mappings]
(. proxy (__updateClojureFnMappings mappings)))
@@ -203,16 +211,30 @@ proxy-mappings [#^IProxy proxy]
(defmacro
#^{:doc "class-and-interfaces - a vector of class names
- args - a (possibly empty) vector of arguments to the superclass constructor.
- f => (name [params*] body) or (name ([params*] body) ([params+] body) ...)
- Expands to code which creates a instance of a proxy class that implements the named class/interface(s)
- by calling the supplied fns. A single class, if provided, must be first. If not provided it defaults to Object.
- The interfaces names must be valid interface types. If a method fn is not provided for a class method, the
- superclass methd will be called. If a method fn is not provided for an interface method, an
- UnsupportedOperationException will be thrown should it be called. Method fns are closures and can capture
- the environment in which proxy is called. Each method fn takes an additional implicit first arg,
- which is bound to 'this. Note that while method fns can be provided to override protected methods,
- they have no other access to protected members, nor to super, as these capabilities cannot be proxied."}
+
+ args - a (possibly empty) vector of arguments to the
+ superclass constructor.
+
+ f => (name [params*] body) or
+ (name ([params*] body) ([params+] body) ...)
+
+ Expands to code which creates a instance of a proxy class
+ that implements the named class/interface(s) by calling
+ the supplied fns. A single class, if provided, must be
+ first. If not provided it defaults to Object.
+
+ The interfaces names must be valid interface types. If a
+ method fn is not provided for a class method, the
+ superclass methd will be called. If a method fn is not
+ provided for an interface method, an
+ UnsupportedOperationException will be thrown should it be
+ called. Method fns are closures and can capture the
+ environment in which proxy is called. Each method fn takes
+ an additional implicit first arg, which is bound to
+ 'this. Note that while method fns can be provided to
+ override protected methods, they have no other access to
+ protected members, nor to super, as these capabilities
+ cannot be proxied."}
proxy [class-and-interfaces args & fs]
`(let [pc# (get-proxy-class ~@class-and-interfaces)
p# (construct-proxy pc# ~@args)]
@@ -233,8 +255,9 @@ proxy [class-and-interfaces args & fs]
(defn
- #^{:doc "Takes a Java object and returns a read-only implementation of the map abstraction based
- upon its JavaBean properties."}
+ #^{:doc "Takes a Java object and returns a read-only
+ implementation of the map abstraction based upon its
+ JavaBean properties."}
bean [#^Object x]
(let [c (. x (getClass))
pmap (reduce (fn [m #^java.beans.PropertyDescriptor pd]
diff --git a/src/zip.clj b/src/zip.clj
index f661edbe..f9e66075 100644
--- a/src/zip.clj
+++ b/src/zip.clj
@@ -14,10 +14,16 @@
(defn
#^{:doc "Creates a new zipper structure.
- branch? is a fn that, given a node, returns true if can have children, even if it currently doesn't.
- children is a fn that, given a branch node, returns a seq of its children.
- make-node is a fn that, given an existing node and a seq of children, returns a new branch node with the supplied children.
- root is the root node."}
+
+ branch? is a fn that, given a node, returns true if can
+ have children, even if it currently doesn't.
+
+ children is a fn that, given a branch node, returns a seq
+ of its children.
+
+ make-node is a fn that, given an existing node and a seq
+ of children, returns a new branch node with the supplied
+ children. root is the root node."}
zipper [branch? children make-node root]
#^{:zip/branch? branch? :zip/children children :zip/make-node make-node} [root nil])
@@ -32,7 +38,8 @@ vector-zip [root]
(zipper vector? seq (fn [node children] (apply vector children)) root))
(defn
- #^{:doc "Returns a zipper for xml elements (as from xml/parse), given a root element"}
+ #^{:doc "Returns a zipper for xml elements (as from xml/parse),
+ given a root element"}
xml-zip [root]
(zipper (complement string?)
(comp seq :content)
@@ -51,12 +58,14 @@ branch? [loc]
((:zip/branch? ^loc) (node loc)))
(defn
- #^{:doc "Returns a seq of the children of node at loc, which must be a branch"}
+ #^{:doc "Returns a seq of the children of node at loc,
+ which must be a branch"}
children [loc]
((:zip/children ^loc) (node loc)))
(defn
- #^{:doc "Returns a new branch node, given an existing node and new children. The loc is only used to supply the constructor."}
+ #^{:doc "Returns a new branch node, given an existing node and new
+ children. The loc is only used to supply the constructor."}
make-node [loc node children]
((:zip/make-node ^loc) node children))
@@ -77,7 +86,8 @@ rights [loc]
(defn
- #^{:doc "Returns the loc of the leftmost child of the node at this loc, or nil if no children"}
+ #^{:doc "Returns the loc of the leftmost child of the node
+ at this loc, or nil if no children"}
down [loc]
(let [[node path] loc
[c & crest :as cs] (children loc)]
@@ -88,7 +98,8 @@ down [loc]
:r crest}] ^loc))))
(defn
- #^{:doc "Returns the loc of the parent of the node at this loc, or nil if at the top"}
+ #^{:doc "Returns the loc of the parent of the node at this loc, or nil
+ if at the top"}
up [loc]
(let [[node {l :l, ppath :ppath, pnodes :pnodes r :r, changed? :changed?, :as path}] loc]
(when path
@@ -100,7 +111,8 @@ up [loc]
^loc)))))
(defn
- #^{:doc "zips all the way up and returns the root node, reflecting any changes."}
+ #^{:doc "zips all the way up and returns the root node,
+ reflecting any changes."}
root [loc]
(if (= :end (loc 1))
(node loc)
@@ -110,21 +122,24 @@ root [loc]
(node loc)))))
(defn
- #^{:doc "Returns the loc of the right sibling of the node at this loc, or nil"}
+ #^{:doc "Returns the loc of the right sibling of the node at this loc,
+ or nil"}
right [loc]
(let [[node {l :l [r & rrest :as rs] :r :as path}] loc]
(when (and path rs)
(with-meta [r (assoc path :l (conj l node) :r rrest)] ^loc))))
(defn
- #^{:doc "Returns the loc of the left sibling of the node at this loc, or nil"}
+ #^{:doc "Returns the loc of the left sibling of the node at this loc, or
+ nil"}
left [loc]
(let [[node {l :l r :r :as path}] loc]
(when (and path (seq l))
(with-meta [(peek l) (assoc path :l (pop l) :r (cons node r))] ^loc))))
(defn
- #^{:doc "Inserts the item as the left sibling of the node at this loc, without moving"}
+ #^{:doc "Inserts the item as the left sibling of the node at this loc,
+ without moving"}
insert-left [loc item]
(let [[node {l :l :as path}] loc]
(if (nil? path)
@@ -132,7 +147,8 @@ insert-left [loc item]
(with-meta [node (assoc path :l (conj l item) :changed? true)] ^loc))))
(defn
- #^{:doc "Inserts the item as the right sibling of the node at this loc, without moving"}
+ #^{:doc "Inserts the item as the right sibling of the node at this loc,
+ without moving"}
insert-right [loc item]
(let [[node {r :r :as path}] loc]
(if (nil? path)
@@ -151,18 +167,21 @@ edit [loc f & args]
(replace loc (apply f (node loc) args)))
(defn
- #^{:doc "Inserts the item as the leftmost child of the node at this loc, without moving"}
+ #^{:doc "Inserts the item as the leftmost child of the node at this loc,
+ without moving"}
insert-child [loc item]
(replace loc (make-node loc (node loc) (cons item (children loc)))))
(defn
- #^{:doc "Inserts the item as the rightmost child of the node at this loc, without moving"}
+ #^{:doc "Inserts the item as the rightmost child of the node at this
+ loc, without moving"}
append-child [loc item]
(replace loc (make-node loc (node loc) (concat (children loc) [item]))))
(defn
- #^{:doc "Moves to the next loc in the hierarchy, depth-first. When reaching the end,
-returns a distinguished loc detectable via end?. If already at the end, stays there."}
+ #^{:doc "Moves to the next loc in the hierarchy, depth-first. When
+ reaching the end, returns a distinguished loc detectable
+ via end?. If already at the end, stays there."}
next [loc]
(if (= :end (loc 1))
loc
@@ -180,7 +199,8 @@ end? [loc]
(= :end (loc 1)))
(defn
- #^{:doc "Removes the node at loc, returning the loc that would have preceded it in a depth-first walk."}
+ #^{:doc "Removes the node at loc, returning the loc that would have
+ preceded it in a depth-first walk."}
remove [loc]
(let [[node {l :l, ppath :ppath, pnodes :pnodes, rs :r, :as path}] loc]
(if (nil? path)