Skip to content
Browse files

Add type-hints to avoid reflection.

  • Loading branch information...
1 parent c9a33c9 commit 347f92d61c5dde8bae38ea1d4fc60d5ec4042172 @ghoseb ghoseb committed with technomancy
Showing with 15 additions and 15 deletions.
  1. +4 −4 src/clj_stacktrace/core.clj
  2. +11 −11 src/clj_stacktrace/repl.clj
View
8 src/clj_stacktrace/core.clj
@@ -58,7 +58,7 @@
:ns String representing the namespace of the function.
:fn String representing the name of the enclosing var for the function.
:anon-fn true iff the function is an anonymous inner fn."
- [elem]
+ [^StackTraceElement elem]
(let [class-name (.getClassName elem)
file (.getFileName elem)
line (let [l (.getLineNumber elem)] (if (pos? l) l))
@@ -98,7 +98,7 @@
:trimmed-elems A subset of :trace-elems representing the portion of the
top of the stacktrace not shared with that of the caused
exception."
- [causer-e caused-parsed-elems]
+ [^Throwable causer-e caused-parsed-elems]
(let [parsed-elems (parse-trace-elems (.getStackTrace causer-e))
base {:class (class causer-e)
:message (.getMessage causer-e)
@@ -115,11 +115,11 @@
:message Regular exception message string.
:trace-elems Parsed stack trace elems, see parse-trace-elem.
:cause See parse-cause-exception."
- [e]
+ [^Throwable e]
(let [parsed-elems (parse-trace-elems (.getStackTrace e))
base {:class (class e)
:message (.getMessage e)
:trace-elems parsed-elems}]
(if-let [cause (.getCause e)]
(assoc base :cause (parse-cause-exception cause parsed-elems))
- base)))
+ base)))
View
22 src/clj_stacktrace/repl.clj
@@ -47,12 +47,12 @@
(defn method-str [parsed]
(if (:java parsed) (java-method-str parsed) (clojure-method-str parsed)))
-(defn pst-class-on [on color? class]
- (.append on (colored color? :red (str (.getName class) ": ")))
+(defn pst-class-on [^java.io.Writer on color? ^Class class]
+ (.append on ^String (colored color? :red (str (.getName class) ": ")))
(.flush on))
-(defn pst-message-on [on color? message]
- (.append on (colored color? :red message))
+(defn pst-message-on [^java.io.Writer on color? message]
+ (.append on ^String (colored color? :red message))
(.append on "\n")
(.flush on))
@@ -63,24 +63,24 @@
" " (method-str parsed-elem))))
(defn pst-elems-on
- [on color? parsed-elems & [source-width]]
+ [^java.io.Writer on color? parsed-elems & [source-width]]
(let [print-width (+ 6 (or source-width
(utils/fence
(sort
- (map #(.length %)
+ (map #(.length ^String %)
(map source-str parsed-elems))))))]
(doseq [parsed-elem parsed-elems]
- (.append on (pst-elem-str color? parsed-elem print-width))
+ (.append on ^String (pst-elem-str color? parsed-elem print-width))
(.append on "\n")
(.flush on))))
(defn pst-caused-by-on
- [on color?]
- (.append on (colored color? :red "Caused by: "))
+ [^java.io.Writer on color?]
+ (.append on ^String (colored color? :red "Caused by: "))
(.flush on))
(defn- pst-cause-on
- [on color? exec source-width]
+ [^java.io.Writer on color? exec source-width]
(pst-caused-by-on on color?)
(pst-class-on on color? (:class exec))
(pst-message-on on color? (:message exec))
@@ -94,7 +94,7 @@
[excp]
(let [this-source-width (utils/fence
(sort
- (map #(.length %)
+ (map #(.length ^String %)
(map source-str (:trace-elems excp)))))]
(if-let [cause (:cause excp)]
(max this-source-width (find-source-width cause))

0 comments on commit 347f92d

Please sign in to comment.
Something went wrong with that request. Please try again.