From ed9b1ac151d675baa4544124153d19c42ead2834 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 29 Mar 2016 17:17:56 +0300 Subject: [PATCH] [REVERTED] 0a71eb7 Alexey Sedunov on 2/25/2016 at 14:02 (committed on 3/24/2016 at 18:42) Spring Support: Implement Spring-specific references --- Changelog.md | 1 - .../jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt | 3 - .../kotlin/generators/tests/GenerateTests.kt | 15 -- .../AbstractKotlinReferenceContributor.kt | 56 -------- .../references/KotlinReferenceContributor.kt | 38 ++++-- .../KotlinFixtureCompletionBaseTestCase.kt | 19 +-- .../AbstractCompletionHandlerTests.kt | 5 - .../src/META-INF/kotlin-spring.xml | 2 - .../KotlinSpringReferenceContributor.kt | 129 ------------------ .../references/KtSpringBeanScopeReference.kt | 44 ------ ...actSpringReferenceCompletionHandlerTest.kt | 39 ------ .../AbstractSpringReferenceCompletionTest.kt | 39 ------ .../AbstractSpringReferenceNavigationTest.kt | 61 --------- ...ferenceCompletionHandlerTestGenerated.java | 55 -------- ...pringReferenceCompletionTestGenerated.java | 49 ------- ...pringReferenceNavigationTestGenerated.java | 79 ----------- .../KotlinPropertiesReferenceContributor.kt | 5 +- .../completion/handler/scopeReference.kt | 7 - .../handler/scopeReference.kt.after | 7 - .../completion/handler/spring-config.xml | 7 - .../handler/springBeanReferenceEnter.kt | 14 -- .../handler/springBeanReferenceEnter.kt.after | 14 -- .../handler/springBeanReferenceTab.kt | 14 -- .../handler/springBeanReferenceTab.kt.after | 14 -- .../completion/variants/scopeReference.kt | 9 -- .../completion/variants/spring-config.xml | 8 -- .../variants/springBeanReference.kt | 15 -- .../fileReferenceInClasspathResource.kt | 9 -- .../fileReferenceInClasspathResource.test.xml | 3 - .../fileReferenceInClasspathXmlContext.kt | 9 -- ...ileReferenceInClasspathXmlContext.test.xml | 3 - .../references/navigation/scopeReference.kt | 7 - .../navigation/scopeReference_config.xml | 5 - .../springBeanRefInFactoryContainsBean.kt | 13 -- ...ingBeanRefInFactoryContainsBean_config.xml | 5 - .../springBeanRefInFactoryGetBean.kt | 13 -- .../springBeanRefInFactoryGetBean_config.xml | 5 - .../navigation/springBeanRefInResource.kt | 11 -- .../springBeanRefInResource_config.xml | 5 - .../springFactoryBeanRefInResource.kt | 11 -- .../springFactoryBeanRefInResource_config.xml | 5 - .../AbstractGotoTestOrCodeActionTest.kt | 46 ++++++- .../idea/actions/AbstractNavigationTest.kt | 75 ---------- .../idea/navigation/NavigationTestUtils.java | 4 +- .../jetbrains/kotlin/test/ReferenceUtils.java | 9 +- 45 files changed, 80 insertions(+), 906 deletions(-) delete mode 100644 idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/AbstractKotlinReferenceContributor.kt delete mode 100644 idea/idea-ultimate/src/org/jetbrains/kotlin/idea/spring/references/KotlinSpringReferenceContributor.kt delete mode 100644 idea/idea-ultimate/src/org/jetbrains/kotlin/idea/spring/references/KtSpringBeanScopeReference.kt delete mode 100644 idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceCompletionHandlerTest.kt delete mode 100644 idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceCompletionTest.kt delete mode 100644 idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceNavigationTest.kt delete mode 100644 idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceCompletionHandlerTestGenerated.java delete mode 100644 idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceCompletionTestGenerated.java delete mode 100644 idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceNavigationTestGenerated.java delete mode 100644 idea/testData/spring/core/references/completion/handler/scopeReference.kt delete mode 100644 idea/testData/spring/core/references/completion/handler/scopeReference.kt.after delete mode 100644 idea/testData/spring/core/references/completion/handler/spring-config.xml delete mode 100644 idea/testData/spring/core/references/completion/handler/springBeanReferenceEnter.kt delete mode 100644 idea/testData/spring/core/references/completion/handler/springBeanReferenceEnter.kt.after delete mode 100644 idea/testData/spring/core/references/completion/handler/springBeanReferenceTab.kt delete mode 100644 idea/testData/spring/core/references/completion/handler/springBeanReferenceTab.kt.after delete mode 100644 idea/testData/spring/core/references/completion/variants/scopeReference.kt delete mode 100644 idea/testData/spring/core/references/completion/variants/spring-config.xml delete mode 100644 idea/testData/spring/core/references/completion/variants/springBeanReference.kt delete mode 100644 idea/testData/spring/core/references/navigation/fileReferenceInClasspathResource.kt delete mode 100644 idea/testData/spring/core/references/navigation/fileReferenceInClasspathResource.test.xml delete mode 100644 idea/testData/spring/core/references/navigation/fileReferenceInClasspathXmlContext.kt delete mode 100644 idea/testData/spring/core/references/navigation/fileReferenceInClasspathXmlContext.test.xml delete mode 100644 idea/testData/spring/core/references/navigation/scopeReference.kt delete mode 100644 idea/testData/spring/core/references/navigation/scopeReference_config.xml delete mode 100644 idea/testData/spring/core/references/navigation/springBeanRefInFactoryContainsBean.kt delete mode 100644 idea/testData/spring/core/references/navigation/springBeanRefInFactoryContainsBean_config.xml delete mode 100644 idea/testData/spring/core/references/navigation/springBeanRefInFactoryGetBean.kt delete mode 100644 idea/testData/spring/core/references/navigation/springBeanRefInFactoryGetBean_config.xml delete mode 100644 idea/testData/spring/core/references/navigation/springBeanRefInResource.kt delete mode 100644 idea/testData/spring/core/references/navigation/springBeanRefInResource_config.xml delete mode 100644 idea/testData/spring/core/references/navigation/springFactoryBeanRefInResource.kt delete mode 100644 idea/testData/spring/core/references/navigation/springFactoryBeanRefInResource_config.xml delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/actions/AbstractNavigationTest.kt diff --git a/Changelog.md b/Changelog.md index 05156a4726e..08d132deb3d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -104,7 +104,6 @@ New features: - [KT-9752](https://youtrack.jetbrains.com/issue/KT-9752) More usable file chooser for "Move declaration to another file" - [KT-9697](https://youtrack.jetbrains.com/issue/KT-9697) Move method to companion object and back - [KT-11098](https://youtrack.jetbrains.com/issue/KT-11098) Inspection on final classes/functions annotated with Spring @Configuration/@Component/@Bean -- [KT-11405](https://youtrack.jetbrains.com/issue/KT-11405) Navigation and Find Usages for Spring beans referenced in annotation arguments and BeanFactory method calls General issues fixed: diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt index 886ac10ba02..f67bb808d97 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt @@ -367,9 +367,6 @@ fun KtStringTemplateExpression.getContentRange(): TextRange { return TextRange(start, if (lastChild.elementType == KtTokens.CLOSING_QUOTE) length - lastChild.textLength else length) } -val KtStringTemplateExpression.plainContent: String - get() = getContentRange().substring(text) - fun KtStringTemplateExpression.isSingleQuoted(): Boolean = node.firstChildNode.textLength == 1 diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index fc2ccae2f80..355216eb65b 100644 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -101,9 +101,6 @@ import org.jetbrains.kotlin.idea.refactoring.pushDown.AbstractPushDownTest import org.jetbrains.kotlin.idea.refactoring.rename.AbstractRenameTest import org.jetbrains.kotlin.idea.refactoring.safeDelete.AbstractSafeDeleteTest import org.jetbrains.kotlin.idea.resolve.* -import org.jetbrains.kotlin.idea.spring.tests.references.AbstractSpringReferenceCompletionHandlerTest -import org.jetbrains.kotlin.idea.spring.tests.references.AbstractSpringReferenceCompletionTest -import org.jetbrains.kotlin.idea.spring.tests.references.AbstractSpringReferenceNavigationTest import org.jetbrains.kotlin.idea.structureView.AbstractKotlinFileStructureTest import org.jetbrains.kotlin.idea.stubs.AbstractMultiFileHighlightingTest import org.jetbrains.kotlin.idea.stubs.AbstractResolveByStubTest @@ -789,18 +786,6 @@ fun main(args: Array) { testClass("UltimateQuickFixTestGenerated") { model("ultimateQuickFixes", pattern = "^([\\w\\-_]+)\\.kt$", filenameStartsLowerCase = true) } - - testClass() { - model("spring/core/references/completion/handler") - } - - testClass() { - model("spring/core/references/completion/variants") - } - - testClass() { - model("spring/core/references/navigation") - } } testGroup("idea/tests", "compiler/testData") { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/AbstractKotlinReferenceContributor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/AbstractKotlinReferenceContributor.kt deleted file mode 100644 index 36f45f81cf3..00000000000 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/AbstractKotlinReferenceContributor.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.kotlin.idea.references - -import com.intellij.patterns.ElementPattern -import com.intellij.patterns.PlatformPatterns -import com.intellij.psi.* -import com.intellij.util.ProcessingContext -import org.jetbrains.kotlin.psi.KtElement - -abstract class AbstractKotlinReferenceContributor : PsiReferenceContributor() { - protected inline fun PsiReferenceRegistrar.registerProvider( - priority: Double = PsiReferenceRegistrar.DEFAULT_PRIORITY, - crossinline factory: (E) -> PsiReference? - ) { - registerMultiProvider(priority) { factory(it)?.let { arrayOf(it) } ?: PsiReference.EMPTY_ARRAY } - } - - protected inline fun PsiReferenceRegistrar.registerMultiProvider( - priority: Double = PsiReferenceRegistrar.DEFAULT_PRIORITY, - crossinline factory: (E) -> Array - ) { - registerMultiProvider(PlatformPatterns.psiElement(E::class.java), priority, factory) - } - - protected inline fun PsiReferenceRegistrar.registerMultiProvider( - pattern: ElementPattern, - priority: Double = PsiReferenceRegistrar.DEFAULT_PRIORITY, - crossinline factory: (E) -> Array - ) { - registerReferenceProvider( - pattern, - object : PsiReferenceProvider() { - override fun getReferencesByElement(element: PsiElement, context: ProcessingContext): Array { - @Suppress("UNCHECKED_CAST") - return factory(element as E) - } - }, - priority - ) - } -} \ No newline at end of file diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KotlinReferenceContributor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KotlinReferenceContributor.kt index cf05d938f90..f0fc216a224 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KotlinReferenceContributor.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KotlinReferenceContributor.kt @@ -16,21 +16,22 @@ package org.jetbrains.kotlin.idea.references -import com.intellij.psi.PsiReference -import com.intellij.psi.PsiReferenceRegistrar +import com.intellij.patterns.PlatformPatterns +import com.intellij.psi.* +import com.intellij.util.ProcessingContext import org.jetbrains.kotlin.idea.kdoc.KDocReference import org.jetbrains.kotlin.kdoc.psi.impl.KDocName import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* -class KotlinReferenceContributor() : AbstractKotlinReferenceContributor() { +class KotlinReferenceContributor() : PsiReferenceContributor() { override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) { with(registrar) { - registerProvider { + registerProvider(KtSimpleNameExpression::class.java) { KtSimpleNameReference(it) } - registerMultiProvider { + registerMultiProvider(KtNameReferenceExpression::class.java) { if (it.getReferencedNameElementType() != KtTokens.IDENTIFIER) return@registerMultiProvider emptyArray() when (it.readWriteAccess(useResolveForReadWrite = false)) { @@ -43,33 +44,46 @@ class KotlinReferenceContributor() : AbstractKotlinReferenceContributor() { } } - registerProvider { + registerProvider(KtConstructorDelegationReferenceExpression::class.java) { KtConstructorDelegationReference(it) } - registerProvider { + registerProvider(KtCallExpression::class.java) { KtInvokeFunctionReference(it) } - registerProvider { + registerProvider(KtArrayAccessExpression::class.java) { KtArrayAccessReference(it) } - registerProvider { + registerProvider(KtForExpression::class.java) { KtForLoopInReference(it) } - registerProvider { + registerProvider(KtPropertyDelegate::class.java) { KtPropertyDelegationMethodsReference(it) } - registerProvider { + registerProvider(KtDestructuringDeclaration::class.java) { KtDestructuringDeclarationReference(it) } - registerProvider { + registerProvider(KDocName::class.java) { KDocReference(it) } } } + + private fun PsiReferenceRegistrar.registerProvider(elementClass: Class, factory: (E) -> KtReference) { + registerMultiProvider(elementClass, { arrayOf(factory(it)) }) + } + + private fun PsiReferenceRegistrar.registerMultiProvider(elementClass: Class, factory: (E) -> Array) { + registerReferenceProvider(PlatformPatterns.psiElement(elementClass), object: PsiReferenceProvider() { + override fun getReferencesByElement(element: PsiElement, context: ProcessingContext): Array { + @Suppress("UNCHECKED_CAST") + return factory(element as E) + } + }) + } } diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt index 3f6764ea9cd..3f6f8beae17 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt @@ -36,18 +36,13 @@ abstract class KotlinFixtureCompletionBaseTestCase : KotlinLightCodeInsightFixtu open fun doTest(testPath: String) { setUpFixture(testPath) - try { - val fileText = FileUtil.loadFile(File(testPath), true) + val fileText = FileUtil.loadFile(File(testPath), true) - if (ExpectedCompletionUtils.shouldRunHighlightingBeforeCompletion(fileText)) { - myFixture.doHighlighting() - } + if (ExpectedCompletionUtils.shouldRunHighlightingBeforeCompletion(fileText)) { + myFixture.doHighlighting() + } - testCompletion(fileText, getPlatform(), { completionType, count -> complete(completionType, count) }, defaultCompletionType(), defaultInvocationCount()) - } - finally { - tearDownFixture() - } + testCompletion(fileText, getPlatform(), { completionType, count -> complete(completionType, count) }, defaultCompletionType(), defaultInvocationCount()) } protected open fun setUpFixture(testPath: String) { @@ -56,8 +51,4 @@ abstract class KotlinFixtureCompletionBaseTestCase : KotlinLightCodeInsightFixtu myFixture.configureByFile(testPath) } - - protected open fun tearDownFixture() { - - } } diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt index 08918cc4a60..88c1160a85e 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt @@ -73,7 +73,6 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType: } finally { settingManager.dropTemporarySettings() - tearDownFixture() } } @@ -81,10 +80,6 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType: fixture.configureByFile(testPath) } - protected open fun tearDownFixture() { - - } - override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE } diff --git a/idea/idea-ultimate/src/META-INF/kotlin-spring.xml b/idea/idea-ultimate/src/META-INF/kotlin-spring.xml index a8767bc3bcb..8999970dab2 100644 --- a/idea/idea-ultimate/src/META-INF/kotlin-spring.xml +++ b/idea/idea-ultimate/src/META-INF/kotlin-spring.xml @@ -1,7 +1,5 @@ - - { - if (!it.isPlain()) return@registerProvider null - - val callExpression = (it.parent as? KtValueArgument)?.getStrictParentOfType() ?: return@registerProvider null - val context = callExpression.analyze(BodyResolveMode.PARTIAL) - val resolvedCall = callExpression.getResolvedCall(context) ?: return@registerProvider null - val callable = resolvedCall.resultingDescriptor as? CallableMemberDescriptor ?: return@registerProvider null - if (!callable.overriddenTreeAsSequence(true).any { - it.containingDeclaration.importableFqName?.asString() == SpringConstants.BEAN_FACTORY_CLASS - }) return@registerProvider null - if (callable.name.asString() !in SpringBeanNamesReferenceProvider.METHODS) return@registerProvider null - - SpringBeanReference(it, it.getContentRange()) - } - - registrar.registerProvider(PsiReferenceRegistrar.HIGHER_PRIORITY) { - if (!it.isPlain()) return@registerProvider null - - val argument = it.parent as? KtValueArgument ?: return@registerProvider null - val argumentName = argument.getArgumentName() ?: return@registerProvider null - if (argumentName.asName.asString() != "name") return@registerProvider null - - val entry = argument.getStrictParentOfType() ?: return@registerProvider null - val context = entry.analyze(BodyResolveMode.PARTIAL) - val resolvedCall = entry.getResolvedCall(context) ?: return@registerProvider null - val annotation = (resolvedCall.resultingDescriptor as? ConstructorDescriptor)?.containingDeclaration ?: return@registerProvider null - if (annotation.importableFqName?.asString() != SpringAnnotationsConstants.JAVAX_RESOURCE) return@registerProvider null - - val contentRange = it.getContentRange() - var startOffset = contentRange.startOffset - val isFactoryBeanRef: Boolean - if (it.plainContent.startsWith("&")) { - startOffset++ - isFactoryBeanRef = true - } - else { - isFactoryBeanRef = false - } - - val callable = (it.getStrictParentOfType()?.parent as? KtModifierList)?.parent as? KtCallableDeclaration - val callableType = (callable?.resolveToDescriptor() as? CallableDescriptor)?.returnType - val requiredSuperClass = callableType?.constructor?.declarationDescriptor?.source?.getPsi() as? KtClass - - SpringBeanReference(it, TextRange(startOffset, contentRange.endOffset), requiredSuperClass?.toLightClass(), isFactoryBeanRef) - } - - registrar.registerProvider(PsiReferenceRegistrar.HIGHER_PRIORITY) { - if (!it.isPlain()) return@registerProvider null - - val argument = it.parent as? KtValueArgument ?: return@registerProvider null - val argumentName = argument.getArgumentName() - if (argumentName != null && argumentName.asName.asString() != "value") return@registerProvider null - - val entry = argument.getStrictParentOfType() ?: return@registerProvider null - val context = entry.analyze(BodyResolveMode.PARTIAL) - val resolvedCall = entry.getResolvedCall(context) ?: return@registerProvider null - val annotation = (resolvedCall.resultingDescriptor as? ConstructorDescriptor)?.containingDeclaration ?: return@registerProvider null - if (annotation.importableFqName?.asString() != SpringAnnotationsConstants.SCOPE) return@registerProvider null - - KtSpringBeanScopeReference(it) - } - - registrar.registerMultiProvider { - if (!it.isPlain()) return@registerMultiProvider PsiReference.EMPTY_ARRAY - - val callExpression = (it.parent as? KtValueArgument)?.getStrictParentOfType() - ?: return@registerMultiProvider PsiReference.EMPTY_ARRAY - val context = callExpression.analyze(BodyResolveMode.PARTIAL) - val resolvedCall = callExpression.getResolvedCall(context) ?: return@registerMultiProvider PsiReference.EMPTY_ARRAY - val classDescriptor = (resolvedCall.resultingDescriptor as? ConstructorDescriptor)?.containingDeclaration - ?: return@registerMultiProvider PsiReference.EMPTY_ARRAY - val qName = classDescriptor.importableFqName?.asString() - if (qName != SpringConstants.CLASS_PATH_XML_APP_CONTEXT && qName != SpringConstants.CLASS_PATH_RESOURCE) { - return@registerMultiProvider PsiReference.EMPTY_ARRAY - } - - val content = it.plainContent - val resourcesBuilder = SpringResourcesBuilder.create(it, content).fromRoot(content.startsWith("/")).soft(false) - SpringResourcesUtil.getInstance().getClassPathReferences(resourcesBuilder) - } - } -} \ No newline at end of file diff --git a/idea/idea-ultimate/src/org/jetbrains/kotlin/idea/spring/references/KtSpringBeanScopeReference.kt b/idea/idea-ultimate/src/org/jetbrains/kotlin/idea/spring/references/KtSpringBeanScopeReference.kt deleted file mode 100644 index 1254d1be575..00000000000 --- a/idea/idea-ultimate/src/org/jetbrains/kotlin/idea/spring/references/KtSpringBeanScopeReference.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.kotlin.idea.spring.references - -import com.intellij.codeInsight.lookup.LookupElementBuilder -import com.intellij.ide.TypePresentationService -import com.intellij.psi.ElementManipulators -import com.intellij.psi.PsiReferenceBase -import com.intellij.spring.model.scope.SpringBeanScope -import com.intellij.spring.model.scope.SpringBeanScopeManager -import org.jetbrains.kotlin.psi.KtStringTemplateExpression -import org.jetbrains.kotlin.psi.psiUtil.plainContent - -class KtSpringBeanScopeReference( - element: KtStringTemplateExpression -) : PsiReferenceBase(element, ElementManipulators.getManipulator(element).getRangeInElement(element)) { - private fun getScopes(): Sequence { - return SpringBeanScope.getDefaultScopes().asSequence() + SpringBeanScopeManager.getInstance().getCustomBeanScopes(element) - } - - private fun getLookupElement(scope: String): LookupElementBuilder { - return LookupElementBuilder - .create(scope) - .withIcon(TypePresentationService.getService().getTypeIcon(SpringBeanScope::class.java)) - } - - override fun resolve() = if (element.plainContent in getScopes().map { it.value }) element else null - - override fun getVariants() = getScopes().map { getLookupElement(it.value) }.toList().toTypedArray() -} diff --git a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceCompletionHandlerTest.kt b/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceCompletionHandlerTest.kt deleted file mode 100644 index 156a945ad3d..00000000000 --- a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceCompletionHandlerTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.kotlin.idea.spring.tests.references - -import com.intellij.util.PathUtil -import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractBasicCompletionHandlerTest -import org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension -import org.jetbrains.kotlin.idea.test.TestFixtureExtension -import java.io.File - -abstract class AbstractSpringReferenceCompletionHandlerTest : AbstractBasicCompletionHandlerTest() { - override fun setUpFixture(testPath: String) { - super.setUpFixture(testPath) - - TestFixtureExtension - .loadFixture(myModule) - .configureFileSet(myFixture, listOf(PathUtil.toSystemIndependentName(File(testPath).parent + "/spring-config.xml"))) - } - - override fun tearDownFixture() { - TestFixtureExtension.unloadFixture() - - super.tearDownFixture() - } -} \ No newline at end of file diff --git a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceCompletionTest.kt b/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceCompletionTest.kt deleted file mode 100644 index b0fa8cb070c..00000000000 --- a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceCompletionTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.kotlin.idea.spring.tests.references - -import com.intellij.util.PathUtil -import org.jetbrains.kotlin.idea.completion.test.AbstractJvmBasicCompletionTest -import org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension -import org.jetbrains.kotlin.idea.test.TestFixtureExtension -import java.io.File - -abstract class AbstractSpringReferenceCompletionTest : AbstractJvmBasicCompletionTest() { - override fun setUpFixture(testPath: String) { - super.setUpFixture(testPath) - - TestFixtureExtension - .loadFixture(myModule)!! - .configureFileSet(myFixture, listOf(PathUtil.toSystemIndependentName(File(testPath).parent + "/spring-config.xml"))) - } - - override fun tearDownFixture() { - TestFixtureExtension.unloadFixture() - - super.tearDownFixture() - } -} \ No newline at end of file diff --git a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceNavigationTest.kt b/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceNavigationTest.kt deleted file mode 100644 index 2d8420f5545..00000000000 --- a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/AbstractSpringReferenceNavigationTest.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.kotlin.idea.spring.tests.references - -import com.intellij.codeInsight.navigation.GotoTargetHandler -import com.intellij.openapi.editor.Editor -import com.intellij.psi.PsiFile -import org.jetbrains.kotlin.idea.KotlinFileType -import org.jetbrains.kotlin.idea.actions.AbstractNavigationTest -import org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension -import org.jetbrains.kotlin.idea.test.TestFixtureExtension -import org.jetbrains.kotlin.psi.KtStringTemplateExpression -import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType -import org.jetbrains.kotlin.test.InTextDirectivesUtils - -abstract class AbstractSpringReferenceNavigationTest : AbstractNavigationTest() { - override fun getSourceAndTargetElements(editor: Editor, file: PsiFile): GotoTargetHandler.GotoData? { - val stringTemplate = file.findElementAt(editor.caretModel.offset)!!.getNonStrictParentOfType()!! - return GotoTargetHandler.GotoData(stringTemplate, - stringTemplate.references.mapNotNull { it.resolve() }.toTypedArray(), - emptyList()) - } - - override fun setUp() { - super.setUp() - TestFixtureExtension.loadFixture(myModule)!! - } - - override fun configureExtra(mainFileBaseName: String, mainFileText: String) { - if (!InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// NO_XML_CONFIG")) { - TestFixtureExtension - .getFixture()!! - .configureFileSet(myFixture, listOf("${mainFileBaseName}_config.xml")) - } - if (InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// JAVAX_ANNOTATION_RESOURCE")) { - myFixture.configureByText( - KotlinFileType.INSTANCE, - """package javax.annotation; annotation class Resource(val name: String = "")""" - ) - } - } - - override fun tearDown() { - TestFixtureExtension.unloadFixture() - super.tearDown() - } -} \ No newline at end of file diff --git a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceCompletionHandlerTestGenerated.java b/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceCompletionHandlerTestGenerated.java deleted file mode 100644 index 13eeb71a123..00000000000 --- a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceCompletionHandlerTestGenerated.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.kotlin.idea.spring.tests.references; - -import com.intellij.testFramework.TestDataPath; -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.TestMetadata; -import org.junit.runner.RunWith; - -import java.io.File; -import java.util.regex.Pattern; - -/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ -@SuppressWarnings("all") -@TestMetadata("idea/testData/spring/core/references/completion/handler") -@TestDataPath("$PROJECT_ROOT") -@RunWith(JUnit3RunnerWithInners.class) -public class SpringReferenceCompletionHandlerTestGenerated extends AbstractSpringReferenceCompletionHandlerTest { - public void testAllFilesPresentInHandler() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/spring/core/references/completion/handler"), Pattern.compile("^(.+)\\.kt$"), true); - } - - @TestMetadata("scopeReference.kt") - public void testScopeReference() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/completion/handler/scopeReference.kt"); - doTest(fileName); - } - - @TestMetadata("springBeanReferenceEnter.kt") - public void testSpringBeanReferenceEnter() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/completion/handler/springBeanReferenceEnter.kt"); - doTest(fileName); - } - - @TestMetadata("springBeanReferenceTab.kt") - public void testSpringBeanReferenceTab() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/completion/handler/springBeanReferenceTab.kt"); - doTest(fileName); - } -} diff --git a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceCompletionTestGenerated.java b/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceCompletionTestGenerated.java deleted file mode 100644 index 7ae8b2ce091..00000000000 --- a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceCompletionTestGenerated.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.kotlin.idea.spring.tests.references; - -import com.intellij.testFramework.TestDataPath; -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.TestMetadata; -import org.junit.runner.RunWith; - -import java.io.File; -import java.util.regex.Pattern; - -/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ -@SuppressWarnings("all") -@TestMetadata("idea/testData/spring/core/references/completion/variants") -@TestDataPath("$PROJECT_ROOT") -@RunWith(JUnit3RunnerWithInners.class) -public class SpringReferenceCompletionTestGenerated extends AbstractSpringReferenceCompletionTest { - public void testAllFilesPresentInVariants() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/spring/core/references/completion/variants"), Pattern.compile("^(.+)\\.kt$"), true); - } - - @TestMetadata("scopeReference.kt") - public void testScopeReference() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/completion/variants/scopeReference.kt"); - doTest(fileName); - } - - @TestMetadata("springBeanReference.kt") - public void testSpringBeanReference() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/completion/variants/springBeanReference.kt"); - doTest(fileName); - } -} diff --git a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceNavigationTestGenerated.java b/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceNavigationTestGenerated.java deleted file mode 100644 index 1edd7c95cc7..00000000000 --- a/idea/idea-ultimate/tests/org/jetbrains/kotlin/idea/spring/tests/references/SpringReferenceNavigationTestGenerated.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.kotlin.idea.spring.tests.references; - -import com.intellij.testFramework.TestDataPath; -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.TestMetadata; -import org.junit.runner.RunWith; - -import java.io.File; -import java.util.regex.Pattern; - -/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ -@SuppressWarnings("all") -@TestMetadata("idea/testData/spring/core/references/navigation") -@TestDataPath("$PROJECT_ROOT") -@RunWith(JUnit3RunnerWithInners.class) -public class SpringReferenceNavigationTestGenerated extends AbstractSpringReferenceNavigationTest { - public void testAllFilesPresentInNavigation() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/spring/core/references/navigation"), Pattern.compile("^(.+)\\.kt$"), true); - } - - @TestMetadata("fileReferenceInClasspathResource.kt") - public void testFileReferenceInClasspathResource() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/navigation/fileReferenceInClasspathResource.kt"); - doTest(fileName); - } - - @TestMetadata("fileReferenceInClasspathXmlContext.kt") - public void testFileReferenceInClasspathXmlContext() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/navigation/fileReferenceInClasspathXmlContext.kt"); - doTest(fileName); - } - - @TestMetadata("scopeReference.kt") - public void testScopeReference() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/navigation/scopeReference.kt"); - doTest(fileName); - } - - @TestMetadata("springBeanRefInFactoryContainsBean.kt") - public void testSpringBeanRefInFactoryContainsBean() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/navigation/springBeanRefInFactoryContainsBean.kt"); - doTest(fileName); - } - - @TestMetadata("springBeanRefInFactoryGetBean.kt") - public void testSpringBeanRefInFactoryGetBean() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/navigation/springBeanRefInFactoryGetBean.kt"); - doTest(fileName); - } - - @TestMetadata("springBeanRefInResource.kt") - public void testSpringBeanRefInResource() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/navigation/springBeanRefInResource.kt"); - doTest(fileName); - } - - @TestMetadata("springFactoryBeanRefInResource.kt") - public void testSpringFactoryBeanRefInResource() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/spring/core/references/navigation/springFactoryBeanRefInResource.kt"); - doTest(fileName); - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/properties/KotlinPropertiesReferenceContributor.kt b/idea/src/org/jetbrains/kotlin/idea/properties/KotlinPropertiesReferenceContributor.kt index 616d8473972..abf03e28783 100644 --- a/idea/src/org/jetbrains/kotlin/idea/properties/KotlinPropertiesReferenceContributor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/properties/KotlinPropertiesReferenceContributor.kt @@ -17,11 +17,12 @@ package org.jetbrains.kotlin.idea.properties import com.intellij.patterns.PlatformPatterns +import com.intellij.psi.PsiReferenceContributor import com.intellij.psi.PsiReferenceRegistrar -import org.jetbrains.kotlin.idea.references.AbstractKotlinReferenceContributor +import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry import org.jetbrains.kotlin.psi.KtStringTemplateExpression -class KotlinPropertiesReferenceContributor : AbstractKotlinReferenceContributor() { +class KotlinPropertiesReferenceContributor : PsiReferenceContributor() { override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) { registrar.registerReferenceProvider( PlatformPatterns.psiElement(KtStringTemplateExpression::class.java), diff --git a/idea/testData/spring/core/references/completion/handler/scopeReference.kt b/idea/testData/spring/core/references/completion/handler/scopeReference.kt deleted file mode 100644 index 57a792359c2..00000000000 --- a/idea/testData/spring/core/references/completion/handler/scopeReference.kt +++ /dev/null @@ -1,7 +0,0 @@ -// ELEMENT: singleton -package test - -import org.springframework.context.annotation.Scope - -@Scope("") -class ScopedBean \ No newline at end of file diff --git a/idea/testData/spring/core/references/completion/handler/scopeReference.kt.after b/idea/testData/spring/core/references/completion/handler/scopeReference.kt.after deleted file mode 100644 index e8b62870d1c..00000000000 --- a/idea/testData/spring/core/references/completion/handler/scopeReference.kt.after +++ /dev/null @@ -1,7 +0,0 @@ -// ELEMENT: singleton -package test - -import org.springframework.context.annotation.Scope - -@Scope("singleton") -class ScopedBean \ No newline at end of file diff --git a/idea/testData/spring/core/references/completion/handler/spring-config.xml b/idea/testData/spring/core/references/completion/handler/spring-config.xml deleted file mode 100644 index c3deaeb35c8..00000000000 --- a/idea/testData/spring/core/references/completion/handler/spring-config.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/idea/testData/spring/core/references/completion/handler/springBeanReferenceEnter.kt b/idea/testData/spring/core/references/completion/handler/springBeanReferenceEnter.kt deleted file mode 100644 index 8e60f0bd691..00000000000 --- a/idea/testData/spring/core/references/completion/handler/springBeanReferenceEnter.kt +++ /dev/null @@ -1,14 +0,0 @@ -// ELEMENT: fooBean -// CHAR: \n -import org.springframework.beans.factory.BeanFactory -import org.springframework.beans.factory.xml.XmlBeanFactory -import org.springframework.core.io.FileSystemResource -import org.springframework.core.io.Resource - -class FooBeanClass { - init { - val configFile = FileSystemResource("spring-config.xml") - val factory = XmlBeanFactory(configFile) - factory.getBean("foo") - } -} \ No newline at end of file diff --git a/idea/testData/spring/core/references/completion/handler/springBeanReferenceEnter.kt.after b/idea/testData/spring/core/references/completion/handler/springBeanReferenceEnter.kt.after deleted file mode 100644 index f83d065dc0d..00000000000 --- a/idea/testData/spring/core/references/completion/handler/springBeanReferenceEnter.kt.after +++ /dev/null @@ -1,14 +0,0 @@ -// ELEMENT: fooBean -// CHAR: \n -import org.springframework.beans.factory.BeanFactory -import org.springframework.beans.factory.xml.XmlBeanFactory -import org.springframework.core.io.FileSystemResource -import org.springframework.core.io.Resource - -class FooBeanClass { - init { - val configFile = FileSystemResource("spring-config.xml") - val factory = XmlBeanFactory(configFile) - factory.getBean("fooBeano") - } -} \ No newline at end of file diff --git a/idea/testData/spring/core/references/completion/handler/springBeanReferenceTab.kt b/idea/testData/spring/core/references/completion/handler/springBeanReferenceTab.kt deleted file mode 100644 index d5c9415da75..00000000000 --- a/idea/testData/spring/core/references/completion/handler/springBeanReferenceTab.kt +++ /dev/null @@ -1,14 +0,0 @@ -// ELEMENT: fooBean -// CHAR: \t -import org.springframework.beans.factory.BeanFactory -import org.springframework.beans.factory.xml.XmlBeanFactory -import org.springframework.core.io.FileSystemResource -import org.springframework.core.io.Resource - -class FooBeanClass { - init { - val configFile = FileSystemResource("spring-config.xml") - val factory = XmlBeanFactory(configFile) - factory.getBean("foo") - } -} \ No newline at end of file diff --git a/idea/testData/spring/core/references/completion/handler/springBeanReferenceTab.kt.after b/idea/testData/spring/core/references/completion/handler/springBeanReferenceTab.kt.after deleted file mode 100644 index 90eafe886ec..00000000000 --- a/idea/testData/spring/core/references/completion/handler/springBeanReferenceTab.kt.after +++ /dev/null @@ -1,14 +0,0 @@ -// ELEMENT: fooBean -// CHAR: \t -import org.springframework.beans.factory.BeanFactory -import org.springframework.beans.factory.xml.XmlBeanFactory -import org.springframework.core.io.FileSystemResource -import org.springframework.core.io.Resource - -class FooBeanClass { - init { - val configFile = FileSystemResource("spring-config.xml") - val factory = XmlBeanFactory(configFile) - factory.getBean("fooBean") - } -} \ No newline at end of file diff --git a/idea/testData/spring/core/references/completion/variants/scopeReference.kt b/idea/testData/spring/core/references/completion/variants/scopeReference.kt deleted file mode 100644 index 6a8e5d626f3..00000000000 --- a/idea/testData/spring/core/references/completion/variants/scopeReference.kt +++ /dev/null @@ -1,9 +0,0 @@ -// NUMBER: 2 -// EXIST: { lookupString:"singleton" } -// EXIST: { lookupString:"prototype" } -package test - -import org.springframework.context.annotation.Scope - -@Scope("") -class ScopedBean \ No newline at end of file diff --git a/idea/testData/spring/core/references/completion/variants/spring-config.xml b/idea/testData/spring/core/references/completion/variants/spring-config.xml deleted file mode 100644 index b3fb31598a4..00000000000 --- a/idea/testData/spring/core/references/completion/variants/spring-config.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/idea/testData/spring/core/references/completion/variants/springBeanReference.kt b/idea/testData/spring/core/references/completion/variants/springBeanReference.kt deleted file mode 100644 index eb587c52a04..00000000000 --- a/idea/testData/spring/core/references/completion/variants/springBeanReference.kt +++ /dev/null @@ -1,15 +0,0 @@ -// NUMBER: 2 -// EXIST: { lookupString:"fooBean" } -// EXIST: { lookupString:"fooBean2" } -import org.springframework.beans.factory.BeanFactory -import org.springframework.beans.factory.xml.XmlBeanFactory -import org.springframework.core.io.FileSystemResource -import org.springframework.core.io.Resource - -class FooBeanClass { - init { - val configFile = FileSystemResource("spring-config.xml") - val factory = XmlBeanFactory(configFile) - factory.getBean("foo") - } -} \ No newline at end of file diff --git a/idea/testData/spring/core/references/navigation/fileReferenceInClasspathResource.kt b/idea/testData/spring/core/references/navigation/fileReferenceInClasspathResource.kt deleted file mode 100644 index 5b7ed134fbf..00000000000 --- a/idea/testData/spring/core/references/navigation/fileReferenceInClasspathResource.kt +++ /dev/null @@ -1,9 +0,0 @@ -// NO_XML_CONFIG -// REF: /src.fileReferenceInClasspathResource.test.xml -import org.springframework.core.io.ClassPathResource - -class Bean { - init { - ClassPathResource("fileReferenceInClasspathResource.test.xml") - } -} \ No newline at end of file diff --git a/idea/testData/spring/core/references/navigation/fileReferenceInClasspathResource.test.xml b/idea/testData/spring/core/references/navigation/fileReferenceInClasspathResource.test.xml deleted file mode 100644 index 5f79f12a9aa..00000000000 --- a/idea/testData/spring/core/references/navigation/fileReferenceInClasspathResource.test.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/idea/testData/spring/core/references/navigation/fileReferenceInClasspathXmlContext.kt b/idea/testData/spring/core/references/navigation/fileReferenceInClasspathXmlContext.kt deleted file mode 100644 index 7fc2d302e59..00000000000 --- a/idea/testData/spring/core/references/navigation/fileReferenceInClasspathXmlContext.kt +++ /dev/null @@ -1,9 +0,0 @@ -// NO_XML_CONFIG -// REF: /src.fileReferenceInClasspathXmlContext.test.xml -import org.springframework.context.support.ClassPathXmlApplicationContext - -class Bean { - init { - ClassPathXmlApplicationContext("fileReferenceInClasspathXmlContext.test.xml") - } -} \ No newline at end of file diff --git a/idea/testData/spring/core/references/navigation/fileReferenceInClasspathXmlContext.test.xml b/idea/testData/spring/core/references/navigation/fileReferenceInClasspathXmlContext.test.xml deleted file mode 100644 index 5f79f12a9aa..00000000000 --- a/idea/testData/spring/core/references/navigation/fileReferenceInClasspathXmlContext.test.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/idea/testData/spring/core/references/navigation/scopeReference.kt b/idea/testData/spring/core/references/navigation/scopeReference.kt deleted file mode 100644 index 34a710a0311..00000000000 --- a/idea/testData/spring/core/references/navigation/scopeReference.kt +++ /dev/null @@ -1,7 +0,0 @@ -// REF: singleton -package test - -import org.springframework.context.annotation.Scope - -@Scope("singleton") -class Bean \ No newline at end of file diff --git a/idea/testData/spring/core/references/navigation/scopeReference_config.xml b/idea/testData/spring/core/references/navigation/scopeReference_config.xml deleted file mode 100644 index aacac5ca9a6..00000000000 --- a/idea/testData/spring/core/references/navigation/scopeReference_config.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/idea/testData/spring/core/references/navigation/springBeanRefInFactoryContainsBean.kt b/idea/testData/spring/core/references/navigation/springBeanRefInFactoryContainsBean.kt deleted file mode 100644 index 6b5fa35e76f..00000000000 --- a/idea/testData/spring/core/references/navigation/springBeanRefInFactoryContainsBean.kt +++ /dev/null @@ -1,13 +0,0 @@ -// REF: -import org.springframework.beans.factory.BeanFactory -import org.springframework.beans.factory.xml.XmlBeanFactory -import org.springframework.core.io.FileSystemResource -import org.springframework.core.io.Resource - -class FooBeanClass { - init { - val configFile = FileSystemResource("spring-config.xml") - val factory = XmlBeanFactory(configFile) - if (factory.containsBean("fooBean")) println("FooBean") - } -} \ No newline at end of file diff --git a/idea/testData/spring/core/references/navigation/springBeanRefInFactoryContainsBean_config.xml b/idea/testData/spring/core/references/navigation/springBeanRefInFactoryContainsBean_config.xml deleted file mode 100644 index 5d68c8ea557..00000000000 --- a/idea/testData/spring/core/references/navigation/springBeanRefInFactoryContainsBean_config.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/idea/testData/spring/core/references/navigation/springBeanRefInFactoryGetBean.kt b/idea/testData/spring/core/references/navigation/springBeanRefInFactoryGetBean.kt deleted file mode 100644 index bf12f85b0bd..00000000000 --- a/idea/testData/spring/core/references/navigation/springBeanRefInFactoryGetBean.kt +++ /dev/null @@ -1,13 +0,0 @@ -// REF: -import org.springframework.beans.factory.BeanFactory -import org.springframework.beans.factory.xml.XmlBeanFactory -import org.springframework.core.io.FileSystemResource -import org.springframework.core.io.Resource - -class FooBeanClass { - init { - val configFile = FileSystemResource("spring-config.xml") - val factory = XmlBeanFactory(configFile) - factory.getBean("fooBean") - } -} \ No newline at end of file diff --git a/idea/testData/spring/core/references/navigation/springBeanRefInFactoryGetBean_config.xml b/idea/testData/spring/core/references/navigation/springBeanRefInFactoryGetBean_config.xml deleted file mode 100644 index 8f56c744117..00000000000 --- a/idea/testData/spring/core/references/navigation/springBeanRefInFactoryGetBean_config.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/idea/testData/spring/core/references/navigation/springBeanRefInResource.kt b/idea/testData/spring/core/references/navigation/springBeanRefInResource.kt deleted file mode 100644 index 4f79d7dbb6f..00000000000 --- a/idea/testData/spring/core/references/navigation/springBeanRefInResource.kt +++ /dev/null @@ -1,11 +0,0 @@ -// JAVAX_ANNOTATION_RESOURCE -// REF: -package test - -import javax.annotation.Resource - -class Bean - -class Test { - @Resource(name= "fooBean") lateinit var name: String -} \ No newline at end of file diff --git a/idea/testData/spring/core/references/navigation/springBeanRefInResource_config.xml b/idea/testData/spring/core/references/navigation/springBeanRefInResource_config.xml deleted file mode 100644 index aacac5ca9a6..00000000000 --- a/idea/testData/spring/core/references/navigation/springBeanRefInResource_config.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/idea/testData/spring/core/references/navigation/springFactoryBeanRefInResource.kt b/idea/testData/spring/core/references/navigation/springFactoryBeanRefInResource.kt deleted file mode 100644 index 55dd5023aa0..00000000000 --- a/idea/testData/spring/core/references/navigation/springFactoryBeanRefInResource.kt +++ /dev/null @@ -1,11 +0,0 @@ -// JAVAX_ANNOTATION_RESOURCE -// REF: -package test - -import javax.annotation.Resource - -class Bean - -class Test { - @Resource(name= "&fooBean") lateinit var name: String -} \ No newline at end of file diff --git a/idea/testData/spring/core/references/navigation/springFactoryBeanRefInResource_config.xml b/idea/testData/spring/core/references/navigation/springFactoryBeanRefInResource_config.xml deleted file mode 100644 index aacac5ca9a6..00000000000 --- a/idea/testData/spring/core/references/navigation/springFactoryBeanRefInResource_config.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/idea/tests/org/jetbrains/kotlin/idea/actions/AbstractGotoTestOrCodeActionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/actions/AbstractGotoTestOrCodeActionTest.kt index f94af6db18a..54fcfc6e165 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/actions/AbstractGotoTestOrCodeActionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/actions/AbstractGotoTestOrCodeActionTest.kt @@ -17,13 +17,55 @@ package org.jetbrains.kotlin.idea.actions import com.intellij.openapi.editor.Editor +import com.intellij.openapi.util.io.FileUtil import com.intellij.psi.PsiFile +import com.intellij.testFramework.PlatformTestUtil import com.intellij.testIntegration.GotoTestOrCodeHandler +import org.jetbrains.kotlin.idea.navigation.NavigationTestUtils +import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor +import org.jetbrains.kotlin.idea.test.PluginTestCaseBase +import org.jetbrains.kotlin.test.InTextDirectivesUtils +import org.jetbrains.kotlin.test.KotlinTestUtils +import java.io.File -abstract class AbstractGotoTestOrCodeActionTest : AbstractNavigationTest() { +abstract class AbstractGotoTestOrCodeActionTest : KotlinLightCodeInsightFixtureTestCase() { private object Handler: GotoTestOrCodeHandler() { public override fun getSourceAndTargetElements(editor: Editor?, file: PsiFile?) = super.getSourceAndTargetElements(editor, file) } - override fun getSourceAndTargetElements(editor: Editor, file: PsiFile) = Handler.getSourceAndTargetElements(editor, file) + override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE + + protected fun doTest(path: String) { + val mainFile = File(path) + val fileText = FileUtil.loadFile(mainFile, true) + val addKotlinRuntime = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// WITH_RUNTIME") != null + + try { + if (addKotlinRuntime) { + ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk()) + } + ConfigLibraryUtil.configureLibrariesByDirective(myModule, PlatformTestUtil.getCommunityPath(), fileText) + + myFixture.testDataPath = "${KotlinTestUtils.getHomeDirectory()}/${mainFile.parent}" + + val mainFileName = mainFile.name + val mainFileBaseName = mainFileName.substring(0, mainFileName.indexOf('.')) + mainFile.parentFile + .listFiles { file, name -> + name != mainFileName && name.startsWith("$mainFileBaseName.") && (name.endsWith(".kt") || name.endsWith(".java")) + } + .forEach{ myFixture.configureByFile(it.name) } + val file = myFixture.configureByFile(mainFileName) + + NavigationTestUtils.assertGotoDataMatching(editor, Handler.getSourceAndTargetElements(editor, file)) + } + finally { + ConfigLibraryUtil.unconfigureLibrariesByDirective(myModule, fileText) + if (addKotlinRuntime) { + ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk()) + } + } + } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/actions/AbstractNavigationTest.kt b/idea/tests/org/jetbrains/kotlin/idea/actions/AbstractNavigationTest.kt deleted file mode 100644 index 78ba636619c..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/actions/AbstractNavigationTest.kt +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.kotlin.idea.actions - -import com.intellij.codeInsight.navigation.GotoTargetHandler -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.util.io.FileUtil -import com.intellij.psi.PsiFile -import com.intellij.testFramework.PlatformTestUtil -import org.jetbrains.kotlin.idea.navigation.NavigationTestUtils -import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase -import org.jetbrains.kotlin.test.InTextDirectivesUtils -import org.jetbrains.kotlin.test.KotlinTestUtils -import java.io.File - -abstract class AbstractNavigationTest : KotlinLightCodeInsightFixtureTestCase() { - protected abstract fun getSourceAndTargetElements(editor: Editor, file: PsiFile): GotoTargetHandler.GotoData? - - override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - - protected open fun configureExtra(mainFileBaseName: String, mainFileText: String) { - - } - - protected fun doTest(path: String) { - val mainFile = File(path) - val fileText = FileUtil.loadFile(mainFile, true) - val addKotlinRuntime = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// WITH_RUNTIME") != null - - try { - if (addKotlinRuntime) { - ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk()) - } - ConfigLibraryUtil.configureLibrariesByDirective(myModule, PlatformTestUtil.getCommunityPath(), fileText) - - myFixture.testDataPath = "${KotlinTestUtils.getHomeDirectory()}/${mainFile.parent}" - - val mainFileName = mainFile.name - val mainFileBaseName = mainFileName.substring(0, mainFileName.indexOf('.')) - configureExtra(mainFileBaseName, fileText) - mainFile.parentFile - .listFiles { file, name -> - name != mainFileName && name.startsWith("$mainFileBaseName.") && (name.endsWith(".kt") || name.endsWith(".java") || name.endsWith(".xml")) - } - .forEach{ myFixture.configureByFile(it.name) } - val file = myFixture.configureByFile(mainFileName) - - NavigationTestUtils.assertGotoDataMatching(editor, getSourceAndTargetElements(editor, file)) - } - finally { - ConfigLibraryUtil.unconfigureLibrariesByDirective(myModule, fileText) - if (addKotlinRuntime) { - ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk()) - } - } - } -} - diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/NavigationTestUtils.java b/idea/tests/org/jetbrains/kotlin/idea/navigation/NavigationTestUtils.java index 5b615d4d004..d0fe9d98e24 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/NavigationTestUtils.java +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/NavigationTestUtils.java @@ -53,9 +53,7 @@ public final class NavigationTestUtils { // Get expected references from the tested document List expectedReferences = InTextDirectivesUtils.findListWithPrefixes(editor.getDocument().getText(), "// REF:"); for (int i = 0; i < expectedReferences.size(); i++) { - String expectedText = expectedReferences.get(i); - if (expectedText.startsWith("<")) continue; - expectedReferences.set(i, PathUtil.toSystemDependentName(expectedText).replace("//", "/")); + expectedReferences.set(i, PathUtil.toSystemDependentName(expectedReferences.get(i)).replace("//", "/")); } Collections.sort(expectedReferences); diff --git a/idea/tests/org/jetbrains/kotlin/test/ReferenceUtils.java b/idea/tests/org/jetbrains/kotlin/test/ReferenceUtils.java index 205f6418e7b..2897119d3c8 100644 --- a/idea/tests/org/jetbrains/kotlin/test/ReferenceUtils.java +++ b/idea/tests/org/jetbrains/kotlin/test/ReferenceUtils.java @@ -25,8 +25,6 @@ import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.psi.KtClass; import org.jetbrains.kotlin.psi.KtObjectDeclaration; -import org.jetbrains.kotlin.psi.KtStringTemplateExpression; -import org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt; import org.junit.Assert; public final class ReferenceUtils { @@ -43,16 +41,11 @@ public final class ReferenceUtils { return "companion object of " + renderAsGotoImplementation(containingClass); } - if (navigationElement instanceof KtStringTemplateExpression) { - return KtPsiUtilKt.getPlainContent((KtStringTemplateExpression) navigationElement); - } - Assert.assertTrue(navigationElement instanceof NavigationItem); ItemPresentation presentation = ((NavigationItem) navigationElement).getPresentation(); if (presentation == null) { - String elementText = element.getText(); - return elementText != null ? elementText : navigationElement.getText(); + return element.getText(); } String presentableText = presentation.getPresentableText();