Skip to content

Commit 54ada36

Browse files
committed
Add sigs function to the api
1 parent ff4b712 commit 54ada36

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ clojure -Sdeps '{:deps {org.clojure/clojure.java.doc {:git/url "https://github.c
3838

3939
## Usage
4040

41-
The core namespace provides two functions:
41+
The core namespace provides three functions:
4242

4343
### jdoc
4444

@@ -60,6 +60,23 @@ Prints a markdown formatted version of the javadoc description:
6060
(jdoc ^[_ int] String/.substring)
6161
```
6262

63+
### sigs
64+
65+
Prints the method signatures in param tags form:
66+
67+
```clojure
68+
(sigs String/valueOf)
69+
;; => ^[boolean] String/valueOf
70+
;; ^[char] String/valueOf
71+
;; ^[char/1] String/valueOf
72+
;; ^[char/1 int int] String/valueOf
73+
;; ^[double] String/valueOf
74+
;; ^[float] String/valueOf
75+
;; ^[int] String/valueOf
76+
;; ^[long] String/valueOf
77+
;; ^[Object] String/valueOf
78+
```
79+
6380
### jdoc-data
6481

6582
Returns structured data instead of printing:

src/clojure/java/doc/api.clj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns clojure.java.doc.api
22
(:require
3-
[clojure.java.doc.impl :refer [parse-javadoc print-javadoc]]))
3+
[clojure.java.doc.impl :refer [parse-javadoc print-javadoc print-signatures]]))
44

55
(defn javadoc-data-fn [s param-tags]
66
(parse-javadoc s param-tags))
@@ -25,3 +25,11 @@
2525
(jdoc ^[char/1] String/valueOf) ; Print specific overload"
2626
[class-or-method]
2727
`(javadoc-fn ~(str class-or-method) '~(:param-tags (meta class-or-method))))
28+
29+
(defn sigs-fn [s param-tags]
30+
(print-signatures (javadoc-data-fn s param-tags)))
31+
32+
(defmacro sigs
33+
"print method signatures in param tags form"
34+
[class-or-method]
35+
`(sigs-fn ~(str class-or-method) '~(:param-tags (meta class-or-method))))

src/clojure/java/doc/impl.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,8 @@
160160
(doseq [{:keys [method-description-md]} selected-method]
161161
(println (condense-lines method-description-md)))
162162
(println (condense-lines class-description-md)))))
163+
164+
(defn print-signatures [{:keys [methods selected-method]}]
165+
(let [methods-to-print (or selected-method methods)]
166+
(doseq [{:keys [clojure-call]} methods-to-print]
167+
(println clojure-call))))

0 commit comments

Comments
 (0)