|
74 | 74 | (.getName ^Class class-sym) |
75 | 75 | (throw (ex-info (str "Cannot resolve class: " class-part) {:class-name class-part})))) |
76 | 76 |
|
| 77 | +(defn- strip-generics |
| 78 | + "Strip generic type parameters: Map<K,V> -> Map" |
| 79 | + [type-str] |
| 80 | + (loop [result type-str] |
| 81 | + (let [next (str/replace result #"<[^<>]*>" "")] |
| 82 | + (if (= result next) |
| 83 | + result |
| 84 | + (recur next))))) |
| 85 | + |
77 | 86 | (defn- extract-params |
78 | 87 | "extract parameter types from a method signature: valueOf(char[] data) -> [char[]]" |
79 | 88 | [signature] |
80 | 89 | (let [params-str (->> signature |
81 | 90 | (drop-while #(not= % \()) |
82 | | - rest |
83 | | - (take-while #(not= % \))) |
84 | | - (apply str))] |
85 | | - (when-not (str/blank? params-str) |
| 91 | + rest |
| 92 | + (take-while #(not= % \))) |
| 93 | + (apply str)) |
| 94 | + params-no-generics (strip-generics params-str)] |
| 95 | + (when-not (str/blank? params-no-generics) |
86 | 96 | (mapv #(first (str/split (str/trim %) #"\s+")) |
87 | | - (str/split params-str #","))))) |
| 97 | + (str/split params-no-generics #","))))) |
88 | 98 |
|
89 | 99 | (defn- get-method-detail [^org.jsoup.nodes.Document doc method] |
90 | 100 | (let [method-signature (:signature method) |
|
123 | 133 | (and (= (count expanded-sig-types) (count expanded-param-strs)) |
124 | 134 | (every? (fn [[sig-type param-str]] |
125 | 135 | (or (= param-str "_") |
126 | | - (= sig-type param-str))) |
| 136 | + (= sig-type param-str) |
| 137 | + (= (strip-generics sig-type) (strip-generics param-str)))) |
127 | 138 | (map vector expanded-sig-types expanded-param-strs)))))) |
128 | 139 |
|
129 | 140 | (defn- method-matches? [signature method-name param-tags] |
|
137 | 148 | (defn- compress-array-syntax |
138 | 149 | "java to clojure param-tag syntax: String[][] -> String/2" |
139 | 150 | [java-type] |
140 | | - (cond |
141 | | - ;; arrays: String[][] -> String/2 |
142 | | - (str/includes? java-type "[]") (let [base-type (str/replace java-type #"\[\]" "") |
143 | | - dims (count (re-seq #"\[" java-type))] |
144 | | - (str base-type "/" dims)) |
145 | | - ;; varargs: Object... -> Object/1 |
146 | | - (str/ends-with? java-type "...") (str/replace java-type #"[.]{3}$" "/1") |
147 | | - :else java-type)) |
| 151 | + (let [raw-type (strip-generics java-type)] |
| 152 | + (cond |
| 153 | + ;; arrays: String[][] -> String/2 |
| 154 | + (str/includes? raw-type "[]") (let [base-type (str/replace raw-type #"\[\]" "") |
| 155 | + dims (count (re-seq #"\[" raw-type))] |
| 156 | + (str base-type "/" dims)) |
| 157 | + ;; varargs: Object... -> Object/1 |
| 158 | + (str/ends-with? raw-type "...") (str/replace raw-type #"[.]{3}$" "/1") |
| 159 | + :else raw-type))) |
148 | 160 |
|
149 | 161 | (defn- clojure-call-syntax |
150 | 162 | "javadoc signature to clojure param-tag syntax: valueOf(char[] data) -> ^[char/1] String/valueOf" |
|
0 commit comments