Skip to content

Commit 992e9a2

Browse files
authored
Merge pull request #193 from julienfantin/fix-reflection-warnings
Fix reflection warnings
2 parents bd3b676 + 9ac330a commit 992e9a2

15 files changed

+69
-63
lines changed

project.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
^:source-dep [rewrite-clj "0.4.13-SNAPSHOT"]
1717
^:source-dep [cljs-tooling "0.1.7"]
1818
^:source-dep [version-clj "0.1.2"]]
19+
:global-vars {*warn-on-reflection* true}
1920
:plugins [[thomasa/mranderson "0.4.7"]]
2021
:filespecs [{:type :bytes :path "refactor-nrepl/refactor-nrepl/project.clj" :bytes ~(slurp "project.clj")}]
2122
:profiles {:provided {:dependencies [[cider/cider-nrepl "0.10.0"]

src/refactor_nrepl/analyzer.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
(throw ast-or-err)
108108

109109
error?
110-
(throw-ast-in-bad-state file-content (.getMessage ast-or-err))
110+
(throw-ast-in-bad-state file-content (.getMessage ^Throwable ast-or-err))
111111

112112
:default
113113
ast-or-err)))
@@ -118,7 +118,7 @@
118118
(->> (vals asts)
119119
(mapcat vals)
120120
(map #(if (instance? Throwable %)
121-
(list "error" (.getMessage %))
121+
(list "error" (.getMessage ^Throwable %))
122122
"OK"))))))
123123

124124
(defn warm-ast-cache []
@@ -128,8 +128,8 @@
128128
(catch Throwable th))) ;noop, ast-status will be reported separately
129129
(ast-stats))
130130

