Reputation:
Is there a tool/library that allows me to import the java packages automatically outside the IDE?
For instrance if I type in notepad something like:
JFrame f = new JFrame();
Then run this magic tool, and then have automatically written as:
import javax.swing.JFrame
....
JFrame f = new JFrame();
Is there something like that? This is what comes to my mind as sample usage:
import java.io.File;
public class TesteImport {
public static void main(String[] args) {
AutoImport autoImport = new AutoImport();
File clazz = new File("SampleClazz.java");
autoImport.setImportClass(clazz);
autoImport.addLib("LibA.jar");
autoImport.addLib("LibB.jar");
autoImport.importAll();
}
}
Upvotes: 0
Views: 231
Reputation: 11085
Even if there is such a tool, it won't work always automatically without user input.
If you have for example this code:
List myList;
It has to ask, if the List
should be from java.awt.List
or java.util.List
.
Upvotes: 1
Reputation: 62789
What you are asking for is a tool that will modify your source code outside of the IDE. That's really not a good idea--codegen always ends up sucking, no matter how cool and limited it seems at first.
The only decent case for code generation is where the programmer NEVER sees the intermediate version--this happens with C preprocessor--it makes an intermediate pre-processed version that you never see.
That said, what you might want is something like Groovy. IIRC, groovy allows something like "import *" for import everything.
The thing is, Java is more of a professional tool--you really don't WANT it doing tricky things. Many Java programmers don't even like "import java.util.*" and insist on expanding the exact imports so that you know exactly where each class is coming from.
With lighter languages like groovy, ruby, etc this isn't really as much of a problem--being terse is more important.
PS. If you have to use Java, honestly the answer is no, there is no good solution outside the development environment GUI. Embrace your GUI.
Upvotes: 0
Reputation: 162851
In Eclipse, you have Crtl-Shift-O (or Command-Shift-O on a mac). Perhaps you could dig into the Eclipse source code (open source) and find the Java code that drives this feature and re-use it. Good luck!
Upvotes: 0