Search code examples
android-studiointellij-ideacode-completion

IntelliJ IDEA shows deleted files and packages in code completion


I have changed the structure of the packages of my project. I have created new packages, moved some files into the new packages and deleted the empty packages where the files had been.

Now the problem is that the code completion shows some of the files twice, there is the new correct version and the old version with the old package structure. Let me give to examples:

  1. I had a class (file) "ButtonBuilder" in the package "component.builders.gui". Then I moved the "ButtonBuilder" into the package "component.builders.gui.button". When I now type somewhere "ButtonBuilder" the code completion suggests two versions, the first one is "ButtonBuilder (component.builders.gui)" and the second is "ButtonBuilder component.builders.gui.button)", but there is no file / class named "ButtonBuilder" in "component.builders.gui".

  2. The second example is similar, when I type "DefaultPhysicComponent" the code completion gives two options, "DefaultPhysicComponent (component.components.physic)" and "DefaultPhysicComponent (components.physicComponents)". The first one is correct but the second does not exist. The class / file "DefaultPhysicComponent" was at first in "components.physicComponents", then I created the new packages "component.components.physic", moved the file there and deleted the old packages. Now there does not even exist a package "physicComponents", but the code completion gives these two options.

There are also other files and packages with the same problem. So somehow the IDE "thinks" that the old packages and files still exists. This also yields another problem with the imports. When I import for example

import component.builders.gui.button.*;

and

import component.builders.gui.*;

the IDE says that the reference to "ButtonBuilder" is ambiguous, but as said above there exists only one file / class "ButtonBuilder".

Does anyone know how to fix this?


Solution

  • Under File > Preferences > Compiler check that this option: "Clear output directory on rebuild" is selected.

    Then rebuild your project using Build > Rebuild Project

    If the problem is still occurring after that then invalidate caches, using File > Invalidate Caches / Restart then click on the Invalidate button.