Timothy Babin writes:
 > Hi,
 >      I found the java-open package written by Rajeev Karunakaran to be
 > quite useful and quick.
 > I have written some functions which use the same concept but use semantic to
 > get the import statements instead
 > of reg-ex. This is very usefull if you don't have class files for the source
 > that you are looking for and for speed.
 > It would be nice if this could be used to open class source files before
 > using the beanshell or if the user could
 > specifiy which method to use first. It would also be nice to then fallback
 > to using tags.
 > 

I've been working with Eric Ludlum to develop additions to semantic
that will integrate the Java classpath with semantic. By this I mean,
whenever you ask for information about a class, the JDEE will look
first in the semantic databases on your system and only resort to
the beanshell as a last resort. This will all be done transparently
so tha clients of the semantic database, such as the JDEE's completion
and go-to-symbol-def commands, never need to worry about where the
class information is located.

I've got a lot of the functionality implemented but have had to 
put the project on hold in order to make time to absorb a recent
spate of JDEE contributions and also because of work deadlines.

I expect to get back to this project in a few weeks.

- Paul

 > Let me know what you think.
 > 
 > 
 > (defun jde-custom-find-fqimport (import-list class)
 >   "Opens the source file for `class' if a fully qualified import statement
 > for
 > the class is found in `import-list' and returns t; returns nil otherwise.
 > Uses `jde-find-class-source' to open the file"
 >   (let ((current-import)
 >         (match-found nil)
 >         (iterator import-list))
 >     (while (and iterator (not match-found))
 >       (setq current-import (car (car iterator)))
 >       (message current-import)
 >       (if (string-match (concat ".*\\." class "\\'") current-import)
 >           (progn
 >             (if (not (jde-find-class-source current-import))
 >                 (message "Can't find source"))
 >             (setq match-found t)))
 >       (setq iterator (cdr iterator)))
 >     match-found
 >     )
 > )
 > 
 > (defun jde-custom-find-starimport (import-list class)
 >   "Opens the source file for `class' if a star import statement for
 > the class is found in `import-list' and returns t; returns nil otherwise.
 > Uses `jde-find-class-source' to open the file"
 >   (let ((current-import)
 >         (match-found nil)
 >         (iterator import-list))
 >     (while (and iterator (not match-found))
 >       (setq current-import (car (car iterator)))
 >       (message current-import)
 >       (if (string-match "\\(.*\\.\\)\\*" current-import)
 >           (progn
 >             (setq current-import (replace-match "\\1" t nil current-import))
 >             (message "found star import")
 >             (message current-import)
 >             (if (jde-find-class-source (concat current-import class))
 >                 (setq match-found t))))
 >       (setq iterator (cdr iterator)))
 >     match-found
 >     )
 > )
 >     
 > 
 > (defun jde-custom-open-class (&optional unqual-class)
 >    "Opens the source file for `class' if an import statement for
 > the class is found or the class is found in the current source file
 > directory or in java.lang.
 > Uses `jde-find-class-source' to open the file"
 >  (interactive)
 > ;;  (semantic-bovinate-toplevel t)
 >   (save-excursion
 >     (let* ((class (or unqual-class
 >                       (read-from-minibuffer "Class: " (thing-at-point
 > 'symbol))))
 >            (tokens (semantic-bovinate-toplevel t))
 >            (depends  (semantic-find-nonterminal-by-token 'include tokens)))
 >       (cond ((jde-custom-find-fqimport depends class))
 >             ((jde-custom-find-starimport depends class))
 >             ((progn
 >                ;; look for file in current directory
 >                (let ((fname (concat class ".java")))
 >                  (if (file-readable-p fname)
 >                      (progn (find-file fname)      ; open file in current
 > dir
 >                             (message "Opened %s" (expand-file-name
 > fname)))))))
 >             ((jde-find-class-source (concat "java.lang." class)))
 >             ((jde-open-class-source class))
 >             )
 >       )))
 > 
 > (defun jde-custom-open-class-at-point()
 >   (interactive)
 >   (jde-custom-open-class (current-word)))
 > 
 > 
 > 
 > 
 > Tim Babin
 > 
 > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
 > <HTML>
 > <HEAD>
 > <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
 > <META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2654.89">
 > <TITLE>Using semantic + import statement to open class source</TITLE>
 > </HEAD>
 > <BODY>
 > 
 > <P><FONT SIZE=2 FACE="Arial">Hi,</FONT>
 > <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Arial">I found the 
 >java-open package written by Rajeev Karunakaran to be quite useful and quick.</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">I have written some functions which use the same 
 >concept but use semantic to get the import statements instead</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">of reg-ex. This is very usefull if you don't have 
 >class files for the source that you are looking for and for speed.</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">It would be nice if this could be used to open class 
 >source files before using the beanshell or if the user could</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">specifiy which method to use first. It would also be 
 >nice to then fallback to using tags.</FONT>
 > </P>
 > 
 > <P><FONT SIZE=2 FACE="Arial">Let me know what you think.</FONT>
 > </P>
 > <BR>
 > 
 > <P><FONT SIZE=2 FACE="Arial">(defun jde-custom-find-fqimport (import-list 
 >class)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp; &quot;Opens the source file for `class' if a 
 >fully qualified import statement for</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">the class is found in `import-list' and returns t; 
 >returns nil otherwise.</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">Uses `jde-find-class-source' to open the 
 >file&quot;</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp; (let ((current-import)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >(match-found nil)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (iterator 
 >import-list))</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; (while (and iterator (not 
 >match-found))</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq current-import 
 >(car (car iterator)))</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (message 
 >current-import)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (if (string-match 
 >(concat &quot;.*\\.&quot; class &quot;\\'&quot;) current-import)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >(progn</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (if 
 >(not (jde-find-class-source current-import))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 > (message &quot;Can't find source&quot;))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq 
 >match-found t)))</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq iterator (cdr 
 >iterator)))</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; match-found</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; )</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">)</FONT>
 > </P>
 > 
 > <P><FONT SIZE=2 FACE="Arial">(defun jde-custom-find-starimport (import-list 
 >class)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp; &quot;Opens the source file for `class' if a 
 >star import statement for</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">the class is found in `import-list' and returns t; 
 >returns nil otherwise.</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">Uses `jde-find-class-source' to open the 
 >file&quot;</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp; (let ((current-import)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >(match-found nil)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (iterator 
 >import-list))</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; (while (and iterator (not 
 >match-found))</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq current-import 
 >(car (car iterator)))</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (message 
 >current-import)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (if (string-match 
 >&quot;\\(.*\\.\\)\\*&quot; current-import)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >(progn</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq 
 >current-import (replace-match &quot;\\1&quot; t nil current-import))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >(message &quot;found star import&quot;)</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >(message current-import)</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (if 
 >(jde-find-class-source (concat current-import class))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 > (setq match-found t))))</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq iterator (cdr 
 >iterator)))</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; match-found</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; )</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; </FONT>
 > </P>
 > 
 > <P><FONT SIZE=2 FACE="Arial">(defun jde-custom-open-class (&amp;optional 
 >unqual-class)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp; &quot;Opens the source file for `class' 
 >if an import statement for</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">the class is found or the class is found in the 
 >current source file</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">directory or in java.lang.</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">Uses `jde-find-class-source' to open the 
 >file&quot;</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;(interactive)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">;;&nbsp; (semantic-bovinate-toplevel t)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp; (save-excursion</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; (let* ((class (or 
 >unqual-class</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 > (read-from-minibuffer &quot;Class: &quot; (thing-at-point 'symbol))))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (tokens 
 >(semantic-bovinate-toplevel t))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >(depends&nbsp; (semantic-find-nonterminal-by-token 'include tokens)))</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cond 
 >((jde-custom-find-fqimport depends class))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >((jde-custom-find-starimport depends class))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >((progn</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 > ;; look for file in current directory</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 > (let ((fname (concat class &quot;.java&quot;)))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 > (if (file-readable-p fname)</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 > (progn (find-file fname)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; open file in current 
 >dir</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 > (message &quot;Opened %s&quot; (expand-file-name fname)))))))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >((jde-find-class-source (concat &quot;java.lang.&quot; class)))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >((jde-open-class-source class))</FONT>
 > <BR><FONT SIZE=2 
 >FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 >)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )))</FONT>
 > </P>
 > 
 > <P><FONT SIZE=2 FACE="Arial">(defun jde-custom-open-class-at-point()</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp; (interactive)</FONT>
 > <BR><FONT SIZE=2 FACE="Arial">&nbsp; (jde-custom-open-class (current-word)))</FONT>
 > </P>
 > <BR>
 > <BR>
 > <BR>
 > 
 > <P><FONT SIZE=2 FACE="Arial">Tim Babin</FONT>
 > </P>
 > 
 > </BODY>
 > </HTML>

Reply via email to