Welcome! Please see the About page for a little more info on how this works.

–1 vote
in Records and Types by

Classes generated loaded by DynamicClassLoader return nil for .getPackage. Tools like CIDER and vim-fireplace are relying on this information to implement things like completion hints.

(.getPackage String) ;; => #<Package package java.lang, Java Platform API Specification, version 1.7> (deftype T []) (.getPackage T) ;; => nil

Proposed: During DynamicClassLoader.defineClass(), invoke definePackage() on the class being defined (similar to what URLClassLoader does).

Patch: clj-1550-v4.patch

Screened by: Alex Miller

19 Answers

0 votes

Comment made by: bozhidar

The original code can derive the package name in the same way the JVM grabs it, from the binary name. (Take the prefix up until the last period.)

I don't completely understand the workaround you're proposing. Can you elaborate on this?

I think this should get reverted, and let user space calculate the package from the binary name.

If that's working on newer JDKs with no changes needed in the user space and in Clojure, that's fine by me. By now I had lost faith that was going to be fixed in Clojure anyways. :-)

0 votes
_Comment made by: gshayban_


Took me a while to track it down, but instead of asking for the package name then grabbing the symbol, do this:

(defn package
  [^Class kls]
  (let [kls (.getName kls)
    idx (clojure.string/last-index-of kls \.)]
    (when (pos? idx)
      (subs kls 0 idx))))

0 votes

Comment made by: alexmiller

Patch reverted

0 votes
Reference: https://clojure.atlassian.net/browse/CLJ-1550 (reported by bozhidar)