Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added linter for deprecated java calls

  • Loading branch information...
commit ddf76e7189f5fcb201605442ade70fac1b347ed9 1 parent 1b5666c
Jonas Enlund authored
13 src/analyze/core.clj
View
@@ -83,14 +83,14 @@
(defmethod analysis->map Compiler$LetExpr
[^Compiler$LetExpr expr env]
(let [body (analysis->map (.body expr) env)
- bindings (-> (doall (map analysis->map (.bindingInits expr) (repeat env)))
- vec)]
+ binding-inits (-> (doall (map analysis->map (.bindingInits expr) (repeat env)))
+ vec)]
{:op :let
:env env
- :binding-inits bindings
+ :binding-inits binding-inits
:body body
:is-loop (.isLoop expr)
- :children (conj bindings body)
+ :children (conj binding-inits body)
:Expr-obj expr}))
;; letfn
@@ -175,7 +175,7 @@
[^Compiler$InstanceFieldExpr expr env]
(let [field (partial field-accessor Compiler$InstanceFieldExpr)
target (analysis->map (field 'target expr) env)]
- {:op :static-field
+ {:op :instance-field
:env (assoc env
:line (field 'line expr))
:target target
@@ -184,7 +184,8 @@
(@#'reflect/field->map field))
:field-name (field 'fieldName expr)
:tag (field 'tag expr)
- :children [target]}))
+ :children [target]
+ :Expr-obj expr}))
(defmethod analysis->map Compiler$NewExpr
[^Compiler$NewExpr expr env]
2  src/brittle/core.clj
View
@@ -1,4 +1,5 @@
(ns brittle.core
+ (:import [java.awt Frame])
(:use clojure.java.io)) ; Naked use
#_(def *rebind-me* nil) ; non-dynamic, already checked by the compiler
@@ -16,4 +17,5 @@
(defn hour [] ;; Deprecated x 2!
+ Frame/TEXT_CURSOR
(.getHours (java.util.Date. 2012 21 12)))
1  src/eastwood/core.clj
View
@@ -1,4 +1,5 @@
(set! *warn-on-reflection* false)
+
(ns eastwood.core
(:require [analyze.core :as analyze]
[clojure.string :as string]
47 src/eastwood/linters/deprecated.clj
View
@@ -1,3 +1,5 @@
+;; TODO: Check for deprecated Interfaces, Classes and Exceptions?
+
(ns eastwood.linters.deprecated
(:use [analyze.util :only [expr-seq print-expr]]))
@@ -6,38 +8,43 @@
(defmethod deprecated :var [expr]
(-> expr :var meta :deprecated))
-(defn java-is-deprecated? [obj]
- (->> obj
- .getAnnotations
- (map #(.annotationType %))
- (some #{java.lang.Deprecated})))
-
(defmethod deprecated :instance-method [expr]
- (->> expr
- :Expr-obj
- .method
- java-is-deprecated?))
+ (-> expr
+ :Expr-obj
+ .method
+ (.isAnnotationPresent java.lang.Deprecated)))
-(defmethod deprecated :new [expr]
- (->> expr
- :Expr-obj
- .ctor
- java-is-deprecated?))
+(defmethod deprecated :static-field [expr]
+ (-> expr
+ :Expr-obj
+ .field
+ (.isAnnotationPresent java.lang.Deprecated)))
-(defmethod deprecated :default [_]
- false)
+(defmethod deprecated :new [expr]
+ (-> expr
+ :Expr-obj
+ .ctor
+ (.isAnnotationPresent java.lang.Deprecated)))
+(defmethod deprecated :default [_] false)
(defmulti report-deprecated :op)
(defmethod report-deprecated :var [expr]
- (printf "%s is deprecated\n" (:var expr)))
+ (printf "Var '%s' is deprecated.\n"
+ (:var expr)))
(defmethod report-deprecated :instance-method [expr]
- (printf "Instance method \"%s\" is deprecated\n" (-> expr :Expr-obj .method)))
+ (printf "Instance method '%s' is deprecated.\n"
+ (-> expr :Expr-obj .method)))
+
+(defmethod report-deprecated :static-field [expr]
+ (printf "Static field '%s' is deprecated.\n"
+ (-> expr :Expr-obj .field)))
(defmethod report-deprecated :new [expr]
- (printf "Constructor \"%s\" is deprecated\n" (-> expr :Expr-obj .ctor)))
+ (printf "Constructor '%s' is deprecated.\n"
+ (-> expr :Expr-obj .ctor)))
(defn deprecations [exprs]
(doseq [expr exprs
Please sign in to comment.
Something went wrong with that request. Please try again.