Frequently I copy and paste code from my existing code base. Eclipse frequently brings in erroneous import statements that I don't need
example, I copy and paste code into my project package named com.myproject.utilities
into a file named twitter_class.java
and in the java file it adds
import com.pigmal.android.ex.twitter4j.TwitterConstants;
and this causes an error The import cannot be resolved
. Of course it can't why, why did it even attempt to import that part when I didn't even select that for copying
I can imagine places where this is convenient, but it is never convenient for me and it is time consuming to repair so often.
How do I turn this off, in Eclipse, using Eclipse.
Let Eclipse automatically organise imports whenever you save a file.
1. Go to the line of unused import, press Ctrl + 1, which is an Eclipse shortcut of a quick fix. This will show a drop-down menu to fix this error and one of them will be “remove unused imports.” It will remove that import statement from the Java file.
To enable this, go to Windows -> Preferences -> Java -> Editor -> Save Actions and then enable Perform the selected action on save -> Organize imports. After this, whenever you save a java file, eclipse will remove the unused imports automatically.
Press: CTRL + SHIFT + O and you should see below dialog boxes. Choose your desired import package and click next. It will prompt you for your next import and thats it.
To turnoff the auto import while pasting
windows > preference > java > editor > Typing > (Under when pasting) uncheck update imports
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With