From 6cb556dd6bc4b8ac2302582df104e007fd19dc7d Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Thu, 26 Oct 2017 14:09:48 +0300 Subject: [PATCH] AbstractQuickFixTest: `FORCE_PACKAGE_FOLDER` directive added It was added as workaround for IDEA-176033 (IDEA-176032 in particular) --- .../idea/quickfix/AbstractQuickFixTest.kt | 20 +++++++++++++++++-- .../addQualifierAnnotation/ambiguousBean.kt | 3 +++ .../ambiguousBean.kt.after | 3 +++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt index 1fe18888042..d5f33a2652a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt @@ -70,6 +70,13 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() { } + private fun getPathAccordingToPackage(name: String, text: String): String { + val packagePath = text.lines().let { it.find { it.trim().startsWith("package") } } + ?.removePrefix("package") + ?.trim()?.replace(".", "/") ?: "" + return packagePath + "/" + name + } + private fun doKotlinQuickFixTest(beforeFileName: String) { val testFile = File(beforeFileName) CommandProcessor.getInstance().executeCommand(project, { @@ -87,13 +94,22 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() { expectedErrorMessage = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// SHOULD_FAIL_WITH: ") val contents = StringUtil.convertLineSeparators(fileText) - myFixture.configureByText(testFile.canonicalFile.name, contents) + var filePath = testFile.canonicalFile.name + val putIntoPackageFolder = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// FORCE_PACKAGE_FOLDER") != null + if (putIntoPackageFolder) { + filePath = getPathAccordingToPackage(filePath, contents) + myFixture.addFileToProject(filePath, contents) + myFixture.configureByFile(filePath) + } + else { + myFixture.configureByText(filePath, contents) + } checkForUnexpectedActions() configExtra(fileText) - applyAction(contents, testFile.canonicalPath) + applyAction(contents, filePath) UsefulTestCase.assertEmpty(expectedErrorMessage) } diff --git a/ultimate/testData/quickFixes/spring/addQualifierAnnotation/ambiguousBean.kt b/ultimate/testData/quickFixes/spring/addQualifierAnnotation/ambiguousBean.kt index 9c0833c2348..a25b5d36761 100644 --- a/ultimate/testData/quickFixes/spring/addQualifierAnnotation/ambiguousBean.kt +++ b/ultimate/testData/quickFixes/spring/addQualifierAnnotation/ambiguousBean.kt @@ -3,6 +3,9 @@ // CONFIGURE_SPRING_FILE_SET // WITH_RUNTIME // DISABLE-ERRORS +// FORCE_PACKAGE_FOLDER + +package pkg import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component diff --git a/ultimate/testData/quickFixes/spring/addQualifierAnnotation/ambiguousBean.kt.after b/ultimate/testData/quickFixes/spring/addQualifierAnnotation/ambiguousBean.kt.after index b6e8b6ee50e..e043d12d4cb 100644 --- a/ultimate/testData/quickFixes/spring/addQualifierAnnotation/ambiguousBean.kt.after +++ b/ultimate/testData/quickFixes/spring/addQualifierAnnotation/ambiguousBean.kt.after @@ -3,6 +3,9 @@ // CONFIGURE_SPRING_FILE_SET // WITH_RUNTIME // DISABLE-ERRORS +// FORCE_PACKAGE_FOLDER + +package pkg import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component