1515 [clojure.test-helper :refer [should-not-reflect]])
1616 (:import
1717 #_(clojure.test SwissArmy ConcreteClass)
18- #_ (clojure.lang Tuple Compiler Compiler$CompilerException)
18+ (clojure.lang #_Tuple Compiler Compiler+CompilerException) ; ;; Compiler $CompilerException + commented out Tuple (overlap with System.Tuple )
1919 #_(java.util Arrays UUID Locale)))
2020
21+ (assembly-load-from " Clojure.Tests.Support.dll" )
22+ (import '[clojure.test SwissArmy])
23+
2124(set! *warn-on-reflection* true )
2225
2326(deftest no-hints-with-param-tags
7780; ; Mapping of symbols returned from reflect call to :parameter-type used as arguments to .getDeclaredMethod,
7881; ; :arg-type used as arguments to the methods and constructors being tested, :arg-tag used as arg-tags
7982; ; to the methods and constructors being tested.
80- #_ (def reflected-parameter-types {'int {:parameter-type Integer/TYPE
83+ (def reflected-parameter-types {'System.Int32 {:parameter-type Int32 ; ;; 'int Integer/TYPE
8184 :arg-type " (int 42)"
8285 :arg-tag " int" }
83- 'boolean {:parameter-type Boolean/TYPE
86+ 'System.Boolean {:parameter-type Boolean ; ;; 'boolean Boolean/TYPE
8487 :arg-type " true"
8588 :arg-tag " boolean" }
86- 'long {:parameter-type Long/TYPE
89+ 'System.Int64 {:parameter-type Int64 ; ;; 'long Long/TYPE
8790 :arg-type " 42"
8891 :arg-tag " long" }
89- 'long<> {:parameter-type (Class/forName " [J" )
92+ '|System.Int64[]| {:parameter-type |System.Int64[]| ; ;; 'long<> (Class/forName "[J")
9093 :arg-type " (long-array [1 2])"
91- :arg-tag " long*" }
92- 'int<><> {:parameter-type (Class/forName " [[I" )
93- :arg-type " (make-array Integer/TYPE 1 2)"
94- :arg-tag " int**" }
95- 'java.lang. Object<> {:parameter-type (Class/forName " [Ljava.lang.Object;" )
96- :arg-type " (into-array [1 2])"
97- :arg-tag " \" [Ljava.lang.Object;\" " }
98- 'java.lang. String<> {:parameter-type (Class/forName " [Ljava.lang.String;" )
94+ :arg-tag " longs " } ; ;; " long*"
95+ ; ;; 'int<><> {:parameter-type (Class/forName "[[I")
96+ ; ;; :arg-type "(make-array Integer/TYPE 1 2)"
97+ ; ;; :arg-tag "int**"}
98+ '|System. Object[]| {:parameter-type |System.Object[]| ; ;; 'System.Object<> java.lang.Object<> (Class/forName "[Ljava.lang.Object;")
99+ :arg-type " (into-array Object [1 2]) " ; ;; "(into-array [1 2])"
100+ :arg-tag " |System.Object[]| " } ; ;; " \"[Ljava.lang.Object;\""
101+ '|System. String[]| {:parameter-type |System.String[]| ; ;; 'System.String<> java.lang.String<> (Class/forName "[Ljava.lang.String;")
99102 :arg-type " (into-array [\" a\" \" b\" ])"
100- :arg-tag " \" [Ljava.lang.String;\" " }})
103+ :arg-tag " |System.String[]| " }}) ; ;; " \"[Ljava.lang.String;\"
101104
102- #_ (defn is-static-method? [class method-name params]
103- (let [method (.getDeclaredMethod ^Class class ^String (name method-name) ^ " [Ljava.lang.Object;" params)]
104- (java.lang.reflect.Modifier/isStatic (.getModifiers method)) ))
105+ (defn is-static-method? [class method-name params]
106+ (let [method (.GetMethod ^Type class ^String (name method-name) ^|System.Type[]| params)] ; ;; getDeclaredMethod ^Class ^ "[Ljava.lang.Object;"
107+ (.IsStatic method))) ; ;; ( java.lang.reflect.Modifier/isStatic (.getModifiers method))
105108
106- #_ (defn get-methods
109+ (defn get-methods
107110 " Reflect the class located at `path`, filter out the public members, add a :type
108111 of :constructor, :static, or :instance to each."
109112 [path]
110113 (let [reflected-class (r/reflect (resolve path))
111114 public (filter #(contains? (:flags %) :public ) (:members reflected-class))]
112115 (reduce (fn [res m]
113116 (let [class (-> m :declaring-class resolve)
114- params (into-array Class (map #(-> % reflected-parameter-types :parameter-type ) (:parameter-types m)))]
117+ params (into-array Type (map #(-> % reflected-parameter-types :parameter-type ) (:parameter-types m)))] ; ;; Class
115118 (cond
116119 (not (contains? m :return-type )) (conj res (assoc m :type :constructor ))
117120 (is-static-method? class (:name m) params) (conj res (assoc m :type :static ))
118121 :else (conj res (assoc m :type :instance )))))
119122 [] public)))
120123
121- #_ (defn exercise-constructor
124+ (defn exercise-constructor
122125 " Provided a map of data returned from a call to reflect representing a constructor.
123126 Construct a new instance of the class providing the appropriate arg-tags and return
124127 a map containing the new instance and expected target class"
125128 [{:keys [declaring-class parameter-types] :as m}]
126- (let [target-class (-> declaring-class str Class/forName)
129+ (let [target-class (-> declaring-class str clojure.lang.RT/classForName) ; ;; Class/forName
127130 args (str/join " " (map #(-> % reflected-parameter-types :arg-type ) parameter-types))
128131 arg-tags (str/join " " (map #(-> % reflected-parameter-types :arg-tag ) parameter-types))
129132 fun-call-str (read-string (str " (^[" arg-tags " ] " declaring-class " . " args " )" ))
130133 _ (should-not-reflect #(eval 'fun-call-str))
131134 new-instance (eval fun-call-str)]
132135 {:expected target-class :actual new-instance}))
133136
134- #_ (defn exercise-static-method
137+ (defn exercise-static-method
135138 " Provided a map of data returned from a call to reflect representing a static class method.
136139 Call the static method providing the appropriate arg-tags and return a map containing
137140 the actual and expected response."
146149 response (eval fun-call-str)]
147150 {:expected expected-response :actual response}))
148151
149- #_ (defn exercise-instance-method
152+ (defn exercise-instance-method
150153 " Provided a map of data returned from a call to reflect representing a class instance method.
151154 Call the method providing the appropriate arg-tags and return a map containing
152155 the actual and expected response."
160163 response (eval fun-call-str)]
161164 {:expected expected-response :actual response}))
162165
163- #_ (deftest arg-tags-in-constructors-and-static-and-instance-methods
166+ (deftest arg-tags-in-constructors-and-static-and-instance-methods
164167 (doseq [m (get-methods 'clojure.test.SwissArmy)]
165168 (case (:type m)
166169 :constructor (let [{:keys [expected actual]} (exercise-constructor m)]
170173 :instance (let [{:keys [expected actual]} (exercise-instance-method m)]
171174 (is (= expected actual))))))
172175
173- #_ (defmacro arg-tags-called-in-macro
176+ (defmacro arg-tags-called-in-macro
174177 [a-type b-type a b]
175178 `(^[~a-type ~b-type] SwissArmy/staticArityOverloadMethod ~a ~b))
176179
177- #_ (deftest arg-tags-in-macro
178- (is (= " int-int " (arg-tags-called-in-macro int int 1 2 ))))
180+ (deftest arg-tags-in-macro
181+ (is (= " System.Int32-System.Int32 " (arg-tags-called-in-macro int int 1 2 )))) ; ;; "int-int"
179182
180- #_(deftest bridge-methods
183+ #_(deftest bridge-methods ; ;; no concept of bridge methods
181184 (testing " Allows correct intended usage."
182185 (let [concrete (ConcreteClass. )]
183186 (is (= 42 (^[Integer] ConcreteClass/.stampWidgets concrete (int 99 ))))))
187190 (^[Object] ConcreteClass/.stampWidgets concrete (int 99 ))))))))
188191
189192
190- #_ (deftest incorrect-arity-invocation-error-messages
193+ (deftest incorrect-arity-invocation-error-messages
191194
192195 (testing " Invocation with param-tags having incorrect number of args"
193196 (let [e (try
194- (eval '(^[long] Math/abs -1 -2 -3 ))
195- (catch Compiler$ CompilerException e (str " -> " (.getMessage (.getCause e)))))]
197+ (eval '(^[long] Math/Abs -1 -2 -3 )) ; ;; Math/abs
198+ (catch Compiler+ CompilerException e (str " -> " (.Message (.InnerException e)))))] ; ;; Compiler$CompilerException .getMessage .getCause
196199 (is (not (nil? (re-find #"expected 1.*received 3" e))) " Error message was expected to indicate 1 argument was expected but 2 were provided" ))))
0 commit comments