Resource Bundles: Add Rename tests for bundle files and properties

#KT-6946 In Progress
This commit is contained in:
Alexey Sedunov
2015-09-23 17:35:00 +03:00
parent 5af4101f7d
commit 44fd9d17ed
16 changed files with 104 additions and 1 deletions
@@ -0,0 +1,2 @@
## FIND_FILE_USAGES
foo.bar = test
@@ -0,0 +1,5 @@
package org.jetbrains.annotations
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.LOCAL_VARIABLE, AnnotationTarget.FIELD)
public annotation class PropertyKey(public val resourceBundle: String)
@@ -0,0 +1,10 @@
import org.jetbrains.annotations.PropertyKey
private val BUNDLE_NAME = "BarBundle"
public fun message(@PropertyKey(resourceBundle = "BarBundle") key: String) = key
public fun message2(@PropertyKey(resourceBundle = BUNDLE_NAME) key: String) = key
fun test() {
message("foo.bar")
}
@@ -0,0 +1,2 @@
## FIND_FILE_USAGES
foo.bar = test
@@ -0,0 +1,5 @@
package org.jetbrains.annotations
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.LOCAL_VARIABLE, AnnotationTarget.FIELD)
public annotation class PropertyKey(public val resourceBundle: String)
@@ -0,0 +1,10 @@
import org.jetbrains.annotations.PropertyKey
private val BUNDLE_NAME = "FooBundle"
public fun message(@PropertyKey(resourceBundle = "FooBundle") key: String) = key
public fun message2(@PropertyKey(resourceBundle = BUNDLE_NAME) key: String) = key
fun test() {
message("foo.bar")
}
@@ -0,0 +1,5 @@
{
"type": "FILE",
"file": "FooBundle.properties",
"newName": "BarBundle.properties"
}
@@ -0,0 +1,5 @@
package org.jetbrains.annotations
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.LOCAL_VARIABLE, AnnotationTarget.FIELD)
public annotation class PropertyKey(public val resourceBundle: String)
@@ -0,0 +1 @@
bar.foo = test
@@ -0,0 +1,8 @@
import org.jetbrains.annotations.PropertyKey
public fun message(@PropertyKey(resourceBundle = "TestBundle") key: String) = key
fun test() {
@PropertyKey(resourceBundle = "TestBundle") val s1 = "bar.foo"
message("bar.foo")
}
@@ -0,0 +1,5 @@
package org.jetbrains.annotations
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.LOCAL_VARIABLE, AnnotationTarget.FIELD)
public annotation class PropertyKey(public val resourceBundle: String)
@@ -0,0 +1 @@
foo.bar = test
@@ -0,0 +1,8 @@
import org.jetbrains.annotations.PropertyKey
public fun message(@PropertyKey(resourceBundle = "TestBundle") key: String) = key
fun test() {
@PropertyKey(resourceBundle = "TestBundle") val s1 = "foo.bar"
message("foo.bar")
}
@@ -0,0 +1,6 @@
{
"type": "BUNDLE_PROPERTY",
"file": "TestBundle.properties",
"oldName": "foo.bar",
"newName": "bar.foo"
}
@@ -19,6 +19,8 @@ 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.lang.properties.psi.PropertiesFile
import com.intellij.lang.properties.psi.Property
import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.module.Module
@@ -66,7 +68,8 @@ private enum class RenameType {
KOTLIN_PROPERTY,
KOTLIN_PACKAGE,
MARKED_ELEMENT,
FILE
FILE,
BUNDLE_PROPERTY
}
public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
@@ -102,6 +105,7 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
RenameType.KOTLIN_PACKAGE -> renameKotlinPackageTest(renameObject, context)
RenameType.MARKED_ELEMENT -> renameMarkedElement(renameObject, context)
RenameType.FILE -> renameFile(renameObject, context)
RenameType.BUNDLE_PROPERTY -> renameBundleProperty(renameObject, context)
}
if (hintDirective != null) {
@@ -244,6 +248,20 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
}
}
private fun renameBundleProperty(renameParamsObject: JsonObject, context: TestContext) {
val file = renameParamsObject.getString("file")
val oldName = renameParamsObject.getString("oldName")
val newName = renameParamsObject.getString("newName")
doTestCommittingDocuments { rootDir, rootAfter ->
val mainFile = rootDir.findChild(file)!!
val psiFile = PsiManager.getInstance(context.project).findFile(mainFile) as PropertiesFile
val property = psiFile.findPropertyByKey(oldName) as Property
runRenameProcessor(context, newName, property, true, true)
}
}
private fun doRenameInKotlinClassOrPackage(
renameParamsObject: JsonObject, context: TestContext, findDescriptorToRename: (JetScope) -> DeclarationDescriptor
) {
@@ -113,6 +113,18 @@ public class RenameTestGenerated extends AbstractRenameTest {
doTest(fileName);
}
@TestMetadata("renameBundle/renameBundle.test")
public void testRenameBundle_RenameBundle() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameBundle/renameBundle.test");
doTest(fileName);
}
@TestMetadata("renameBundleProperty/renameBundleProperty.test")
public void testRenameBundleProperty_RenameBundleProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameBundleProperty/renameBundleProperty.test");
doTest(fileName);
}
@TestMetadata("renameCompareTo/compareTo.test")
public void testRenameCompareTo_CompareTo() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameCompareTo/compareTo.test");