Re: Bugs introduced that affected jde-import-all (reparse after insert import)

"Jeff Peck" <[email protected]>
Newsgroups gmane.emacs.jdee.devel
Message-ID <F253749855A349F8A8FF7F85610855B1@blue>
Eric,
  Once again, thanks for the info; 
For those who are following along at home, i'll include the two functions of interest.
(and the patch to create them from 2.4.0 svn-191)
And it all works pretty much as you expect and describe.
The only deviation is that I find jde-insert-imports-into-buffer requires both of:
     (semantic-fetch-tags)  (semantic-parse-changes)
In order that then next/subsequent usage of jde-insert-imports-into-buffer
actually sees the previously inserted import lines. 
A simple call to (semantic-fetch-tags) does not seem to notice the new import statements.
(and not seeing them, the logic in jde-insert-imports-into-buffer inserts a *new* copy of the imports)
Given the file:
package foo;
public class Foo {
 Map foo = new HashMap();
}

jde-import-get-insertion-point first gets "tags" as:
tags = ((foo package nil (reparse-symbol package_declaration) #<overlay from 1 to 13 in Foo.java>)
        (Foo type (:typemodifiers (public) ... class_declaration... )) #<overlay from 14 to 60 in Foo.java>))
And then inserts two import lines (and highlight-edits shows no highlighting):
package foo;
import java.util.HashMap;
import java.util.Map;
public class Foo {
 Map foo = new HashMap();
}

and then call jde-insert-import-into-buffer again; now, jde-import-get-insertion-point gets "tags" as:
tags = ((foo package nil (reparse-symbol package_declaration) #<overlay from 1 to 13 in Foo.java>)
 (java.util.HashMap include nil ... import_delaration ... #<overlay from 14 to 39 in Foo.java>)
 (java.util.Map include nil (reparse-symbol import_declaration) #<overlay from 40 to 61 in Foo.java>)
 (Foo type (:typemodifiers (public) ... class_declaration...)) #<overlay from 62 to 108 in Foo.java>))

Note: without adding (semantic-fetch-tags)  (semantic-parse-changes), 
the import_declaration tags are not found, leaving a "hole" between 13 and 62:
tags = ((foo package nil (reparse-symbol package_declaration) #<overlay from 1 to 13 in Foo.java>)
        (Foo type (:typemodifiers (public) :members ... class_declaration #<overlay from 62 to 108 in Foo.java>))

As you say, the speed of reparse is not an issue, and with this patch, the logic works just fine.
For those that are curious, here are the two functions involved:

(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
          (when (> (length new-import) 0) ; added to avoid insert empty import statements.
            (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))
    (semantic-fetch-tags)       ; add these two lines
    (semantic-parse-changes)    ; to avoid duplicate inserts
    ))

(defun jde-import-get-import-insertion-point ()
  "Determine where to insert an import statement.
If the buffer contains an import statement, return
the beginning of the next line; otherwise, if
the buffer contains a package statement, insert
three empty lines and return the beginning of
the second empty line; otherwise, if the buffer
contains a class definition, return the beginning
of the line before the class definition; otherwise,
return the beginning of the buffer."
  (flet ((insertion-point-after (tag-end)
          (save-excursion
            (goto-char tag-end)
            (if (eolp) (forward-char 1)(forward-line 1)) ;skip comment
            (unless (bolp) (insert "\n"))                ;open empty line
            (point)
            )))
    (let* ((tags (semantic-fetch-tags))    ; (xx (message "tags = %s" tags))
           (import-tag (car
                        (last (semantic-brute-find-tag-by-class
                               'include tags))))
           (package-tag (car (semantic-brute-find-tag-by-class
                              'package tags)))
           (class-tag (car (semantic-brute-find-tag-by-class
                            'type tags)))
           )
      (cond (import-tag
             (insertion-point-after (semantic-tag-end import-tag)))
            (package-tag
             (insertion-point-after (semantic-tag-end package-tag)))
            (class-tag
             (let ((comment-token (semantic-documentation-for-tag
                                   class-tag 'lex)))
               (if comment-token
                   (semantic-lex-token-start comment-token)
                 (semantic-tag-start class-tag))))
            (t 1))
      )))

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev

_______________________________________________
jdee-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jdee-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.