131-
(defn node-at-loc? [loc-line loc-column node]
132-
(let [{:keys [line end-line column end-column]} (:env node)]
131+
(defn node-at-loc? [^long loc-line ^long loc-column node]
132+
(let [{:keys [^long line ^long end-line ^long column ^long end-column]} (:env node)]
133133
;; The node for ::an-ns-alias/foo, when it appeared as a toplevel form,
134134
;; had nil as position info
135135
(and line end-line column end-column

src/refactor_nrepl/core.clj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[me.raynes.fs :as fs]
88
[refactor-nrepl.util :refer [normalize-to-unix-path]]
99
[refactor-nrepl.s-expressions :as sexp])
10-
(:import [java.io FileReader PushbackReader StringReader]))
10+
(:import [java.io File FileReader PushbackReader StringReader]))
1111

1212
(defn version []
1313
(let [v (-> (or (io/resource "refactor-nrepl/refactor-nrepl/project.clj")
@@ -45,18 +45,18 @@
4545
to use as a starting point. We search anything above this dir, until
4646
we reach the file system root. Default value is the property
4747
`user.dir`."
48-
([] (project-root (System/getProperty "user.dir")))
49-
([path-or-file-in-project]
48+
(^File [] (project-root (System/getProperty "user.dir")))
49+
(^File [path-or-file-in-project]
5050
(let [path-or-file-in-project (io/file path-or-file-in-project)
5151
start (if (fs/directory? path-or-file-in-project)
5252
path-or-file-in-project
5353
(fs/parent path-or-file-in-project))
5454
names-at-root #{"project.clj" "build.boot" "build.gradle" "pom.xml"}
55-
known-root-file? (fn [f] (some (fn [known-root-name]
56-
(.endsWith (.getCanonicalPath f)
57-
known-root-name))
58-
names-at-root))
59-
root-dir? (fn [f] (some known-root-file? (.listFiles f)))
55+
known-root-file? (fn [^File f] (some (fn [known-root-name]
56+
(.endsWith (.getCanonicalPath f)
57+
known-root-name))
58+
names-at-root))
59+
root-dir? (fn [^File f] (some known-root-file? (.listFiles f)))
6060
most-likely-root (io/file (System/getProperty "user.dir"))]
6161
(if (root-dir? most-likely-root)
6262
most-likely-root
@@ -72,7 +72,7 @@
7272
normalize-to-unix-path
7373
(str "/target"))
7474
parent-paths (map (comp normalize-to-unix-path
75-
(memfn getCanonicalPath))
75+
(memfn ^File getCanonicalPath))
7676
(fs/parents f))]
7777
(and (some #{target-path} parent-paths)
7878
path-or-file)))
@@ -192,7 +192,7 @@
192192
(defn strip-reader-macros
193193
"Strip reader macros like #' and . (as in '(Date.)') from
194194
symbol-or-string."
195-
[symbol-or-string]
195+
^String [symbol-or-string]
196196
(let [s (-> symbol-or-string
197197
str
198198
(str/replace "#'" ""))]

src/refactor_nrepl/extract_definition.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(zipmap (take-nth 2 occurrence) (take-nth 2 (rest occurrence))))
1414

1515
(defn- extract-definition-from-def
16-
[^String sexp]
16+
^String [^String sexp]
1717
(let [def-form (read-string sexp)
1818
docstring? (string? (nth def-form 2 :not-found))
1919
sexp-sans-delimiters (.substring (str/trim sexp) 1 (dec (.length sexp)))
@@ -25,23 +25,23 @@
2525
(str/trim (slurp rdr))))
2626

2727
(defn- extract-definition-from-defn
28-
[^String sexp]
28+
^String [^String sexp]
2929
(let [form (read-string sexp)
3030
fn-name (str (second form))]
3131
(-> sexp
3232
(.replaceFirst (if (re-find #"defn-" sexp) "defn-" "defn") "fn")
3333
(.replaceFirst (str "\\s*" (Pattern/quote fn-name)) ""))))
3434

3535
(defn- extract-def-from-binding-vector
36-
[^String bindings ^String var-name]
36+
^String [^String bindings ^String var-name]
3737
(let [zipper (zip/of-string bindings)
3838
zloc (some (fn [zloc] (when (= (symbol var-name) (zip/sexpr zloc)) zloc))
3939
(sexp/all-zlocs zipper))]
4040
(when zloc
4141
(str/trim (zip/string (zip/right zloc))))))
4242

4343
(defn- -extract-definition
44-
[{:keys [match file line-beg col-beg name]}]
44+
[{:keys [match file ^long line-beg ^long col-beg name]}]
4545
(let [literal-sexp (sexp/get-enclosing-sexp (slurp file) (dec line-beg)
4646
col-beg)
4747
form (read-string literal-sexp)]
@@ -67,7 +67,7 @@
6767

6868
(defn- def?
6969
"Is the OCCURRENCE the defining form?"
70-
[{:keys [file name col-beg line-beg] :as occurrence}]
70+
[{:keys [file name ^long col-beg ^long line-beg] :as occurrence}]
7171
(let [form (read-string (sexp/get-enclosing-sexp (slurp file) (dec line-beg)
7272
col-beg))
7373
name (symbol (suffix (read-string name)))]
@@ -78,7 +78,7 @@
7878

7979
(defn- sort-by-linum
8080
[occurrences]
81-
(sort #(- (:line-beg %1) (:line-beg %2)) occurrences))
81+
(sort #(- (long (:line-beg %1)) (long (:line-beg %2))) occurrences))
8282

8383
(defn- find-definition [occurrences]
8484
(some->> occurrences

src/refactor_nrepl/find/find_locals.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[s-expressions :as sexp]
77
[core :as core]]))
88

9-
(defn find-used-locals [{:keys [file line column]}]
9+
(defn find-used-locals [{:keys [file ^long line ^long column]}]
1010
{:pre [(number? line)
1111
(number? column)
1212
(not-empty file)]}

src/refactor_nrepl/find/find_macros.clj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
(str/join "\n")))
3131

3232
(defn- build-macro-meta
33-
[form f]
33+
[form ^File f]
3434
(let [{:keys [line column end-line end-column]} (meta form)
3535
file-content (slurp f)
3636
file-ns (core/ns-from-string file-content)
@@ -47,7 +47,7 @@
4747
:match sexp}))
4848

4949
(defn- find-macro-definitions-in-file
50-
[f]
50+
[^File f]
5151
(util/with-additional-ex-data [:file (.getAbsolutePath f)]
5252
(with-open [file-rdr (FileReader. f)]
5353
(binding [*ns* (or (core/path->namespace :no-error f) *ns*)
@@ -63,12 +63,12 @@
6363
:else
6464
(recur macros (reader/read opts rdr)))))))))
6565

66-
(defn- get-cached-macro-definitions [f]
66+
(defn- get-cached-macro-definitions [^File f]
6767
(when-let [[ts v] (get @macro-defs-cache (.getAbsolutePath f))]
6868
(when (= ts (.lastModified f))
6969
v)))
7070

71-
(defn- put-cached-macro-definitions [f]
71+
(defn- put-cached-macro-definitions [^File f]
7272
(let [defs (find-macro-definitions-in-file f)
7373
ts (.lastModified f)]
7474
(swap! macro-defs-cache assoc-in [(.getAbsolutePath f)] [ts defs])
@@ -117,10 +117,10 @@
117117
"line-offset is the offset in the file where we start searching.
118118
This is after the ns but clj-rewrite keeps tracking of any following
119119
whitespace."
120-
[path macro-name line-offset zip-node]
120+
[path macro-name ^long line-offset zip-node]
121121
(let [node (zip/node zip-node)
122-
val (:string-value node)
123-
{:keys [row col]} (meta node)]
122+
^String val (:string-value node)
123+
{:keys [^long row ^long col]} (meta node)]
124124
{:match (zip/string (zip/up zip-node))
125125
:name macro-name
126126
:line-beg (dec (+ row line-offset))

src/refactor_nrepl/find/find_symbol.clj

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
[s-expressions :as sexp]]
1111
[refactor-nrepl.find.find-macros :refer [find-macro]]
1212
[refactor-nrepl.find.util :as find-util]
13-
[refactor-nrepl.ns.libspecs :as libspecs]))
13+
[refactor-nrepl.ns.libspecs :as libspecs])
14+
(:import (java.io File)))
1415

1516
(def ^:private symbol-regex #"[\w\.:\*\+\-_!\?]+")
1617

@@ -92,7 +93,7 @@
9293
name
9394
(alias-info asts)))))
9495

95-
(defn- match [file-content line end-line]
96+
(defn- match [file-content ^long line ^long end-line]
9697
(let [line-index (dec line)
9798
eline (if (number? end-line) end-line line)]
9899
(->> file-content
@@ -102,7 +103,7 @@
102103
(str/join "\n")
103104
str/trim)))
104105

105-
(defn- find-symbol-in-file [fully-qualified-name ignore-errors file]
106+
(defn- find-symbol-in-file [fully-qualified-name ignore-errors ^File file]
106107
(let [file-content (slurp file)
107108
locs (try (->> (ana/ns-ast file-content)
108109
(find-symbol-in-ast fully-qualified-name)
@@ -139,7 +140,7 @@
139140
(mapcat (partial find-symbol-in-file fully-qualified-name ignore-errors)))))
140141

141142
(defn- get&read-enclosing-sexps
142-
[file-content {:keys [line-beg col-beg]}]
143+
[file-content {:keys [^long line-beg ^long col-beg]}]
143144
(binding [*read-eval* false]
144145
(let [line (dec line-beg)
145146
encl-sexp-level1 (or (sexp/get-enclosing-sexp file-content line col-beg) "")
@@ -164,18 +165,18 @@
164165
res)))
165166

166167
(defn- occurrence-for-optmap-default
167-
[var-name [{:keys [line-beg col-beg] :as orig-occurrence} [_ _ level2-string _]]]
168+
[var-name [{:keys [line-beg col-beg] :as orig-occurrence} [_ _ ^String level2-string _]]]
168169
(let [var-positions (re-pos (re-pattern (format "\\W%s\\W" var-name)) level2-string)
169-
var-default-pos (first (second var-positions))
170-
newline-cnt (reduce (fn [cnt char] (if (= char \newline) (inc cnt) cnt)) 0 (.substring level2-string 0 var-default-pos))
170+
^long var-default-pos (first (second var-positions))
171+
newline-cnt (reduce (fn [cnt char] (if (= char \newline) (inc (long cnt)) cnt)) 0 (.substring level2-string 0 var-default-pos))
171172
prev-newline-position (->> (concat (keys (re-pos #"\n" level2-string))
172173
(keys var-positions))
173174
sort
174175
(take-while (partial not= var-default-pos))
175176
last)
176177
new-col (if (= 0 newline-cnt)
177-
(- var-default-pos (ffirst var-positions))
178-
(inc (- var-default-pos prev-newline-position)))
178+
(- var-default-pos (long (ffirst var-positions)))
179+
(inc (- (long var-default-pos) (long prev-newline-position))))
179180
new-occurrence (-> (update-in orig-occurrence [:line-beg] + newline-cnt)
180181
(update-in [:line-end] + newline-cnt))]
181182
(if (= 0 newline-cnt)
@@ -192,7 +193,7 @@
192193
var-name is the name of the var the user wants to know about
193194
line is the line number of the symbol
194195
column is the column of the symbol"
195-
[file var-name line column]
196+
[^String file var-name line column]
196197
{:pre [(number? line)
197198
(number? column)
198199
(not-empty file)]}

src/refactor_nrepl/find/util.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
(defn spurious?
66
"True if the occurrence doesn't exist at the given coordinates."
7-
([{:keys [file line-beg col-beg col-end name match] :as occ}]
7+
([{:keys [file ^long line-beg ^long col-beg ^long col-end name ^String match] :as occ}]
88
;; coordinates are wrong for def forms, they match the beginning of
99
;; the form not the first mention of the symbol being defined
1010
(when-not (and match (.startsWith match "(def"))

src/refactor_nrepl/ns/libspecs.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns refactor-nrepl.ns.libspecs
22
(:require [refactor-nrepl.core :as core]
3-
[refactor-nrepl.ns.ns-parser :as ns-parser]))
3+
[refactor-nrepl.ns.ns-parser :as ns-parser])
4+
(:import [java.io File]))
45

56
;; The structure here is {path {lang [timestamp value]}}
67
;; where lang is either :clj or :cljs
@@ -24,12 +25,12 @@
2425
(mapcat identity)
2526
(apply hash-map)))
2627

27-
(defn- get-cached-libspec [f lang]
28+
(defn- get-cached-libspec [^File f lang]
2829
(when-let [[ts v] (get-in @cache [(.getAbsolutePath f) lang])]
2930
(when (= ts (.lastModified f))
3031
v)))
3132

32-
(defn- put-cached-libspec [f lang]
33+
(defn- put-cached-libspec [^File f lang]
3334
(let [libspecs (ns-parser/get-libspecs-from-file lang f)]
3435
(swap! cache assoc-in [(.getAbsolutePath f) lang]
3536
[(.lastModified f) libspecs])

src/refactor_nrepl/ns/pprint.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
(printf "[%s" name)
1616
(let [ordered-libspecs (libspec-vectors-last libspecs)]
1717
(dorun
18-
(map-indexed (fn [idx libspec]
18+
(map-indexed (fn [^long idx libspec]
1919
;; insert newline after all non-libspec vectors
2020
(when (and (vector? libspec)
2121
(or (zero? idx)

0 commit comments

Comments
 (0)