diff --git a/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy b/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy index 55e6042ab5ca..9f15da6d3dfd 100644 --- a/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy +++ b/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy @@ -16,6 +16,7 @@ package com.intellij.index import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.WriteAction import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.command.impl.CurrentEditorProvider import com.intellij.openapi.command.impl.UndoManagerImpl @@ -25,6 +26,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.fileTypes.PlainTextFileType +import com.intellij.openapi.module.StdModuleTypes import com.intellij.openapi.roots.ContentIterator import com.intellij.openapi.util.Ref import com.intellij.openapi.util.io.FileUtil @@ -39,6 +41,7 @@ import com.intellij.psi.impl.cache.impl.id.IdIndex import com.intellij.psi.impl.cache.impl.id.IdIndexEntry import com.intellij.psi.impl.file.impl.FileManagerImpl import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys +import com.intellij.psi.impl.source.JavaFileElementType import com.intellij.psi.impl.source.PostprocessReformattingAspect import com.intellij.psi.impl.source.PsiFileWithStubSupport import com.intellij.psi.search.EverythingGlobalScope @@ -50,6 +53,7 @@ import com.intellij.psi.stubs.StubIndexImpl import com.intellij.psi.stubs.StubUpdatingIndex import com.intellij.testFramework.IdeaTestUtil import com.intellij.testFramework.PlatformTestUtil +import com.intellij.testFramework.PsiTestUtil import com.intellij.testFramework.SkipSlowTestLocally import com.intellij.testFramework.exceptionCases.IllegalArgumentExceptionCase import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase @@ -615,4 +619,21 @@ class IndexTest extends JavaCodeInsightFixtureTestCase { StringUtil.replace(operation.get(), file.getPath(), file.getName()); } + + void "test files inside copied directory are indexed"() { + def facade = JavaPsiFacade.getInstance(project) + + def srcFile = myFixture.addFileToProject('foo/bar/A.java', 'class A {}') + assert facade.findClass('A', GlobalSearchScope.moduleScope(myModule)) != null + + def anotherDir = myFixture.tempDirFixture.findOrCreateDir('another') + def anotherModule = PsiTestUtil.addModule(project, StdModuleTypes.JAVA, 'another', anotherDir) + assert !facade.findClass('A', GlobalSearchScope.moduleScope(anotherModule)) + + WriteAction.run { srcFile.virtualFile.parent.copy(this, anotherDir, 'doo') } + + assert facade.findClass('A', GlobalSearchScope.moduleScope(anotherModule)) != null + assert JavaFileElementType.isInSourceContent(myFixture.tempDirFixture.getFile('another/doo/A.java')) + } + } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java index bd7b78ac2702..1310222eea24 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/PushedFilePropertiesUpdaterImpl.java @@ -39,6 +39,7 @@ import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.EmptyRunnable; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.newvfs.events.VFileCopyEvent; import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent; @@ -88,7 +89,10 @@ public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater boolean pushedSomething = false; List delayedTasks = ContainerUtil.newArrayList(); for (VFileEvent event : events) { - final VirtualFile file = event.getFile(); + VirtualFile file = event.getFile(); + if (event instanceof VFileCopyEvent) { + file = ((VFileCopyEvent)event).getNewParent().findChild(((VFileCopyEvent)event).getNewChildName()); + } if (file == null) continue; final FilePropertyPusher[] pushers = file.isDirectory() ? myPushers : myFilePushers; @@ -104,8 +108,8 @@ public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater else if (!ProjectUtil.isProjectOrWorkspaceFile(file)) { ContainerUtil.addIfNotNull(delayedTasks, createRecursivePushTask(file, pushers)); } - } else if (event instanceof VFileMoveEvent) { - for (FilePropertyPusher pusher : pushers) { + } else if (event instanceof VFileMoveEvent || event instanceof VFileCopyEvent) { + for (FilePropertyPusher pusher : pushers) { file.putUserData(pusher.getFileDataKey(), null); } // push synchronously to avoid entering dumb mode in the middle of a meaningful write action