auto import adding full package name to the line Follow
Answered
When using auto-import via the Alt-Enter button, it gives me list of possible classes. When I click on one I expect it to add the class to the list of imports at the top of the page. Instead if changes the reference to the fully qualified name. Is there a way to switch this?
For example:
Foo foo = new Foo();
I want this to become:
import ack.bar.Foo;
Foo foo = new Foo();
but instead I get this:
ack.bar.Foo foo = new ack.bar.Foo();
Please sign in to leave a comment.
Make sure this option is not enabled:
That's not checked. My settings look similar except I have 5 and 3 respective for the counts.
Please share a sample project with the exact steps to reproduce.
What's the easiest way to do that? You want the actual IDEA project?
Here's the repository: https://github.com/strattonbrazil/munch
I'm using the sbt plugin, which may or may not be related. I get these kind of warnings for classes that are in the same package.
Before alt-enter:
after alt-enter:
Package statement doesn't correspond to the class location (package), hence the problem. Please fix it and imports will work.
I having the same problem with 2017.3 EAP.
alt-enter generates:
The package name matches the directory structure.
Hello Roger,
Could you please clarify what is wrong with the import? Also it would be great if you could provide sample project example.
I'm having the same problem.
https://github.com/jcbodnar/savings-bonds-bulk-importer
Updating my IntelliJ seems to have fixed the problem. I was using:
IntelliJ IDEA 2018.2.8 (Ultimate Edition)
Build #IU-182.5262.2, built on March 28, 2019
I upgraded to:
IntelliJ IDEA 2019.1.2 (Ultimate Edition)
Build #IU-191.7141.44, built on May 7, 2019
IntelliJ IDEA 2019.2.2 (Ultimate Edition)
Build #IU-192.6603.28, built on September 6, 2019
IDEA does not put a path to the import section if dependency is higher in the structure.
full_path
╚ src_folder
╠ dependency_class
╚ inner_folder
╚ file_with_dependecy_class
file_with_dependecy_class will have a variable with type <full_path.src_folder.dependency_class> and highlighted 'Unnecessarry qualified reference'. Action 'replace qualified name with import' do nothing.
Put import manually does not see src_folder, but as variable type sees correct.
Java doesn't support importing classes from the default package: https://stackoverflow.com/questions/283816/how-to-access-java-classes-in-the-default-package .
This is an acquired behavior because the project was obtained from the git repository with the correct view, but IDEA itself made changes to the import.
Same behavior for structure :
project
╚ src
╚ main
╚ java
╚ org
╚ project
╚ subfolder
╠ dependency_class
╚ inner_folder
╚ file_with_dependecy_class
Please upload the sample project at https://uploads.services.jetbrains.com/ and specify the file name.
I have the same problem on Ubuntu 19.04 with
IntelliJ IDEA 2019.2.3 (Ultimate Edition)
Build #IU-192.6817.14, built on September 24, 2019
For me it is when importing generated classes.
Fs, we'd appreciate a sample project to reproduce it, thanks.
I found the error. For some reason, Idea had messed up the folder structure. On disk the folder structure and package structure was identical for the generated classes, but in Idea the package structure skipped two levels of folders. Starting over and doing a new clone of the repo sorted it out.
I have no sample project to send in.
Hi, I have same issue
I already upload the demo project to https://uploads.services.jetbrains.com/
demo-spring-protobuf.zip
you can check AddPerson.java, and try to fix the import
here is correct import:
but IDEA always generate this
btw, I use Alt+enter to import.
Same problem here.
Henrik, could you please also share a sample project to show the problem that you have? There were multiple different problems mentioned in this thread so it's not clear which one you have.