Back
inspect (clj)
(source)function
(inspect x)
creates a graphical (Swing) inspector on the supplied object
Examples
clojure
(ns clojure.test-clojure.java-interop
(:use clojure.test)
(:require [clojure.data :as data]
[clojure.inspector]
[clojure.pprint :as pp]
[clojure.set :as set]
[clojure.test-clojure.proxy.examples :as proxy-examples])
(:import java.util.Base64
(java.util.concurrent.atomic AtomicLong AtomicInteger)))
;; serialized-proxy can be regenerated using a modified version of
;; Clojure with the proxy serialization prohibition disabled and the
;; following code:
;; revert 271674c9b484d798484d134a5ac40a6df15d3ac3 to allow serialization
(comment
(require 'clojure.inspector)
(let [baos (java.io.ByteArrayOutputStream.)]
(with-open [baos baos]
(.writeObject (java.io.ObjectOutputStream. baos) (clojure.inspector/list-model nil)))
(prn (vector (System/getProperty "java.specification.version")
(.encodeToString (java.util.Base64/getEncoder) (.toByteArray baos))))))
(deftest test-proxy-non-serializable
(testing "That proxy classes refuse serialization and deserialization"
;; Serializable listed directly in interface list:
(is (thrown? java.io.NotSerializableException
(-> (java.io.ByteArrayOutputStream.)
(java.io.ObjectOutputStream.)
(.writeObject (proxy [Object java.io.Serializable] [])))))
;; Serializable included via inheritence:
(is (thrown? java.io.NotSerializableException
(-> (java.io.ByteArrayOutputStream.)
(java.io.ObjectOutputStream.)
(.writeObject (clojure.inspector/list-model nil)))))
;; Deserialization also prohibited:
(let [java-version (System/getProperty "java.specification.version")
serialized-proxy (get serialized-proxies java-version)]
(if serialized-proxy
(is (thrown? java.io.NotSerializableException
(-> serialized-proxy
decode-base64
java.io.ByteArrayInputStream. java.io.ObjectInputStream.
.readObject)))
(println "WARNING: Missing serialized proxy for Java" java-version "in test/clojure/test_clojure/java_interop.clj")))))
clojure/core.typed
(deftest atom?-test
(is-tc-e #(atom? "abc") [-> Boolean]
:requires [[clojure.inspector :refer [atom?]]])
(is-tc-err #(atom? "abc") [-> String]
:requires [[clojure.inspector :refer [atom?]]]))
(deftest collection-tag-test
(is-tc-e #(collection-tag "abc") [-> Keyword]
:requires [[clojure.inspector :refer [collection-tag]]])
(is-tc-err #(collection-tag "abc") [-> String]
:requires [[clojure.inspector :refer [collection-tag]]]))
(deftest tree-model-test
(is-tc-e #(tree-model "abc")
:requires [[clojure.inspector :refer [tree-model]]]))
(deftest old-table-model-test
(is-tc-e #(old-table-model [[1 2 3] [4 5 6] [7 8 9] [10 11 12]])
:requires [[clojure.inspector :refer [old-table-model]]])
(is-tc-err #(old-table-model 1)
:requires [[clojure.inspector :refer [old-table-model]]]))
(deftest inspect-test
(is-tc-e #(inspect "abc") [-> javax.swing.JFrame]
:requires [[clojure.inspector :refer [inspect]]])
(is-tc-err #(inspect "abc") [-> String]
:requires [[clojure.inspector :refer [inspect]]]))
(deftest inspect-tree-test
(is-tc-e #(inspect-tree "abc") [-> javax.swing.JFrame]
:requires [[clojure.inspector :refer [inspect-tree]]])
(is-tc-err #(inspect-tree "abc") [-> String]
:requires [[clojure.inspector :refer [inspect-tree]]]))
(deftest inspect-table-test
(is-tc-e #(inspect-table [[1 2 3] [4 5 6] [7 8 9] [10 11 12]]) [-> javax.swing.JFrame]
:requires [[clojure.inspector :refer [inspect-table]]])
(is-tc-err #(inspect-table 1)
:requires [[clojure.inspector :refer [inspect-table]]]))
typedclojure/typedclojure
(deftest atom?-test
(is-tc-e #(atom? "abc") [-> Boolean]
:requires [[clojure.inspector :refer [atom?]]])
(is-tc-err #(atom? "abc") [-> String]
:requires [[clojure.inspector :refer [atom?]]]))
(deftest collection-tag-test
(is-tc-e #(collection-tag "abc") [-> t/Keyword]
:requires [[clojure.inspector :refer [collection-tag]]])
(is-tc-err #(collection-tag "abc") [-> String]
:requires [[clojure.inspector :refer [collection-tag]]]))
(deftest tree-model-test
(is-tc-e #(tree-model "abc")
:requires [[clojure.inspector :refer [tree-model]]]))
(deftest old-table-model-test
(is-tc-e #(old-table-model [[1 2 3] [4 5 6] [7 8 9] [10 11 12]])
:requires [[clojure.inspector :refer [old-table-model]]])
(is-tc-err #(old-table-model 1)
:requires [[clojure.inspector :refer [old-table-model]]]))
(deftest inspect-test
(is-tc-e #(inspect "abc") [-> javax.swing.JFrame]
:requires [[clojure.inspector :refer [inspect]]])
(is-tc-err #(inspect "abc") [-> String]
:requires [[clojure.inspector :refer [inspect]]]))
(deftest inspect-tree-test
(is-tc-e #(inspect-tree "abc") [-> javax.swing.JFrame]
:requires [[clojure.inspector :refer [inspect-tree]]])
(is-tc-err #(inspect-tree "abc") [-> String]
:requires [[clojure.inspector :refer [inspect-tree]]]))
(deftest inspect-table-test
(is-tc-e #(inspect-table [[1 2 3] [4 5 6] [7 8 9] [10 11 12]]) [-> javax.swing.JFrame]
:requires [[clojure.inspector :refer [inspect-table]]])
(is-tc-err #(inspect-table 1)
:requires [[clojure.inspector :refer [inspect-table]]]))
reborg/clojure-essential-reference
(require '[clojure.inspector :refer [inspect-table]]) ; <1>
(inspect-table events)
;; See image below