Skip to content

Commit c044c57

Browse files
[inspect] Display identity hashcode for objects
1 parent 8c949e5 commit c044c57

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
* [#328](https://github.com/clojure-emacs/orchard/pull/328): Inspector: display identity hashcode for Java objects.
6+
7+
## 0.31.1 (2025-03-19)
8+
59
* [#325](https://github.com/clojure-emacs/orchard/pull/325): Add `ex-str`-formatted message to analyzed causes.
610

711
## 0.31.0 (2025-03-14)

src/orchard/inspect.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,17 @@
640640
(into (sorted-map)))
641641
false)
642642
(unindent))
643-
inspector))]
643+
inspector))
644+
(render-ident-hashcode [inspector]
645+
(let [code (System/identityHashCode obj)]
646+
(-> inspector
647+
(render-indent "Identity hash code: " (str code) " "
648+
(format "(0x%s)" (Integer/toHexString code)))
649+
(render-ln))))]
644650
(cond-> inspector
645651
true (render-labeled-value "Class" (class obj))
646652
true (render-labeled-value "Value" obj {:display-value printed})
653+
true (render-ident-hashcode)
647654
(seq non-static-accessible) (render-fields "Instance fields" non-static-accessible)
648655
(seq static-accessible) (render-fields "Static fields" static-accessible)
649656
(seq non-static-nonaccessible) (render-fields "Private instance fields" non-static-nonaccessible)

test/orchard/inspect_test.clj

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -849,21 +849,25 @@
849849

850850
(deftest inspect-java-object-test
851851
(testing "inspecting any Java object prints its fields"
852-
(is (match? '("Class: "
853-
(:value "clojure.lang.TaggedLiteral" 0)
854-
(:newline)
855-
"Value: " (:value "#foo ()" 1)
856-
(:newline)
857-
(:newline)
858-
"--- Instance fields:"
859-
(:newline) " " (:value "form" 2) " = " (:value "()" 3)
860-
(:newline) " " (:value "tag" 4) " = " (:value "foo" 5)
861-
(:newline)
862-
(:newline)
863-
"--- Static fields:"
864-
(:newline) " " (:value "FORM_KW" 6) " = " (:value ":form" 7)
865-
(:newline) " " (:value "TAG_KW" 8) " = " (:value ":tag" 9)
866-
(:newline))
852+
(is (match? (resolve-syms
853+
'("Class: "
854+
(:value "clojure.lang.TaggedLiteral" 0)
855+
(:newline)
856+
"Value: " (:value "#foo ()" 1)
857+
(:newline)
858+
"Identity hash code: "
859+
string? " " string?
860+
(:newline)
861+
(:newline)
862+
"--- Instance fields:"
863+
(:newline) " " (:value "form" 2) " = " (:value "()" 3)
864+
(:newline) " " (:value "tag" 4) " = " (:value "foo" 5)
865+
(:newline)
866+
(:newline)
867+
"--- Static fields:"
868+
(:newline) " " (:value "FORM_KW" 6) " = " (:value ":form" 7)
869+
(:newline) " " (:value "TAG_KW" 8) " = " (:value ":tag" 9)
870+
(:newline)))
867871
(render (inspect (clojure.lang.TaggedLiteral/create 'foo ())))))))
868872

869873
(deftest inspect-path
@@ -1357,13 +1361,17 @@
13571361
(testing "inspecting eduction shows its object fields"
13581362
(let [rendered (-> (eduction (range 10)) inspect render)]
13591363
(testing "renders the header section"
1360-
(is (match? '("Class: "
1361-
(:value "clojure.core.Eduction" 0)
1362-
(:newline)
1363-
"Value: "
1364-
(:value "(0 1 2 3 4 ...)" 1)
1365-
(:newline)
1366-
(:newline))
1364+
(is (match? (resolve-syms
1365+
'("Class: "
1366+
(:value "clojure.core.Eduction" 0)
1367+
(:newline)
1368+
"Value: "
1369+
(:value "(0 1 2 3 4 ...)" 1)
1370+
(:newline)
1371+
"Identity hash code: "
1372+
string? " " string?
1373+
(:newline)
1374+
(:newline)))
13671375
(header rendered)))))
13681376

13691377
(let [rendered (-> (eduction (range 100)) inspect render)]

0 commit comments

Comments
 (0)