std.object
class-convert
added in 3.0
(class-convert v)(class-convert v to)Converts a class to its representation.
(class-convert “byte”) => Byte/TYPE
(class-convert ’byte :string) => “byte”
(class-convert (Class/forName “[[B”) :string) => “byte[][]”
class-hierarchy
added in 3.0
(class-hierarchy obj)Lists the class and interface hierarchy for the class
(element/class-hierarchy String) => [java.lang.String java.lang.Object #{java.lang.CharSequence java.lang.constant.ConstantDesc java.lang.constant.Constable java.lang.Comparable java.io.Serializable}]
class-info
added in 3.0
(class-info obj)Lists class information
(element/class-info String) => (contains {:name “java.lang.String” :hash anything :modifiers #{:instance :class :public :final}})
constructor?
added in 3.0
(constructor? elem)checks if if an element is a constructor
(-> (.getConstructors String) (first) (element/to-element) (element/constructor?)) => true
context-class
added in 3.0
(context-class obj)If x is a class, return x otherwise return the class of x
(context-class String) => String
(context-class "") => String
delegate
added in 3.0
(delegate obj)Allow transparent field access and manipulation to the underlying object.
(def -a- “hello”) (def -*a- (delegate -a-)) (def -world-array- (.getBytes “world”))
(mapv char (-*a- :value)) => \h \e \l \l \o
(-*a- :value -world-array-) (String. ^bytes (-*a- :value)) => “world” -a- => “world”
element
added in 3.0
(element body)creates a element from a map
(element {}) => std.object.element.common.Element
element?
added in 3.0
(element? x)checker for the element type
(element? (element {})) => true
field?
added in 3.0
(field? elem)checks if an element is a field
(-> (.getFields String) (first) (element/to-element) (element/field?)) => true
from-data
added in 3.0
(from-data arg cls)get
added in 3.0
(get obj k)accessor with either keyword or array lookup
(access/get (test.Cat. “spike”) :name) => “spike”
get-in
added in 3.0
(get-in obj ks)accesses the nested object using specifiedb path
(access/get-in (test.Cat. “spike”) :name)
instance?
added in 3.0
(instance? elem)checks if an element is non static
(->> (.getMethods String) (map element/to-element) (filter element/instance?) first) ;;#elemequals :: (java.lang.String, java.lang.Object) -> boolean
keys
added in 3.0
(keys obj)gets all keys of an object
(access/keys (test.Cat. “spike”)) => (contains :name)
map-like
macro
added in 3.0
(map-like & {:as classes})creates an accessibility layer for map-like objects
(framework/map-like org.eclipse.jgit.revwalk.RevCommit {:tag “commit” :include :commit-time :name :author-ident :full-message})
(framework/map-like org.eclipse.jgit.lib.PersonIdent {:tag “person” :exclude :time-zone})
(framework/map-like org.eclipse.jgit.api.Status {:tag “status” :display (fn m (reduce-kv (fn out k v (if (and (or (instance? java.util.Collection v) (instance? java.util.Map v)) (empty? v)) out (assoc out k v))) {} m))})
meta-clear
added in 3.0
(meta-clear class)clears all meta-read and meta-write definitions for a class
meta-read
added in 3.0
(meta-read cls)access read attributes
(read/meta-read Pet) => (contains-in {:class test.Pet :methods {:name {:fn fn?} :species {:fn fn?}}})
meta-read-exact
added in 3.0
(meta-read-exact cls)access read attributes for the exact class
(read/meta-read-exact Object) => nil
meta-read-exact?
added in 3.0
(meta-read-exact? cls)checks if read attributes are avaliable
(read/meta-read-exact? Object) => false
meta-write
added in 3.0
(meta-write cls)access read-attributes with caching
(write/meta-write DogBuilder) => (contains-in {:class test.DogBuilder :empty fn?, :methods {:name {:type java.lang.String, :fn fn?}}})
meta-write-exact
added in 3.0
(meta-write-exact cls)access write attributes for the exact class
(write/meta-write-exact Object) => nil
meta-write-exact?
added in 3.0
(meta-write-exact? cls)checks if write attributes are avaliable
(write/meta-write-exact? Object) => false
method?
added in 3.0
(method? elem)checks if an element is a method
(-> (.getMethods String) (first) (element/to-element) (element/method?)) => true
private?
added in 3.0
(private? elem)checks if an element is private
(->> (.getDeclaredFields String) (map element/to-element) (filter element/private?) first) ;;#elem[value :: (java.lang.String) | byte[]]
public?
added in 3.0
(public? elem)checks if an element is public
(->> (.getMethods String) (map element/to-element) (filter element/public?) first) ;;#elemequals :: (java.lang.String, java.lang.Object) -> boolean
query-class
added in 3.0
(query-class obj selectors)queries the java view of the class declaration
(query-class String #“^c” :name) ;;=> “charAt” “checkBounds” “codePointAt” “codePointBefore” ;; “codePointCount” “compareTo” “compareToIgnoreCase” ;; “concat” “contains” “contentEquals” “copyValueOf”
query-hierarchy
added in 3.0
(query-hierarchy obj selectors)lists what methods could be applied to a particular instance
(query-hierarchy String :name #“^to”) => “toCharArray” “toLowerCase” “toString” “toUpperCase”
query-instance
added in 3.0
(query-instance obj selectors)lists what class methods could be applied to a particular instance
(query-instance “abc” :name #“^to”) => “toCharArray” “toLowerCase” “toString” “toUpperCase”
(query-instance String :name #“^to”) => (contains “toString”)
read-all-getters
macro
added in 3.0
(read-all-getters cls)(read-all-getters cls opts)returns fields of an object and base classes (-> (read/read-all-getters Dog) keys) => :class :name :species
read-ex
added in 3.0
(read-ex k)creates a getter method that throws an an exception
((read/read-ex :hello) nil) => (throws)
read-fields
added in 3.0
(read-fields cls)(read-fields cls query-fn)fields of an object from reflection (-> (read/read-fields Dog) keys) => :name :species
read-getters
macro
added in 3.0
(read-getters cls)(read-getters cls opts)(read-getters cls opts query-fn)returns fields of an object through getter methods (-> (read/read-getters Dog) keys) => :name :species
read-getters-form
added in 3.0
(read-getters-form cls)(read-getters-form cls opts)(read-getters-form cls {:keys [prefix template extra], :as opts} query-fn)set
added in 3.0
(set obj m)(set obj k v)sets the fields of an object with a map
(-> (doto (test.Cat. “spike”) (access/set {:name “fluffy”})) (access/get :name)) => (any “fluffy” (throws))
static?
added in 3.0
(static? elem)checks if an element is a static one
(->> (.getMethods String) (map element/to-element) (filter element/static?) first) ;;#elemvalueOf :: (int) -> java.lang.String
string-like
macro
added in 3.0
(string-like & {:as classes})creates an accessibility layer for string-like objects
(framework/string-like java.io.File {:tag “path” :read (fn ^java.io.File f(.getPath f)) :write (fn ^String path(java.io.File. path))})
(object/to-data (java.io.File. “/home”)) => “/home”
(object/from-data “/home” java.io.File) => java.io.File
;; Enums are automatically string-like
(object/to-data java.lang.Thread$State/NEW) => “NEW”
struct-accessor
added in 3.0
(struct-accessor spec)(struct-accessor spec access)creates an accessor function
((struct-accessor {:value :data :msg :detail-message :value} :field) (ex-info “hello” {:a 1})) => (contains {:value {:a 1}, :msg bytes?})
struct-fields
added in 3.0
(struct-fields spec obj)creates a struct given an object and a field map
(struct-fields {:depth []} (ex-info “hello” {:a 1})) => (contains {:depth number?})
(struct-fields {:msg :detail-message :value} (ex-info “hello” {:a 1})) => (contains {:msg bytes?})
struct-getters
added in 3.0
(struct-getters spec obj)creates a struct given an object and a getter map
(struct-getters {:value :data :message [] :class {:name []}} (ex-info “hello” {:a 1})) => {:value {:a 1}, :message “hello”, :class {:name “clojure.lang.ExceptionInfo”}}
to-data
added in 3.0
(to-data obj)creates the object from a string or map
(read/to-data “hello”) => “hello”
(read/to-data (write/from-map {:name “hello” :species “dog”} Pet)) => (contains {:name “hello”})
to-element
added in 3.0
(to-element obj)converts a java.reflect object to a std.object.element one
(element/to-element (first (.getMethods String))) ;; #elemequals :: (java.lang.String, java.lang.Object) -> boolean
to-map
added in 3.0
(to-map obj)creates a map from an object
(read/to-map (Cat. “spike”)) => (contains {:name “spike”})
unextend
added in 3.0
(unextend cls)vector-like
macro
added in 3.0
(vector-like & {:as classes})creates an accessibility layer for vector-like objects
(framework/vector-like org.eclipse.jgit.revwalk.RevWalk {:tag “commits” :read (fn ^org.eclipse.jgit.revwalk.RevWalk walk (->> walk (.iterator) object/to-data))})
write-all-setters
macro
added in 3.0
(write-all-setters cls)(write-all-setters cls opts)write all setters of an object and base classes
(write/write-all-setters Dog) => {}
(keys (write/write-all-setters DogBuilder)) => :name
write-ex
added in 3.0
(write-ex k)writes a getter method that throws an an exception
((write/write-ex :hello) nil nil) => (throws)
write-fields
added in 3.0
(write-fields cls)(write-fields cls query-fn)write fields of an object from reflection
(-> (write/write-fields Dog) keys) => :name :species
write-setters
macro
added in 3.0
(write-setters cls)(write-setters cls opts)(write-setters cls opts query-fn)write fields of an object through setter methods
(write/write-setters Dog) => {}
(keys (write/write-setters DogBuilder)) => :name
write-setters-form
added in 3.0
(write-setters-form cls)(write-setters-form cls opts)(write-setters-form cls {:keys [prefix template create select], :or {prefix "set", template +write-template+, create create-write-method-form}} query-fn)constructs forms for a given object
(write/write-setters-form DogBuilder) => ’{:name {:type java.lang.String, :fn (clojure.core/fn setName obj val (clojure.core/or (. obj (setName val)) obj))}}