Fix many reflection warnings.

This commit is contained in:
Andrey Antukh 2020-01-27 10:03:42 +01:00
parent de233d6778
commit f2cb2c3791
18 changed files with 79 additions and 57 deletions

View file

@ -15,4 +15,4 @@
(defstate system
:start (vc/system)
:stop (.close system))
:stop (vc/stop system))

View file

@ -44,7 +44,7 @@
(defmethod handle-exception :service-error
[err req]
(handle-exception (.getCause err) req))
(handle-exception (.getCause ^Throwable err) req))
(defmethod handle-exception :parse
[err req]
@ -56,7 +56,7 @@
[err req]
(log/error "Unhandled exception on request:" (:path req) "\n"
(with-out-str
(.printStackTrace err (java.io.PrintWriter. *out*))))
(.printStackTrace ^Throwable err (java.io.PrintWriter. *out*))))
{:status 500
:body {:type :exception
:message (ex-message err)
@ -66,5 +66,5 @@
[error req]
(if (or (instance? java.util.concurrent.CompletionException error)
(instance? java.util.concurrent.ExecutionException error))
(handle-exception (.getCause error) req)
(handle-exception (.getCause ^Throwable error) req)
(handle-exception error req)))

View file

@ -34,7 +34,7 @@
;; --- Task Execution
(defn- string-strack-trace
[err]
[^Throwable err]
(with-out-str
(.printStackTrace err (java.io.PrintWriter. *out*))))

View file

@ -58,7 +58,7 @@
(decode-v1 data udata-len)))))
(defn- decode-v1
[data udata-len]
[^bytes data udata-len]
(let [^bytes output-ba (byte-array udata-len)]
(Snappy/uncompress data 6 (- (alength data) 6) output-ba 0)
(t/decode output-ba {:type :json})))

View file

