Permalink
Browse files

Moved reflection from linters/misc to linters/reflection

  • Loading branch information...
1 parent 0046c06 commit f3980e8b25970d687a9c46331769427123b0bb17 @jonase committed Jan 15, 2012
Showing with 38 additions and 44 deletions.
  1. +2 −1 src/brittle/core.clj
  2. +5 −5 src/eastwood/core.clj
  3. +0 −38 src/eastwood/linters/misc.clj
  4. +31 −0 src/eastwood/linters/reflection.clj
View
@@ -12,7 +12,8 @@
(defn len [s] ; reflects
(replicate 1 0) ; deprecated
- (.length s))
+ (.length s)
+ (.method s 0))
(defn foo [x] ; <- never used
(let [a 0 x 1] ; <- a is never used
View
@@ -6,7 +6,8 @@
[clojure.set :as set]
[eastwood.linters.misc :as misc]
[eastwood.linters.deprecated :as deprecated]
- [eastwood.linters.unused :as unused]))
+ [eastwood.linters.unused :as unused]
+ [eastwood.linters.reflection :as reflection]))
(defn analyze [ns-sym]
@@ -20,11 +21,10 @@
{:naked-use misc/naked-use
:misplaced-docstrings misc/misplaced-docstrings
;; :non-dynamic-earmuffs misc/non-dynamic-earmuffs ; checked by compiler
- :reflection misc/reflection
+ :reflection reflection/reflection
:deprecations deprecated/deprecations
:unused-locals unused/unused-locals
- :unused-private-vars unused/unused-private-vars
- })
+ :unused-private-vars unused/unused-private-vars})
(def ^:private all-linters (set (keys linters)))
@@ -39,4 +39,4 @@
(doseq [ns namespaces]
(lint exprs ns))))
-;(lint-ns 'brittle.core :only [:unused-private-vars])
+;(lint-ns 'brittle.core :only [:reflection])
@@ -70,41 +70,3 @@
(doseq [exp exprs]
(find-and-check-earmuffed-defs exp)))
-;; Reflection
-(defn- check-new [exp]
- (when (not (:ctor exp))
- (println "Unresolved constructor" (:class exp) (-> exp :env :ns :name))))
-
-(defn- check-static-method [exp]
- (when (not (:method exp))
- (println "Unresolved static method" (:method-name exp) (:class exp) (-> exp :env :ns :name))))
-
-(defn- check-instance-method [exp]
- (when (not (:method exp))
- (println "Unresolved instance method" (:method-name exp) (:class exp) (-> exp :env :ns :name))))
-
-(defn- check-static-field [exp]
- (when (not (:field exp))
- (println "Unresolved static field" (:field-name exp) (:class exp) (-> exp :env :ns :name))))
-
-(defn- check-instance-field [exp]
- (when (not (:field exp))
- (println "Unresolved instance field" (:field-name exp) (:class exp) (-> exp :env :ns :name))))
-
-
-(defn- check-for-reflection [exp]
- (condp = (:op exp)
- :new (check-new exp)
- :static-method (check-static-method exp)
- :instance-method (check-instance-method exp)
- :static-field (check-static-field exp)
- :instance-field (check-instance-field exp)
- nil)
-
- (doseq [c (:children exp)]
- (check-for-reflection c)))
-
-(defn reflection [exprs]
- (doseq [exp exprs]
- (check-for-reflection exp)))
-
@@ -0,0 +1,31 @@
+(ns eastwood.linters.reflection
+ (:use analyze.util))
+
+(defmulti reflective-call? :op)
+
+(defmethod reflective-call? :instance-method [expr]
+ (not (:method expr)))
+
+(defmethod reflective-call? :instance-field [expr]
+ (not (:method expr)))
+
+(defmethod reflective-call? :default [_] false)
+
+(defmulti report :op)
+
+(defmethod report :instance-method [expr]
+ (println "Unresolved instance method"
+ (:method-name expr)
+ "in"
+ (-> expr :env :ns :name)))
+
+(defmethod report :instance-field [expr]
+ (println "Unresolved instance field"
+ (:field-name expr)
+ "in"
+ (-> expr :env :ns :name)))
+
+(defn reflection [exprs]
+ (doseq [expr (mapcat expr-seq exprs)
+ :when (reflective-call? expr)]
+ (report expr)))

0 comments on commit f3980e8

Please sign in to comment.