Petter M�hl�n writes:
> Hi,
>
> I have a file with (at least) the following import statement:
>
> import java.util.*;
>
> If I then ask JDE to import java.util.List, a new statement will be
> added:
>
> import java.util.*;
> import java.util.List;
>
> The second statement is of course redundant. I think I have traced the
> problem to:
>
> (defun jde-import-strip-existing-imports (new-imports existing-imports)
> "Exclude classes that have already been imported."
> (let (i n return-imports)
> (setq i 0)
> (setq n (length new-imports))
> (while (< i n)
> ;;iterate through the new imports
> (let((new-import
> (nth i new-imports)))
> ;;Strip out those alreay there
> (when (not (find new-import existing-imports :test 'string=))
> (setq return-imports (nconc (list new-import)
> return-imports))))
> (setq i(+ i 1)))
> ;;Return any that still exist
> return-imports))
>
> The comparison test 'string= should probably be changed to a test that
> matches if:
>
> - there is an exact string match, or
> - if "packagename.*" is imported (but not if "packagename.subpackage.*"
> is imported)
>
> That should not be too hard to do with a regexp, I guess, but I am not
> sure how to actually do it. Any elisp-literate people out there who can
> solve it?
>
Hi Petter,
Try this:
(defun jde-import-strip-existing-imports (new-imports existing-imports)
"Exclude classes that have already been imported."
(delq
nil
(mapcar
(lambda (new-import)
(unless
(find
new-import
existing-imports
:test (lambda (new existing)
(let ((new-package (jde-parse-get-package-from-name new))
(new-class (jde-parse-get-unqualified-name new))
(existing-package (jde-parse-get-package-from-name existing))
(existing-class (jde-parse-get-unqualified-name existing)))
(and
(string= new-package existing-package)
(or
(string= new-class existing-class)
(string= existing-class "*"))))))
new-import))
new-imports)))
- Paul