Spring Support: Fix renaming of Spring bean declarations via SpEL references

#KT-11720 Fixed
 #KT-11725 Fixed
This commit is contained in:
Alexey Sedunov
2016-04-04 21:20:59 +03:00
parent 5203f62655
commit afecb09b6f
66 changed files with 715 additions and 11 deletions
+2
View File
@@ -162,6 +162,8 @@ Issues fixed:
- Fixed NoSuchFieldException in Kotlin module settings on IDEA Ultimate
- [KT-11702](https://youtrack.jetbrains.com/issue/KT-11702) Fixed resolution of Kotlin beans with custom name
- [KT-11689](https://youtrack.jetbrains.com/issue/KT-11689) Fixed exception on attempt to navigate to Kotlin file from Spring notification balloon
- [KT-11725](https://youtrack.jetbrains.com/issue/KT-11725) Fixed renaming of injected SpEL references
- [KT-11720](https://youtrack.jetbrains.com/issue/KT-11720) Fixed renaming of Kotlin beans through SpEL references
#### Debugger
@@ -56,6 +56,8 @@ public class KtStringTemplateExpression extends KtExpressionImpl implements PsiL
@Override
public PsiLanguageInjectionHost updateText(@NotNull String text) {
KtExpression newExpression = new KtPsiFactory(getProject()).createExpressionIfPossible(text);
if (newExpression instanceof KtStringTemplateExpression) return (KtStringTemplateExpression) replace(newExpression);
return ElementManipulators.handleContentChange(this, text);
}
@@ -33,6 +33,7 @@
package org.jetbrains.kotlin.asJava
import com.intellij.psi.ClassFileViewProvider
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.impl.compiled.ClsFileImpl
import com.intellij.psi.stubs.PsiClassHolderFileStub
import org.jetbrains.kotlin.name.FqName
@@ -51,4 +52,9 @@ open class FakeFileForLightClass(
override fun getClasses() = arrayOf(lightClass())
override fun getNavigationElement() = ktFile
override fun accept(visitor: PsiElementVisitor) {
// Prevent access to compiled PSI
// TODO: More complex traversal logic may be implemented when necessary
}
}
@@ -74,6 +74,7 @@ class KtLightAnnotation(
override fun getReference() = references.singleOrNull()
override fun getReferences() = ReferenceProvidersRegistry.getReferencesFromProviders(delegate, PsiReferenceService.Hints.NO_HINTS)
override fun getLanguage() = KotlinLanguage.INSTANCE
override fun getNavigationElement() = originalExpression
}
inner class LightArrayInitializerValue(private val delegate: PsiArrayInitializerMemberValue) : PsiArrayInitializerMemberValue by delegate {
@@ -18,9 +18,10 @@ package org.jetbrains.kotlin.idea.refactoring.rename
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.intellij.codeInsight.TargetElementUtilBase
import com.intellij.codeInsight.TargetElementUtil
import com.intellij.lang.properties.psi.PropertiesFile
import com.intellij.lang.properties.psi.Property
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.module.Module
@@ -32,6 +33,7 @@ import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileVisitor
import com.intellij.psi.*
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.refactoring.BaseRefactoringProcessor.ConflictsInTestsException
import com.intellij.refactoring.MultiFileTestCase
@@ -46,10 +48,7 @@ import org.jetbrains.kotlin.idea.jsonUtils.getNullableString
import org.jetbrains.kotlin.idea.jsonUtils.getString
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.search.allScope
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
import org.jetbrains.kotlin.idea.test.KotlinMultiFileTestCase
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.idea.test.*
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.*
import org.jetbrains.kotlin.psi.KtFile
@@ -93,7 +92,11 @@ abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk())
}
val fixtureClasses = renameObject.getAsJsonArray("fixtureClasses")?.map { it.asString } ?: emptyList()
try {
fixtureClasses.forEach { TestFixtureExtension.loadFixture(it, module) }
val context = TestContext()
when (RenameType.valueOf(renameTypeStr)) {
@@ -137,6 +140,13 @@ abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
Assert.fail("""Unexpected "hint: $hintExceptionUnquoted" """)
}
}
finally {
fixtureClasses.forEach { TestFixtureExtension.unloadFixture(it) }
}
}
protected open fun configExtra(rootDir: VirtualFile, renameParamsObject: JsonObject) {
}
private fun renameMarkedElement(renameParamsObject: JsonObject, context: TestContext) {
@@ -144,21 +154,34 @@ abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
val newName = renameParamsObject.getString("newName")
doTestCommittingDocuments { rootDir, rootAfter ->
val mainFile = rootDir.findChild(mainFilePath)!!
configExtra(rootDir, renameParamsObject)
val mainFile = rootDir.findFileByRelativePath(mainFilePath)!!
val psiFile = PsiManager.getInstance(context.project).findFile(mainFile)!!
val doc = PsiDocumentManager.getInstance(project).getDocument(psiFile)!!
val marker = doc.extractMarkerOffset(project, "/*rename*/")
assert(marker != -1)
val toRename = if (renameParamsObject["byRef"]?.asBoolean ?: false) {
val editor = createEditor(mainFile)
editor.caretModel.moveToOffset(marker)
TargetElementUtilBase.findTargetElement(editor, TargetElementUtilBase.getInstance().allAccepted)!!
val isByRef = renameParamsObject["byRef"]?.asBoolean ?: false
val isInjected = renameParamsObject["injected"]?.asBoolean ?: false
var currentEditor: Editor? = null
var currentFile: PsiFile = psiFile
if (isByRef || isInjected) {
currentEditor = createEditor(mainFile)
currentEditor.caretModel.moveToOffset(marker)
if (isInjected) {
currentFile = InjectedLanguageUtil.findInjectedPsiNoCommit(psiFile, marker)!!
currentEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(currentEditor, currentFile)
}
}
val toRename = if (isByRef) {
TargetElementUtil.findTargetElement(currentEditor, TargetElementUtil.getInstance().allAccepted)!!
}
else {
psiFile.findElementAt(marker)!!.getNonStrictParentOfType<PsiNamedElement>()!!
currentFile.findElementAt(marker)!!.getNonStrictParentOfType<PsiNamedElement>()!!
}
val substitution = RenamePsiElementProcessor.forElement(toRename).substituteElementToRename(toRename, null)
runRenameProcessor(context, newName, substitution, true, true)
@@ -0,0 +1,11 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Bean public JavaSpringBean buildBeanJNew() { return new JavaSpringBean(3); }
@Value("#{buildBeanJNew.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,9 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
@Configuration
open class KotlinAnnotated {
@Value("#{buildBeanJNew.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,11 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Bean public JavaSpringBean buildBeanJ() { return new JavaSpringBean(3); }
@Value("#{/*rename*/buildBeanJ.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,9 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
@Configuration
open class KotlinAnnotated {
@Value("#{buildBeanJ.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
{
"fixtureClasses": ["org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension"],
"type": "MARKED_ELEMENT",
"mainFile": "test/JavaAnnotated.java",
"springFileSet": ["test/JavaAnnotated.java", "test/KotlinAnnotated.kt"],
"injected": "true",
"byRef": "true",
"newName": "buildBeanJNew",
"withRuntime": "true"
}
@@ -0,0 +1,11 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Bean(name = {"annJavaBean2"}) public JavaSpringBean buildBeanJ() { return new JavaSpringBean(3); }
@Value("#{annJavaBean2.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,9 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
@Configuration
open class KotlinAnnotated {
@Value("#{annJavaBean2.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,11 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Bean(name = { "annJavaBean" }) public JavaSpringBean buildBeanJ() { return new JavaSpringBean(3); }
@Value("#{/*rename*/annJavaBean.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,9 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
@Configuration
open class KotlinAnnotated {
@Value("#{annJavaBean.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
{
"fixtureClasses": ["org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension"],
"type": "MARKED_ELEMENT",
"mainFile": "test/JavaAnnotated.java",
"springFileSet": ["test/JavaAnnotated.java", "test/KotlinAnnotated.kt"],
"injected": "true",
"byRef": "true",
"newName": "annJavaBean2",
"withRuntime": "true"
}
@@ -0,0 +1,10 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Value("#{buildBeanJNew.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,13 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Bean
@Configuration
open class KotlinAnnotated {
@Bean
fun buildBeanJNew() = JavaSpringBean(3)
@Value("#{buildBeanJNew.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Value("#{/*rename*/buildBeanJ.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,13 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Bean
@Configuration
open class KotlinAnnotated {
@Bean
fun buildBeanJ() = JavaSpringBean(3)
@Value("#{buildBeanJ.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
{
"fixtureClasses": ["org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension"],
"type": "MARKED_ELEMENT",
"mainFile": "test/JavaAnnotated.java",
"springFileSet": ["test/JavaAnnotated.java", "test/KotlinAnnotated.kt"],
"injected": "true",
"byRef": "true",
"newName": "buildBeanJNew",
"withRuntime": "true"
}
@@ -0,0 +1,10 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Value("#{annJavaBean2.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,13 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Bean
@Configuration
open class KotlinAnnotated {
@Bean(name = arrayOf("annJavaBean2"))
fun buildBeanJ() = JavaSpringBean(3)
@Value("#{annJavaBean2.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Value("#{/*rename*/annJavaBean.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,13 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Bean
@Configuration
open class KotlinAnnotated {
@Bean(name = arrayOf("annJavaBean"))
fun buildBeanJ() = JavaSpringBean(3)
@Value("#{annJavaBean.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
{
"fixtureClasses": ["org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension"],
"type": "MARKED_ELEMENT",
"mainFile": "test/JavaAnnotated.java",
"springFileSet": ["test/JavaAnnotated.java", "test/KotlinAnnotated.kt"],
"injected": "true",
"byRef": "true",
"newName": "annJavaBean2",
"withRuntime": "true"
}
@@ -0,0 +1,11 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Bean public JavaSpringBean buildBeanJNew() { return new JavaSpringBean(3); }
@Value("#{buildBeanJNew.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,9 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
@Configuration
open class KotlinAnnotated {
@Value("#{buildBeanJNew.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,11 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Bean public JavaSpringBean buildBeanJ() { return new JavaSpringBean(3); }
@Value("#{buildBeanJ.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,9 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
@Configuration
open class KotlinAnnotated {
@Value("#{/*rename*/buildBeanJ.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
{
"fixtureClasses": ["org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension"],
"type": "MARKED_ELEMENT",
"mainFile": "test/KotlinAnnotated.kt",
"springFileSet": ["test/JavaAnnotated.java", "test/KotlinAnnotated.kt"],
"injected": "true",
"byRef": "true",
"newName": "buildBeanJNew",
"withRuntime": "true"
}
@@ -0,0 +1,11 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Bean(name = {"annJavaBean2"}) public JavaSpringBean buildBeanJ() { return new JavaSpringBean(3); }
@Value("#{annJavaBean2.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,9 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
@Configuration
open class KotlinAnnotated {
@Value("#{annJavaBean2.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,11 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Bean(name = { "annJavaBean" }) public JavaSpringBean buildBeanJ() { return new JavaSpringBean(3); }
@Value("#{annJavaBean.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,9 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
@Configuration
open class KotlinAnnotated {
@Value("#{/*rename*/annJavaBean.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
{
"fixtureClasses": ["org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension"],
"type": "MARKED_ELEMENT",
"mainFile": "test/KotlinAnnotated.kt",
"springFileSet": ["test/JavaAnnotated.java", "test/KotlinAnnotated.kt"],
"injected": "true",
"byRef": "true",
"newName": "annJavaBean2",
"withRuntime": "true"
}
@@ -0,0 +1,10 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Value("#{buildBeanJNew.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,13 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Bean
@Configuration
open class KotlinAnnotated {
@Bean
fun buildBeanJNew() = JavaSpringBean(3)
@Value("#{buildBeanJNew.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Value("#{buildBeanJ.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,13 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Bean
@Configuration
open class KotlinAnnotated {
@Bean
fun buildBeanJ() = JavaSpringBean(3)
@Value("#{/*rename*/buildBeanJ.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
{
"fixtureClasses": ["org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension"],
"type": "MARKED_ELEMENT",
"mainFile": "test/KotlinAnnotated.kt",
"springFileSet": ["test/JavaAnnotated.java", "test/KotlinAnnotated.kt"],
"injected": "true",
"byRef": "true",
"newName": "buildBeanJNew",
"withRuntime": "true"
}
@@ -0,0 +1,10 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Value("#{annJavaBean2.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,13 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Bean
@Configuration
open class KotlinAnnotated {
@Bean(name = arrayOf("annJavaBean2"))
fun buildBeanJ() = JavaSpringBean(3)
@Value("#{annJavaBean2.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
package test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaAnnotated {
@Value("#{annJavaBean.value + 1}") private int newValue;
}
@@ -0,0 +1,6 @@
package test;
public class JavaSpringBean {
public final int value;
public JavaSpringBean(int p) { value = p; }
}
@@ -0,0 +1,13 @@
package test
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Bean
@Configuration
open class KotlinAnnotated {
@Bean(name = arrayOf("annJavaBean"))
fun buildBeanJ() = JavaSpringBean(3)
@Value("#{/*rename*/annJavaBean.value + 1}") private var newValue: Int = 0
}
@@ -0,0 +1,10 @@
{
"fixtureClasses": ["org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension"],
"type": "MARKED_ELEMENT",
"mainFile": "test/KotlinAnnotated.kt",
"springFileSet": ["test/JavaAnnotated.java", "test/KotlinAnnotated.kt"],
"injected": "true",
"byRef": "true",
"newName": "annJavaBean2",
"withRuntime": "true"
}
@@ -0,0 +1,24 @@
/*
* 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.rename
import org.jetbrains.kotlin.idea.refactoring.rename.AbstractRenameTest
import org.jetbrains.kotlin.tests.ULTIMATE_TEST_DATA_DIR
abstract class AbstractUltimateRenameTest : AbstractRenameTest() {
override fun getTestDataPath() = ULTIMATE_TEST_DATA_DIR
}
@@ -0,0 +1,33 @@
/*
* 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.rename
import com.google.gson.JsonObject
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.spring.facet.SpringFacet
import org.jetbrains.kotlin.idea.rename.AbstractUltimateRenameTest
abstract class AbstractSpringRenameTest : AbstractUltimateRenameTest() {
override fun getTestRoot() = "/spring/core/rename/"
override fun configExtra(rootDir: VirtualFile, renameParamsObject: JsonObject) {
val fileSet = SpringFacet.getInstance(module)!!.addFileSet("default", "default")!!
for (filePath in renameParamsObject.getAsJsonArray("springFileSet")) {
fileSet.addFile(rootDir.findFileByRelativePath(filePath.asString)!!)
}
}
}
@@ -0,0 +1,85 @@
/*
* 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.rename;
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("ultimate/testData/spring/core/rename")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class SpringRenameTestGenerated extends AbstractSpringRenameTest {
public void testAllFilesPresentInRename() throws Exception {
KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File("ultimate/testData/spring/core/rename"), Pattern.compile("^(.+)\\.test$"));
}
@TestMetadata("javaSpelRefToJava/javaSpelRefToJava.test")
public void testJavaSpelRefToJava_JavaSpelRefToJava() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/javaSpelRefToJava/javaSpelRefToJava.test");
doTest(fileName);
}
@TestMetadata("javaSpelRefToJavaAnnotated/javaSpelRefToJavaAnnotated.test")
public void testJavaSpelRefToJavaAnnotated_JavaSpelRefToJavaAnnotated() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/javaSpelRefToJavaAnnotated/javaSpelRefToJavaAnnotated.test");
doTest(fileName);
}
@TestMetadata("javaSpelRefToKt/javaSpelRefToKt.test")
public void testJavaSpelRefToKt_JavaSpelRefToKt() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/javaSpelRefToKt/javaSpelRefToKt.test");
doTest(fileName);
}
@TestMetadata("javaSpelRefToKtAnnotated/javaSpelRefToKtAnnotated.test")
public void testJavaSpelRefToKtAnnotated_JavaSpelRefToKtAnnotated() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/javaSpelRefToKtAnnotated/javaSpelRefToKtAnnotated.test");
doTest(fileName);
}
@TestMetadata("ktSpelRefToJava/ktSpelRefToJava.test")
public void testKtSpelRefToJava_KtSpelRefToJava() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/ktSpelRefToJava/ktSpelRefToJava.test");
doTest(fileName);
}
@TestMetadata("ktSpelRefToJavaAnnotated/ktSpelRefToJavaAnnotated.test")
public void testKtSpelRefToJavaAnnotated_KtSpelRefToJavaAnnotated() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/ktSpelRefToJavaAnnotated/ktSpelRefToJavaAnnotated.test");
doTest(fileName);
}
@TestMetadata("ktSpelRefToKt/ktSpelRefToKt.test")
public void testKtSpelRefToKt_KtSpelRefToKt() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/ktSpelRefToKt/ktSpelRefToKt.test");
doTest(fileName);
}
@TestMetadata("ktSpelRefToKtAnnotated/ktSpelRefToKtAnnotated.test")
public void testKtSpelRefToKtAnnotated_KtSpelRefToKtAnnotated() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/ktSpelRefToKtAnnotated/ktSpelRefToKtAnnotated.test");
doTest(fileName);
}
}
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.idea.spring.tests.gutter.AbstractSpringClassAnnotato
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.spring.tests.rename.AbstractSpringRenameTest
fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true")
@@ -56,5 +57,9 @@ fun main(args: Array<String>) {
testClass<AbstractGenerateSpringDependencyActionTest>() {
model("spring/core/generate", pattern = "^([\\w]+)\\.kt$", singleClass = true)
}
testClass<AbstractSpringRenameTest>() {
model("spring/core/rename", extension = "test", singleClass = true)
}
}
}
@@ -20,3 +20,6 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
val ULTIMATE_TEST_ROOT: String
get() = "${KotlinTestUtils.getHomeDirectory()}/ultimate"
val ULTIMATE_TEST_DATA_DIR: String
get() = "$ULTIMATE_TEST_ROOT/testData"