-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cljr-clean-ns when importing a deftype #194
Comments
Is this a problem even after loading the code into the repl, e.g. with C-c C-k? I just find it hard to believe that no-one has run into this until now! I suppose it makes some sense... Even after writing clojure professionally for some time I've yet to use the Thanks for reporting! |
If you manually load
I believe it. A common pattern with deftype (and other dynamically-generated java classes) is to provide a clojure function that wraps the class constructor. So consumers would require/refer the clojure function that constructs the type, rather than importing class. Another reason others might not have run into this is that often namespaces that have a deftype have other stuff in them which could cause that namespace to happen to be required before any of its generated classes are imported. Unfortunately in my case, I need to import the actual class and just the class to use as a type hint to avoid a costly reflection call. If I were hand-writing the namespace requires, I'd just keep the extra Another possible solution that is a little more general: we could have a way of marking requires as "do not remove" by (ns foo.c
(:require [foo.a]
^:cljr-keep [foo.b])) Just a thought. |
Just commenting here to note that this issue is still unrsolved, but I had an idea for how to resolve it. It's a bit of a heuristic, but I can't think of cases where it would go wrong. What if, when cleaning a namespace, we keep all requires that are substrings of any imported classes? For example, if we require |
Yeah, this is definitely solvable. We could also look for explicit constructor use. I just haven't gotten to this because I never write code like this. I always make a |
Fixed in refactor-nrepl 3.3.2 / clj-refactor.el 3.3.2 |
If namespace A has a deftype that is imported by namespace B, then namespace B needs to also require A, or the import could fail. For example:
If you run
cljr-clean-ns
ontest.b
, it will remove therequire
oftest.a
. Without that require, the(deftype MyType [])
is never evaluated, and loadingtest.b
will produce aClassNotFoundException
.Have other folks run into this / have a workaround?
One idea would be to add a rule to
cljr-clean-ns
: wheneverpath.to.SomeClass
is imported, and there is a clojure namespacepath.to
, then also requirepath.to
.Environment & Version information
The text was updated successfully, but these errors were encountered: