Resource Bundles: Add Rename tests for bundle files and properties
#KT-6946 In Progress
This commit is contained in:
@@ -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)
|
||||||
+1
@@ -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)
|
||||||
+1
@@ -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")
|
||||||
|
}
|
||||||
+6
@@ -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.JsonObject
|
||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
import com.intellij.codeInsight.TargetElementUtilBase
|
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.extensions.Extensions
|
||||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
@@ -66,7 +68,8 @@ private enum class RenameType {
|
|||||||
KOTLIN_PROPERTY,
|
KOTLIN_PROPERTY,
|
||||||
KOTLIN_PACKAGE,
|
KOTLIN_PACKAGE,
|
||||||
MARKED_ELEMENT,
|
MARKED_ELEMENT,
|
||||||
FILE
|
FILE,
|
||||||
|
BUNDLE_PROPERTY
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
|
public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
|
||||||
@@ -102,6 +105,7 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
|
|||||||
RenameType.KOTLIN_PACKAGE -> renameKotlinPackageTest(renameObject, context)
|
RenameType.KOTLIN_PACKAGE -> renameKotlinPackageTest(renameObject, context)
|
||||||
RenameType.MARKED_ELEMENT -> renameMarkedElement(renameObject, context)
|
RenameType.MARKED_ELEMENT -> renameMarkedElement(renameObject, context)
|
||||||
RenameType.FILE -> renameFile(renameObject, context)
|
RenameType.FILE -> renameFile(renameObject, context)
|
||||||
|
RenameType.BUNDLE_PROPERTY -> renameBundleProperty(renameObject, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hintDirective != null) {
|
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(
|
private fun doRenameInKotlinClassOrPackage(
|
||||||
renameParamsObject: JsonObject, context: TestContext, findDescriptorToRename: (JetScope) -> DeclarationDescriptor
|
renameParamsObject: JsonObject, context: TestContext, findDescriptorToRename: (JetScope) -> DeclarationDescriptor
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -113,6 +113,18 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("renameCompareTo/compareTo.test")
|
||||||
public void testRenameCompareTo_CompareTo() throws Exception {
|
public void testRenameCompareTo_CompareTo() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameCompareTo/compareTo.test");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameCompareTo/compareTo.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user