@ -100,7 +100,8 @@
f `(fn ~args ~@body)]
`(do
(s/assert dispatcher? ~sym)
(.add ~sym ~key ~f ~meta)
(.add ~(with-meta sym {:tag 'uxbox.util.dispatcher.IDispatcher})
~key ~f ~meta)
~sym)))
(def spec-interceptor

View file

@ -17,8 +17,13 @@
io.vertx.core.AsyncResult
io.vertx.core.buffer.Buffer
io.vertx.pgclient.PgPool
io.vertx.pgclient.PgConnection
io.vertx.sqlclient.impl.ArrayTuple
io.vertx.sqlclient.SqlClient
io.vertx.sqlclient.RowSet
io.vertx.sqlclient.Row
io.vertx.sqlclient.Tuple
io.vertx.sqlclient.Transaction
io.vertx.sqlclient.PoolOptions))
(declare impl-execute)
@ -79,10 +84,10 @@
(p/map first (apply query args)))
(defn row->map
[row]
[^Row row]
(reduce (fn [acc index]
(let [cname (.getColumnName row index)]
(assoc acc cname (.getValue row index))))
(assoc acc cname (.getValue row ^int index))))
{}
(range (.size row))))
@ -102,18 +107,21 @@
[resolve reject]
(reify Handler
(handle [_ ar]
(if (.failed ar)
(reject (.cause ar))
(resolve (.result ar))))))
(if (.failed ^AsyncResult ar)
(reject (.cause ^AsyncResult ar))
(resolve (.result ^AsyncResult ar))))))
(defn- impl-execute
[conn sql params]
[^SqlClient conn ^String sql params]
(if (seq params)
(p/create #(.preparedQuery conn sql (seqable->tuple params) (impl-handler %1 %2)))
(p/create #(.query conn sql (impl-handler %1 %2)))))
(p/create #(.preparedQuery conn sql
^Tuple (seqable->tuple params)
^Handler (impl-handler %1 %2)))
(p/create #(.query conn sql
^Handler (impl-handler %1 %2)))))
(defn- impl-query
[conn sql params {:keys [xfm] :as opts}]
[^SqlClient conn ^String sql params {:keys [xfm] :as opts}]
(let [conn (if (instance? IDeref conn) @conn conn)]
(-> (impl-execute conn sql params)
(p/catch (fn [err]
@ -126,11 +134,11 @@
(defn impl-transact
[pool f]
(let [pool (if (instance? IDeref pool) @pool pool)]
(letfn [(commit [tx]
(letfn [(commit [^Transaction tx]
(p/create #(.commit tx (impl-handler %1 %2))))
(rollback [tx]
(rollback [^Transaction tx]
(p/create #(.rollback tx (impl-handler %1 %2))))
(on-connect [conn]
(on-connect [^PgConnection conn]
(let [tx (.begin conn)
df (p/deferred)]
(-> (f conn)
@ -147,6 +155,6 @@
(p/reject! df e')
(p/resolve! df v)))))))))
df))]
(-> (p/create #(.getConnection pool (impl-handler %1 %2)))
(-> (p/create #(.getConnection ^PgPool pool (impl-handler %1 %2)))
(p/bind on-connect)))))

View file

@ -58,7 +58,7 @@
path))
(defn blob
[v]
[^String v]
(let [data (.getBytes v "UTF-8")]
(ByteArrayInputStream. ^bytes data)))
@ -162,7 +162,7 @@
(def ^:private prng
(delay
(doto (java.security.SecureRandom/getInstance "SHA1PRNG")
(.setSeed (sodi.prng/random-bytes 64)))))
(.setSeed ^bytes (sodi.prng/random-bytes 64)))))
(defn random-path
[^Path path]

View file

@ -41,13 +41,13 @@
""))))
(or (vector? x) (list? x))
(java.util.ArrayList. x)
(java.util.ArrayList. ^java.util.List x)
(map? x)
(java.util.HashMap. x)
(java.util.HashMap. ^java.util.Map x)
(set? x)
(java.util.HashSet. x)
(java.util.HashSet. ^java.util.Set x)
:else
x))
@ -60,7 +60,7 @@
(let [context (adapt-context context)
template (.compile +mustache-factory+ path)]
(with-out-str
(let [scope (HashMap. (walk/stringify-keys context))]
(let [scope (HashMap. ^java.util.Map (walk/stringify-keys context))]
(.execute ^Mustache template *out* scope))))
(catch Exception cause
(ex/raise :type :internal

View file

@ -6,12 +6,14 @@
(ns uxbox.util.time
(:require
[clojure.spec.alpha :as s]
[uxbox.common.exceptions :as ex]
[cognitect.transit :as t])
(:import
java.time.Instant
java.time.OffsetDateTime
java.time.Duration
java.util.Date
org.apache.logging.log4j.core.util.CronExpression))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -161,13 +163,18 @@
[v]
(instance? CronExpression v))
(defn next-valid-instant-from
[^CronExpression cron ^Instant now]
(s/assert cron? cron)
(.toInstant (.getNextValidTimeAfter cron (Date/from now))))
(defmethod print-method CronExpression
[mv ^java.io.Writer writer]
(.write writer (str "#uxbox/cron \"" (.toString mv) "\"")))
(.write writer (str "#uxbox/cron \"" (.toString ^CronExpression mv) "\"")))
(defmethod print-dup CronExpression
[o w]
(print-ctor o (fn [o w] (print-dup (.toString o) w)) w))
(print-ctor o (fn [o w] (print-dup (.toString ^CronExpression o) w)) w))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Serialization
@ -178,12 +185,12 @@
(def ^:private instant-write-handler
(t/write-handler
(constantly "m")
(fn [v] (str (.toEpochMilli v)))))
(fn [v] (str (.toEpochMilli ^Instant v)))))
(def ^:private offset-datetime-write-handler
(t/write-handler
(constantly "m")
(fn [v] (str (.toEpochMilli (.toInstant v))))))
(fn [v] (str (.toEpochMilli (.toInstant ^OffsetDateTime v))))))
(def ^:private read-handler
(t/read-handler
@ -199,7 +206,7 @@
(defmethod print-method Instant
[mv ^java.io.Writer writer]
(.write writer (str "#instant \"" (.toString mv) "\"")))
(.write writer (str "#instant \"" (.toString ^Instant mv) "\"")))
(defmethod print-dup Instant [o w]
(print-method o w))