At 12:07 PM 5/5/99 -0700, Ramkarthik Kalyanasundaram wrote:
>
>Paul Kinnucan <[EMAIL PROTECTED]> writes:
>
>
>]Meanwhile, if you haven't already, I'd suggest playing with the new JDE
>]2.1.5 command, jde-wiz-import (C-c C-v C-z). This command prompts you to
>]enter the qualified name of the class to import. It then generates the
>]import statement at the top of the buffer or after any existing import
>]statements. I use the command a lot.
>
>I was thinking that something along the lines of jde-wiz-import, without the 
>qualification condition, maybe better i.e. you don't enter a fully qualified 
>class. The wizard instead allows you to specify just the classname and does 
>the import(defaulting to something at point perhaps). Typically, the wizard 
>would search the jde-compile-option-classpath. 
>            One problem that I came up against is zip/jar files. The only 
>solution to this, that I could think of, was to use the jar command to list 
>the files in the various jar files and store the output on disk. Ofcourse, 
>entries in classpath that aren't jar files will be scanned every time.
>
>   My contention is that contents of your classpath(read jar files) do not 
>change that often. So you should be able to generate this listing when there 
>is a change.
>

Actually, this should not be too difficult to implement almost entirely in
Java. You can get the classpath from System.properties. For any zip or jar
entries on the classpath, you can get easily get all the entries, using the
JDK's JarFile class. Thus, the algorithm would be something like:

1.  Get class name from user.

2. Get classpath from System.properties.

3. Iterate through the classpath.

   a. Get contents of each classpath entry, using one of the following methods:

      Entry n == directory ? Use File.list() method.
      Entry n == jar file ? Use JarFile.entries() method.
      Entry n == zip file ? Use ZipFile.entries() method.

    b. If any of the entries has the same root name as the target class, go
to next step.

4. Construct the fully qualified class name from the path of the found
class (and/or source file if source
    directories are included on the classpath).

This could be implemented as a static method of a Java class (e.g.,
ImportWizard class) that could be invoked from Emacs via the Beanshell, e.g.,

   (setq import-statement
      (bsh-eval-r
"jde.wizards.ImportWizard.makeImportStatement(\"Graphics2D\");"))

If anyone is interested in creating such an ImportWizard class, I'd be glad
to write the elisp interface to it (actually just plug it into the current
jde-wizard-import command). The class should have one static method that
accepts the name of the class to be imported, e.g., Graphics2D, and returns
the import statement by writing it to standard out as follows:

    System.out.print("\"import java.awt.Graphics2D;\""  + "\n");
    System.out.flush();

Note the quotes around the import statement. This is necessary because to
allow the JDE's bsh-eval-r function to evaluate it as a string. 

If there are no takers, I'll implement this at some point.

- Paul




    

Reply via email to