diff --git a/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt b/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt index d5aec1156d8..d47cd91a77f 100644 --- a/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt +++ b/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.test @@ -32,13 +21,18 @@ import com.intellij.openapi.startup.StartupManager import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess +import com.intellij.psi.PsiManager +import com.intellij.psi.search.FileTypeIndex +import com.intellij.psi.search.ProjectScope import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.LoggedErrorProcessor import org.apache.log4j.Logger import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode import org.jetbrains.kotlin.idea.facet.configureFacet import org.jetbrains.kotlin.idea.facet.getOrCreateFacet +import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.TestMetadata @@ -193,3 +187,10 @@ fun configureLanguageVersion(fileText: String, project: Project, module: Module) } } } + +fun Project.allKotlinFiles(): List { + val virtualFiles = FileTypeIndex.getFiles(KotlinFileType.INSTANCE, ProjectScope.getProjectScope(this)) + return virtualFiles + .map { PsiManager.getInstance(this).findFile(it) } + .filterIsInstance() +} diff --git a/idea/src/org/jetbrains/kotlin/idea/project/PluginJetFilesProvider.java b/idea/src/org/jetbrains/kotlin/idea/project/PluginJetFilesProvider.java deleted file mode 100644 index fd4ebfac4a2..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/project/PluginJetFilesProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.project; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.search.GlobalSearchScope; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.stubindex.KotlinExactPackagesIndex; -import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope; -import org.jetbrains.kotlin.psi.KtFile; - -import java.util.ArrayList; -import java.util.Collection; - -public class PluginJetFilesProvider { - - @NotNull - public static Collection allFilesInProject(@NotNull Project project) { - Collection result = new ArrayList(); - GlobalSearchScope scope = KotlinSourceFilterScope.sources(GlobalSearchScope.allScope(project), project); - for (String packageWithFiles : KotlinExactPackagesIndex.getInstance().getAllKeys(project)) { - result.addAll(KotlinExactPackagesIndex.getInstance().get(packageWithFiles, project, scope)); - } - return result; - } - - private PluginJetFilesProvider() { - } -} diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesMultiModuleTest.kt b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesMultiModuleTest.kt index 801ecc30976..8fb318fc36c 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesMultiModuleTest.kt +++ b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesMultiModuleTest.kt @@ -1,26 +1,15 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.findUsages import com.intellij.codeInsight.TargetElementUtil import com.intellij.testFramework.UsefulTestCase -import org.jetbrains.kotlin.idea.project.PluginJetFilesProvider import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest import org.jetbrains.kotlin.idea.test.PluginTestCaseBase +import org.jetbrains.kotlin.idea.test.allKotlinFiles import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.test.InTextDirectivesUtils @@ -29,7 +18,7 @@ abstract class AbstractFindUsagesMultiModuleTest : AbstractMultiModuleTest() { override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/multiModuleFindUsages/" protected fun doFindUsagesTest() { - val allFilesInProject = PluginJetFilesProvider.allFilesInProject(myProject!!) + val allFilesInProject = project.allKotlinFiles() val mainFile = allFilesInProject.single { file -> file.text.contains("// ") } diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java index 27f2e2351a0..e484a5f6b52 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractPositionManagerTest.java @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.debugger; @@ -46,8 +35,8 @@ import org.jetbrains.kotlin.config.CompilerConfiguration; import org.jetbrains.kotlin.config.JVMConfigurationKeys; import org.jetbrains.kotlin.descriptors.PackagePartProvider; import org.jetbrains.kotlin.idea.debugger.evaluate.KotlinDebuggerCaches; -import org.jetbrains.kotlin.idea.project.PluginJetFilesProvider; import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase; +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCaseKt; import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor; import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; import org.jetbrains.kotlin.psi.KtFile; @@ -134,7 +123,7 @@ public abstract class AbstractPositionManagerTest extends KotlinLightCodeInsight private void performTest() { Project project = getProject(); - List files = new ArrayList<>(PluginJetFilesProvider.allFilesInProject(project)); + List files = new ArrayList<>(KotlinLightCodeInsightFixtureTestCaseKt.allKotlinFiles(project)); if (files.isEmpty()) return; List breakpoints = Lists.newArrayList(); diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinNavigationMultiModuleTest.kt b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinNavigationMultiModuleTest.kt index 2ef11b46ee9..49277584ea5 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinNavigationMultiModuleTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinNavigationMultiModuleTest.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.navigation @@ -23,9 +12,9 @@ import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiFile import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.TargetPlatformKind -import org.jetbrains.kotlin.idea.project.PluginJetFilesProvider import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest import org.jetbrains.kotlin.idea.stubs.createFacet +import org.jetbrains.kotlin.idea.test.allKotlinFiles import org.jetbrains.kotlin.idea.test.extractMarkerOffset abstract class AbstractKotlinNavigationMultiModuleTest : AbstractMultiModuleTest() { @@ -46,7 +35,7 @@ abstract class AbstractKotlinNavigationMultiModuleTest : AbstractMultiModuleTest implModule.addDependency(commonModule) } - val file = PluginJetFilesProvider.allFilesInProject(myProject).single { it.name == testFileName } + val file = project.allKotlinFiles().single { it.name == testFileName } val doc = PsiDocumentManager.getInstance(myProject).getDocument(file)!! val offset = doc.extractMarkerOffset(project, "") val editor = EditorFactory.getInstance().createEditor(doc, myProject) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixMultiModuleTest.kt b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixMultiModuleTest.kt index 30ebf35702d..957be43528c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixMultiModuleTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixMultiModuleTest.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.quickfix @@ -23,12 +12,11 @@ import com.intellij.openapi.command.CommandProcessor import junit.framework.ComparisonFailure import junit.framework.TestCase import org.jetbrains.kotlin.idea.inspections.findExistingEditor -import org.jetbrains.kotlin.idea.project.PluginJetFilesProvider import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils import org.jetbrains.kotlin.idea.test.PluginTestCaseBase +import org.jetbrains.kotlin.idea.test.allKotlinFiles import org.jetbrains.kotlin.idea.util.module -import org.jetbrains.kotlin.idea.util.sourceRoot import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils @@ -39,7 +27,7 @@ abstract class AbstractQuickFixMultiModuleTest : AbstractMultiModuleTest() { override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/multiModuleQuickFix/" protected fun doQuickFixTest() { - val allFilesInProject = PluginJetFilesProvider.allFilesInProject(myProject!!) + val allFilesInProject = project.allKotlinFiles() val actionFile = allFilesInProject.single { file -> file.text.contains("// \"") } diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt b/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt index b1ff3cbf3cc..4981b6d91bb 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractMultiModuleTest.kt @@ -26,10 +26,10 @@ import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider import org.jetbrains.kotlin.config.TargetPlatformKind import org.jetbrains.kotlin.idea.facet.getOrCreateFacet import org.jetbrains.kotlin.idea.facet.initializeIfNeeded -import org.jetbrains.kotlin.idea.project.PluginJetFilesProvider import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor import org.jetbrains.kotlin.idea.test.PluginTestCaseBase +import org.jetbrains.kotlin.idea.test.allKotlinFiles import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.TestJdkKind import org.junit.Assert @@ -96,7 +96,7 @@ abstract class AbstractMultiModuleTest : DaemonAnalyzerTestCase() { protected fun checkFiles(shouldCheckFile: () -> Boolean = { true }, check: () -> Unit) { var atLeastOneFile = false - PluginJetFilesProvider.allFilesInProject(myProject!!).forEach { file -> + myProject.allKotlinFiles().forEach { file -> configureByExistingFile(file.virtualFile!!) if (shouldCheckFile()) { atLeastOneFile = true