> >>>>> "Petter" == Petter M�hl�n <[EMAIL PROTECTED]> writes:
>
> Petter> Found another little nit to pick. I have a class named
> Petter> "Task", and when I run jde-import-all for that class, I am
> Petter> prompted to import some class named sun.something.Task. I am
> Petter> not enough of an elisp person to see how, but maybe
> Petter> jde-import-all-expand-strip-exclude should exclude the
> Petter> current class as well?
>
>
> The functions that actually do the import come from JDEE core itself
> rather than me. In this case the `jde-import-excluded-packages'
> variable should do what you want (exclude sun.* classes).
>
> The current class, and classes in the current package should already
> be excluded. If this isn't happening then its a bug but probably not
> mine.
Aha, I saw it slightly differently: if I am presently working on a class
called Task, and the jde-import-all finds an unqualified name of Task, it
shouldn't bother trying to import it. That's why I suggested that the
current class should be removed before even looking for classes to import.
Anyway, I looked into it (and realised that maybe one of these days I am
going to have to drop my claim of not knowing any elisp... terrible
thought), and came up with the below possible solution, which seems to work
as far as I can tell. Would that make sense to you?
By the way, I am afraid I came up with another case that doesn't quite work,
and which I think may be difficult to catch with a regexp: calling a static
method in another class, like:
Logger.getLogger();
Maybe a regexp that assumes that something that starts with a capital
letter, followed by a dot is a class to be imported? A bit shaky to me.
Still, even without it, this is a command that I will be using a lot.
/ Petter
(defun jde-import-all-expand-strip-exclude(list)
"Qualifies, strips and excludes imports.
This function takes in a list of imports. It removes all the existing
imports, qualifies them and then strips excluded imports. It returns a
list of lists of strings. And all in one function."
(delq nil
(mapcar
(lambda(unqualified-class)
;; we want to remove any imports which already exists and also
;; not bother with the current class
(if (or (jde-import-get-existing-import unqualified-class)
(string-match unqualified-class
(file-name-sans-extension
(file-name-nondirectory (buffer-file-name)))))
nil
(jde-import-exclude-imports
;; we want to kill of the java.lang
;; packges. exclude-imports will probably do this for
;; us. But this is not good as it will leave the other
;; possibilities. So "String" will be imported as
;; "apache.xpath.String" (on my machine) which is almost
;; exactly the wrong behaviour
;;
;; I'm not really happy with this but what can you do.
(jde-import-all-kill-lang-classes
;; we want to expand any unqualified names, this returns
;; a list of string possibilities
(jde-jeval-r
(concat "jde.util.JdeUtilities.getQualifiedName(\""
unqualified-class "\");"))))))
list)))