Search code examples
javaemacsintellij-ideaclojurecursive

Is there a clojure IDE can help autocomplete Java object method?


Is there a clojure IDE that can help autocomplete a Java object method?

For example:

(def my-temp-file (java.io.File/createTempFile "filename" ".txt"))

then i want to input:

(.deleteOnExit my-temp-file)

how can i :

(. my-temp-file delet|"cursor here") ;; how can i get auto-complate del* methods

or

(.delet|"cursor here" my-temp-file) ;; how can i get auto-complate del* methods

...

just now, I tried intellij14.1.4 + cursive0.1.60, it's wonderful.

i tried to auto-complate from "delete" to " deleteOnExist"

Situation 1 ,This is ok: Situation 1 ,This is ok:

Situation 2 ,this canot work : Situation 2 ,this canot work :

How can I get the "deleteOnExist" autocomplete in Situation 2? please help


Solution

  • The problem with your example is that def does not automatically add the :tag metadata based on the type of its initialiser. You can see this as follows:

    Connecting to local IDE...
    Clojure 1.7.0
    (import java.io.File)
    => java.io.File
    (def temp-file (File/createTempFile "filename" ".txt"))
    => #'user/temp-file
    temp-file
    => #object[java.io.File 0x6c8b97fd "/var/folders/x1/9k18lcbn4qnfs4pptm0dm8fm0000gn/T/filename8344242261832815384.txt"]
    (meta #'temp-file)
    => {:line 1, :column 1, :file "NO_SOURCE_PATH", :name temp-file, :ns #object[clojure.lang.Namespace 0x548b68c5 "user"]}
    

    So your example will work in cases like the following:

    (let [temp-file (File/createTempFile "filename" ".txt")]
      (temp-file .dele|))
    

    Where | represents the caret. It will also work if you manually add the tag to your def, like:

    (def ^File temp-file (File/createTempFile "filename" ".txt"))