Petter M�hl�n writes:
> Hi,
>
> jde-import-all is a function that I really want to work well, I think it is
> potentially extremely useful. At the moment, though, it suffers from a big
> drawback to me: it keeps importing obscure classes if they are on the
> classpath and are named String or Object or something else from java.lang.
> In almost all cases, that is undesirable, I think. I have made a
> modification which seems to work, although I think it is highly unelegant
> lisp. Maybe somebody could improve it? A second problem is that if you don't
> choose any entry in a list group, a empty import statement ("import ;") will
> be entered. I made a minor modification to
> jde-import-insert-imports-into-buffer to avoid that.
>
Hi Petter,
I'm aware of the first problem. I'll take a look at your solution. Meanwhile
a workaround (which I use) is to set jde-import-exclude-imports to filter
out the undersirable apache classes.
Paul
> / Petter
>
> ------- fix 1:
> (defun jde-import-all-filter (unqualified-imports)
> "Generate a list of fully qualified names of classes to
> import from UNQUALIFIED-IMPORTS, excluding classes specified
> by `jde-import-exclude-imports'."
> (delq
> nil
> (mapcar
> (lambda(unqualified-class)
> (let ((qualified-classnames (jde-jeval-r
> (concat
>
> "jde.util.JdeUtilities.getQualifiedName(\""
> unqualified-class "\");"))))
> (if (jde-import-all-skip-all qualified-classnames)
> nil
> (jde-import-exclude-imports qualified-classnames))))
> unqualified-imports)))
>
> (defun jde-import-all-skip-all (imports)
> "Returns non-nil if all the imports should be skipped,
> and nil otherwise."
> (let ((skip (catch 'found
> (loop for import in imports do
> (if (string-match "^java\\.lang\\.[^.]*$" import)
> (throw 'found import))))))
> ;; report the skipped imports if any
> (if skip
> (progn (loop for import in imports do
> (message "Excluding %s!!" import))))
> skip))
> ------
>
> ------ fix 2:
> (defun jde-import-insert-imports-into-buffer (new-imports &optional exclude)
> "Inserts imports into the correct place in the buffer."
> (save-excursion
> (goto-char (jde-import-get-import-insertion-point))
> (if (not jde-xemacsp) (deactivate-mark))
> (if exclude
> (setq new-imports (jde-import-exclude-imports new-imports)))
> (loop for new-import in new-imports do
> (if (> (length new-import) 0) ;; added to avoid insert empty
> import statement
> (progn
> (insert
> (concat "import " new-import ";\n"))
> (message "Imported %s" new-import))))
> (if jde-import-auto-collapse-imports
> (let (jde-import-auto-collapse-imports) ;; setting this to avoid
> infinite recursion
> (jde-import-collapse-imports)))
> (if jde-import-auto-sort
> (funcall jde-import-auto-sort-function))))
>