Skip to content

Commit bc61942

Browse files
alexander-yakushevbbatsov
authored andcommitted
[misc] Replace require-and-resolve with requiring-resolve where suitable
1 parent 4ae5b64 commit bc61942

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

src/orchard/java.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
(def ^:private parser-next-source-info
5050
(delay
5151
(when (>= misc/java-api-version 11)
52-
(try (let [f (misc/require-and-resolve 'orchard.java.parser-next/source-info)]
52+
(try (let [f (requiring-resolve 'orchard.java.parser-next/source-info)]
5353
;; We try parsing LruMap.java as a litmus test for whether the
5454
;; parser works. We can be sure that LruMap.java is on the
5555
;; classpath because we pack it into the final Orchard jar.
@@ -87,7 +87,7 @@
8787
"On JDK11+, return module name from the class if present; otherwise return nil"
8888
[class-or-sym]
8989
(when (>= misc/java-api-version 11)
90-
((misc/require-and-resolve 'orchard.java.modules/module-name) class-or-sym)))
90+
((requiring-resolve 'orchard.java.modules/module-name) class-or-sym)))
9191

9292
(defn javadoc-url
9393
"Return the relative `.html` javadoc path and member fragment."

src/orchard/misc.clj

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,12 @@
137137
[ns]
138138
(instance? clojure.lang.Namespace ns))
139139

140-
;; Drop this in favor of clojure.core/requiring-resolve at some point?
141-
142140
(defn require-and-resolve
143-
"Try to require the namespace and get a var for the symbol, return the var's
144-
value if successful, nil if not."
141+
"Like `clojure.core/requiring-resolve`, but doesn't throw exception if namespace
142+
was not found or failed to load. Also, returns derefs the resolved var."
145143
{:added "0.5"}
146144
[sym]
147-
(try (require (-> sym namespace symbol))
145+
(try (some-> sym requiring-resolve var-get)
148146
(var-get (resolve sym))
149147
(catch Exception _)))
150148

test/orchard/java/parser_next_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
(def source-info
1919
(when jdk11+?
20-
(misc/require-and-resolve 'orchard.java.parser-next/source-info)))
20+
(requiring-resolve 'orchard.java.parser-next/source-info)))
2121

2222
(def parse-java
2323
(when jdk11+?
24-
(misc/require-and-resolve 'orchard.java.parser-next/parse-java)))
24+
(requiring-resolve 'orchard.java.parser-next/parse-java)))
2525

2626
(when jdk11+?
2727
(deftest parse-java-test

0 commit comments

Comments
 (0)