From 5a2f1ca65f4f15cda1a50d262b281aaace3abd4b Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Mon, 28 Apr 2014 13:47:19 +0400 Subject: [PATCH] Add package directive with fileName for InspectionTests to avoid names clashing --- .../codeInsight/AbstractJetInspectionTest.kt | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractJetInspectionTest.kt b/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractJetInspectionTest.kt index 139d6395413..71d613b3c7e 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractJetInspectionTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractJetInspectionTest.kt @@ -49,23 +49,28 @@ public abstract class AbstractJetInspectionTest: LightCodeInsightFixtureTestCase val inspectionsTestDir = optionsFile.getParentFile()!! val srcDir = inspectionsTestDir.getParentFile()!! - with(myFixture!!) { + with(myFixture) { setTestDataPath("${JetTestCaseBuilder.getHomeDirectory()}/$srcDir") - val virtualFiles = srcDir + val psiFiles = srcDir .listFiles { it.getName().endsWith(".kt") }!! - .map { configureByFile(it.getName())!!.getVirtualFile()!! } + .map { + file -> + val text = FileUtil.loadFile(file, true) + val fileText = if (text.startsWith("package")) text else "package ${file.getName().trimTrailing(".kt")};$text" + configureByText(file.getName(), fileText)!! + } - val isWithRuntime = virtualFiles.any({ file -> - InTextDirectivesUtils.findStringWithPrefixes(String(file.contentsToByteArray(), "utf-8"), "// WITH_RUNTIME") != null + val isWithRuntime = psiFiles.any({ file -> + InTextDirectivesUtils.findStringWithPrefixes(file.getText(), "// WITH_RUNTIME") != null }) try { if (isWithRuntime) { - ConfigLibraryUtil.configureKotlinRuntime(myFixture!!.getModule(), getFullJavaJDK()); + ConfigLibraryUtil.configureKotlinRuntime(myFixture.getModule(), getFullJavaJDK()); } - val scope = AnalysisScope(getProject(), virtualFiles) + val scope = AnalysisScope(getProject(), psiFiles.map { it.getVirtualFile()!! }) scope.invalidate() val inspectionManager = (InspectionManager.getInstance(getProject()) as InspectionManagerEx) @@ -76,7 +81,7 @@ public abstract class AbstractJetInspectionTest: LightCodeInsightFixtureTestCase } finally { if (isWithRuntime) { - ConfigLibraryUtil.unConfigureKotlinRuntime(myFixture!!.getModule(), IdeaTestUtil.getMockJdk17()); + ConfigLibraryUtil.unConfigureKotlinRuntime(myFixture.getModule(), IdeaTestUtil.getMockJdk17()); } } }