2

Given the following class:

package my.pack;

public class Foo {
    public static void varArgsMethod(Object ... arrr) {
    }
}

when analysing this using a Doclet, I get a MethodDoc for varArgsMethod, but the method isVarArgs returns false. Why doesn't it return true?

Code in Clojure:

(defn -start [^com.sun.javadoc.RootDoc root]
  (doseq [^com.sun.javadoc.ClassDoc c (.classes root)
          ^com.sun.javadoc.MethodDoc m (.methods c)]
    (try (println (.name m))
         (println "varargs:" (.isVarArgs m))
         (println "arity:" (count (.parameters m)))
         (println "return type:" (.returnType m))
         (catch Throwable e
           (println "something went wrong with" m))))
  true)

;; requires JDK 11 now: JAVA_HOME=~/Downloads/jdk-11.0.2.jdk/Contents/Home
(defn -main []
  (println (System/getProperty "java.home"))
  (let [dt (ToolProvider/getSystemDocumentationTool)]
    (.run dt nil nil nil
          (into-array ["-doclet" "clj_kondo.Doclet"
                       "-public"
                       "--source-path" "/tmp/"
                       "my.pack"]))))
Michiel Borkent
  • 34,228
  • 15
  • 86
  • 149
  • Completely random guess: could this have anything to do with the fact that Clojure treats Java var-arg methods as having a single array parameter? I wouldn't think the Clojure-end of it would have anything to do with the operation of `.isVarArgs`, but I also have no idea how that method works. Do you get different results when running the same code in Java? – Carcigenicate Apr 13 '19 at 16:23
  • I'd have to rewrite this to Java to test, but I hardly think this would be related. – Michiel Borkent Apr 13 '19 at 17:51
  • Ya, I don't either. It's just the only thing that came to mind. – Carcigenicate Apr 13 '19 at 18:28

0 Answers0