|
175 | 175 | (defn- filter-methods [all-methods method-name param-tags] |
176 | 176 | (filterv #(method-matches? (:signature %) method-name param-tags) all-methods)) |
177 | 177 |
|
| 178 | +(defn- reflection-type-name [^Class c] |
| 179 | + (if (.isArray c) |
| 180 | + (str (reflection-type-name (.getComponentType c)) "[]") |
| 181 | + (.getSimpleName c))) |
| 182 | + |
| 183 | +(defn- reflection-params-match? [^java.lang.reflect.Method method param-tags] |
| 184 | + (let [param-type-names (mapv reflection-type-name (.getParameterTypes method))] |
| 185 | + (params-match? param-type-names param-tags))) |
| 186 | + |
| 187 | +(defn- find-declaring-class [^String class-name method-name param-tags] |
| 188 | + (let [klass (Class/forName class-name) |
| 189 | + name-matches? (fn [^java.lang.reflect.Method m] (= method-name (.getName m))) |
| 190 | + inherited? (fn [^java.lang.reflect.Method m] (not= class-name (.getName (.getDeclaringClass m)))) |
| 191 | + params-compatible? (fn [^java.lang.reflect.Method m] (or (nil? param-tags) (reflection-params-match? m param-tags))) |
| 192 | + matching (->> (.getMethods klass) |
| 193 | + (filter (fn [^java.lang.reflect.Method m] |
| 194 | + (and (name-matches? m) (inherited? m) (params-compatible? m)))))] |
| 195 | + (when-let [^java.lang.reflect.Method method (first matching)] |
| 196 | + (.getName (.getDeclaringClass method))))) |
| 197 | + |
178 | 198 | (defn- compress-array-syntax |
179 | 199 | "java to clojure param-tag syntax: String[][] -> String/2" |
180 | 200 | [java-type] |
|
249 | 269 | :class-description-md (when class-html (html-to-md class-html)) |
250 | 270 | :methods all-methods}] |
251 | 271 | (if method-part |
252 | | - (let [filtered (filter-methods all-methods method-part param-tags)] |
| 272 | + (let [filtered (filter-methods all-methods method-part param-tags) |
| 273 | + declaring-class (when (empty? filtered) |
| 274 | + (find-declaring-class class-name method-part param-tags))] |
253 | 275 | (assoc result :selected-method |
254 | | - (mapv #(get-method-detail doc %) filtered))) |
| 276 | + (cond |
| 277 | + (seq filtered) (mapv #(get-method-detail doc %) filtered) |
| 278 | + declaring-class (:selected-method (parse-javadoc (str declaring-class "/." method-part) param-tags)) |
| 279 | + :else []))) |
255 | 280 | result))) |
256 | 281 |
|
257 | 282 | (defn print-javadoc [{:keys [classname class-description-md selected-method]}] |
|
0 commit comments