Disable 'Optimize Imports' partially
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
public class MainClass {
public static String foo(String s) {
Deque<Character> st = new ArrayDeque<>();
List<Integer> loop = new ArrayList<>();
List<Integer> loop2 = new LinkedList<>(); <== Add
...
}
}
-------------------------------------------------------------------------------
import java.util.*;
public class MainClass {
public static String foo(String s) {
Deque<Character> st = new ArrayDeque<>();
List<Integer> loop = new ArrayList<>();
List<Integer> loop2 = new LinkedList<>();
...
}
}
IntelliJ optimizes import statements of same package to '*'. Is there any way to only disable this?
I think auto import/clear is great but this option works in situations I don't intend.
Please sign in to leave a comment.
Hello,
Do you mean that you need to keep the first state with four import statements? You could increase "Class count to use import with *" value in "File | Settings | Editor | Code Style | Java - Imports".
Thank you. Now it works as I intented.
But I have one more question. I set Insert imports on paste to All but IntelliJ always ask me if I want to insert imports when I paste the code.
How to change this configuration correctly?
I couldn't reproduce the issue on my machine. Do you face it with every project? Could you please share idea.log ("Help | Show Log in...") after restarting IDE?
I don't know if it's relevant, the issue has resolved after checking Add unambiguous imports on the fly option.
It works fine without this option on my machine. Could you please provide sample project example? Maybe it depends on project configuration?
https://drive.google.com/open?id=1ALiCphp_O2I-2xXjwrjORYJ_jYnhHCYG
Can you check any issues in my idea.log file?
No errors in log. So it should be fine. You could also try it with 2018.3.3 RC: https://confluence.jetbrains.com/display/IDEADEV/IDEA+2018.3+EAP
Found from stackoverflow (worked for me):
"Use single class import" does not prevent wildcard imports. The solution is to go to
Preferences
(⌘ + , on macOS / Ctrl + Alt + S on Windows and Linux)> Editor > Code Style > Java > Imports tab
setClass count to use import with '*'
andNames count to use static import with '*'
to a higher value. Any value over 99 seems to work fine.Hello, baum. Could you please specify which IDE version you use? I tried to reproduce the case in IntelliJIDEA 2023.1.3, but the IDE follows the Class count to use import with * option.