i18n: add bundle for idea/refactoring/rename

- Modify `text.parameter` value to `Parameter`;
use `text.parameter.0` in previous usages
- Add @Nls and @NonNls annotations to few places
This commit is contained in:
Roman Golyshev
2020-02-26 22:42:18 +03:00
committed by Dmitry Gridin
parent 4fc76e25a8
commit e1cb561398
18 changed files with 103 additions and 32 deletions
@@ -299,7 +299,7 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m
return (dummyFun.bodyExpression as KtLambdaExpression).functionLiteral.valueParameters.first()
}
fun <TDeclaration : KtDeclaration> createDeclaration(text: String): TDeclaration {
fun <TDeclaration : KtDeclaration> createDeclaration(@NonNls text: String): TDeclaration {
val file = createFile(text)
val declarations = file.declarations
checkWithAttachment(declarations.size == 1, { "unexpected ${declarations.size} declarations" }) {
@@ -22,6 +22,7 @@ import com.intellij.psi.SmartPointerManager
import com.intellij.psi.SmartPsiElementPointer
import com.intellij.psi.codeStyle.CodeStyleManager
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.psiUtil.PsiChildRange
@@ -31,7 +32,7 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.renderer.render
import java.util.*
fun KtPsiFactory.createExpressionByPattern(pattern: String, vararg args: Any, reformat: Boolean = true): KtExpression =
fun KtPsiFactory.createExpressionByPattern(@NonNls pattern: String, vararg args: Any, reformat: Boolean = true): KtExpression =
createByPattern(pattern, *args, reformat = reformat) { createExpression(it) }
fun KtPsiFactory.createValueArgumentListByPattern(pattern: String, vararg args: Any, reformat: Boolean = true): KtValueArgumentList =
@@ -856,6 +856,7 @@ setter.of.0.will.become.invisible.after.extraction = Setter of {0} will become i
text.0.1.must.be.moved.with.sealed.parent.class.and.all.its.subclasses={0} ''{1}'' must be moved with sealed parent class and all its subclasses
text.0.already.contains.1={0} already contains {1}
text.0.already.contains.nested.class.1={0} already contains nested class named {1}
text.0.already.declared.in.1={0} is already declared in {1}
text.0.have.no.inheritors.warning={0} doesn''t have inheritors\nPushing members down will result in them being deleted. Would you like to proceed?
text.0.in.1.will.override.corresponding.member.of.2.after.refactoring={0} in {1} will override corresponding member of {2} after refactoring
text.0.inherits.from.1.it.will.not.be.affected.by.refactoring={0} inherits from {1}.\nIt won''t be affected by the refactoring
@@ -867,6 +868,8 @@ text.0.uses.1.which.is.not.accessible.from.2={0} uses {1}, which is not accessib
text.0.uses.1.which.will.be.inaccessible.after.move={0} uses {1} which will be inaccessible after move
text.0.uses.1.which.will.not.be.accessible.from.subclass={0} uses {1} which won''t be accessible from the subclass.
text.0.uses.internal.1.which.will.be.inaccessible.after.move={0} uses internal {1} which will be inaccessible after move
text.0.will.be.shadowed.by.1={0} will be shadowed by {1}
text.0.will.clash.with.existing.1.in.2={0} after rename will clash with existing {1} in {2}
text.0.will.no.longer.be.accessible.after.signature.change={0} will no longer be accessible after signature change
text.all.declarations.must.belong.to.the.same.directory.or.class=All declarations must belong to the same directory or class
text.all=All
@@ -889,12 +892,16 @@ text.class.0.already.exists.in.package.1=Class {0} already exists in package {1}
text.class.0.already.exists.in.the.target.scope=Class {0} already exists in the target scope
text.class.0.is.final={0} is final
text.constructor=constructor
text.convert._it_.to.explicit.lambda.parameter=Convert 'it' to explicit lambda parameter
text.create.destructuring.declaration=Create destructuring declaration
text.create.single.variable=Create single variable
text.declaration=declaration
text.declarations.clash.move.0.destination.1.declared.in.scope.2=Following declarations would clash: to move {0} and destination {1} declared in scope {2}
text.default.value=\ // default value = {0}
text.destination.class.should.be.kotlin.class=Destination class must be a Kotlin class
text.do.you.want.to.rename.0.as.well=Do you want to rename {0}() as well?
text.do.you.want.to.rename.base.property.from.0=Do you want to rename base property from \n{0}
text.do.you.want.to.rename.base.property=Do you want to rename base property
text.duplicating.local.variable=Duplicating local variable ''{0}''
text.duplicating.parameter=Duplicating parameter ''{0}''
text.duplicating.property=Duplicating property ''{0}''
@@ -942,13 +949,14 @@ text.no.files.to.move=There is no given files to move
text.no.name.provided.for.type.alias=No name provided for type alias
text.no.package.corresponds.to.directory=No package corresponds to this directory
text.non.kotlin.0.will.not.be.affected.by.refactoring=Non-Kotlin {0} won''t be affected by the refactoring
text.overload=Overload
text.package.directive.dont.match.file.location=Package directive doesn't match file location
text.parameter.0=parameter ''{0}''
text.parameter.name=Parameter &name:\u0020
text.parameter.reference.can.t.be.safely.replaced.with.0.since.1.is.ambiguous.in.this.context=Parameter reference can''t be safely replaced with {0} since {1} is ambiguous in this context
text.parameter.reference.can.t.be.safely.replaced.with.0.since.target.function.can.t.be.referenced.in.this.context=Parameter reference can''t be safely replaced with {0} since target function can''t be referenced in this context
text.parameter.type=Parameter &type:\u0020
text.parameter=parameter ''{0}''
text.parameter=Parameter
text.parameters=&Parameters
text.proceed.with.extraction=Proceed with extraction
text.process.duplicates=Process Duplicates
@@ -966,6 +974,16 @@ text.refactoring.is.not.applicable.to.this.code.fragment=Refactoring is not appl
text.references.in.code.to.0.1.and.its.declarations=References in code to {0} {1} and its declarations
text.remove.0.no.longer.used=Remove {0} no longer used
text.remove=remove
text.rename.as.part.of.phrase=rename
text.rename.is.not.applicable.to.secondary.constructors=Rename is not applicable to secondary constructors
text.rename.is.not.applicable.to.synthetic.declarations=Rename is not applicable to synthetic declaration
text.rename.not.applicable.to.backing.field.reference=Rename is not applicable to backing field reference
text.rename.not.applicable.to.dynamically.invoked.methods=Rename is not applicable to dynamically invoked members
text.rename.overloads.title=Rename Overloads
text.rename.overloads.to=Rename overloads to:
text.rename.parameters.in.hierarchy.to=Rename parameter in hierarchy to:
text.rename.parameters.title=Rename Parameters
text.rename.warning=Rename warning
text.sealed.class.0.must.be.moved.with.all.its.subclasses=Sealed class ''{0}'' must be moved with all its subclasses
text.select.target.code.block.file=Select target code block / file
text.select.target.code.block=Select target code block
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.util.application
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.project.Project
import org.jetbrains.annotations.Nls
fun <T> runReadAction(action: () -> T): T {
return ApplicationManager.getApplication().runReadAction<T>(action)
@@ -28,15 +29,15 @@ fun <T> runWriteAction(action: () -> T): T {
return ApplicationManager.getApplication().runWriteAction<T>(action)
}
fun Project.executeWriteCommand(name: String, command: () -> Unit) {
fun Project.executeWriteCommand(@Nls name: String, command: () -> Unit) {
CommandProcessor.getInstance().executeCommand(this, { runWriteAction(command) }, name, null)
}
fun <T> Project.executeWriteCommand(name: String, groupId: Any? = null, command: () -> T): T {
fun <T> Project.executeWriteCommand(@Nls name: String, groupId: Any? = null, command: () -> T): T {
return executeCommand<T>(name, groupId) { runWriteAction(command) }
}
fun <T> Project.executeCommand(name: String, groupId: Any? = null, command: () -> T): T {
fun <T> Project.executeCommand(@Nls name: String, groupId: Any? = null, command: () -> T): T {
@Suppress("UNCHECKED_CAST") var result: T = null as T
CommandProcessor.getInstance().executeCommand(this, { result = command() }, name, groupId)
@Suppress("USELESS_CAST")
@@ -348,7 +348,7 @@ class KotlinChangeSignatureDialog(
for (item in parametersTableModel.items) {
if (item.typeCodeFragment.getTypeInfo(isCovariant = true, forPreview = false, reanalyse = true).type == null) {
val paramText = if (item.parameter != parametersTableModel.receiver)
KotlinBundle.message("text.parameter", item.parameter.name)
KotlinBundle.message("text.parameter.0", item.parameter.name)
else
KotlinBundle.message("text.receiver")
if (Messages.showOkCancelDialog(
@@ -350,7 +350,7 @@ class KotlinChangeSignatureDialog(
for (item in parametersTableModel.items) {
if (item.typeCodeFragment.getTypeInfo(isCovariant = true, forPreview = false).type == null) {
val paramText = if (item.parameter != parametersTableModel.receiver)
KotlinBundle.message("text.parameter", item.parameter.name)
KotlinBundle.message("text.parameter.0", item.parameter.name)
else
KotlinBundle.message("text.receiver")
if (Messages.showOkCancelDialog(
@@ -48,6 +48,7 @@ import com.intellij.ui.components.JBList
import com.intellij.usageView.UsageViewTypeLocation
import com.intellij.util.VisibilityUtil
import com.intellij.util.containers.MultiMap
import org.jetbrains.annotations.Nls
import org.jetbrains.kotlin.asJava.LightClassUtil
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
import org.jetbrains.kotlin.asJava.getAccessorLightMethods
@@ -852,7 +853,7 @@ val PsiElement.isInsideInjectedFragment: Boolean
fun checkSuperMethods(
declaration: KtDeclaration,
ignore: Collection<PsiElement>?,
actionString: String
@Nls actionString: String
): List<PsiElement> {
fun getClassDescriptions(overriddenElementsToDescriptor: Map<PsiElement, CallableDescriptor>): List<String> {
return overriddenElementsToDescriptor.entries.map { entry ->
@@ -49,6 +49,7 @@ import com.intellij.ui.components.JBList
import com.intellij.usageView.UsageViewTypeLocation
import com.intellij.util.VisibilityUtil
import com.intellij.util.containers.MultiMap
import org.jetbrains.annotations.Nls
import org.jetbrains.kotlin.asJava.LightClassUtil
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
import org.jetbrains.kotlin.asJava.getAccessorLightMethods
@@ -853,7 +854,7 @@ val PsiElement.isInsideInjectedFragment: Boolean
fun checkSuperMethods(
declaration: KtDeclaration,
ignore: Collection<PsiElement>?,
actionString: String
@Nls actionString: String
): List<PsiElement> {
fun getClassDescriptions(overriddenElementsToDescriptor: Map<PsiElement, CallableDescriptor>): List<String> {
return overriddenElementsToDescriptor.entries.map { entry ->
@@ -14,6 +14,7 @@ import com.intellij.usageView.UsageInfo
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringSettings
@@ -43,9 +44,9 @@ class AutomaticOverloadsRenamer(function: KtNamedFunction, newName: String) : Au
suggestAllNames(function.name, newName)
}
override fun getDialogTitle() = "Rename Overloads"
override fun getDialogDescription() = "Rename overloads to:"
override fun entityName() = "Overload"
override fun getDialogTitle() = KotlinBundle.message("text.rename.overloads.title")
override fun getDialogDescription() = KotlinBundle.message("text.rename.overloads.to")
override fun entityName() = KotlinBundle.message("text.overload")
override fun isSelectedByDefault(): Boolean = true
}
@@ -13,6 +13,7 @@ import com.intellij.refactoring.rename.naming.AutomaticRenamer
import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory
import com.intellij.usageView.UsageInfo
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringSettings
import org.jetbrains.kotlin.idea.refactoring.canRefactor
import org.jetbrains.kotlin.idea.search.declarationsSearch.HierarchySearchRequest
@@ -43,11 +44,11 @@ class AutomaticParameterRenamer(element: KtParameter, newName: String) : Automat
suggestAllNames(element.name, newName.quoteIfNeeded())
}
override fun getDialogTitle() = "Rename Parameters"
override fun getDialogTitle() = KotlinBundle.message("text.rename.parameters.title")
override fun getDialogDescription() = "Rename parameter in hierarchy to:"
override fun getDialogDescription() = RefactoringBundle.message("rename.parameters.hierarchy")
override fun entityName() = "Parameter"
override fun entityName() = KotlinBundle.message("text.parameter")
override fun isSelectedByDefault() = true
}
@@ -10,7 +10,9 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.refactoring.RefactoringBundle
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.core.util.CodeInsightUtils
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
@@ -24,7 +26,13 @@ class RenameBackingFieldReferenceHandler : KotlinVariableInplaceRenameHandler()
override fun invoke(project: Project, editor: Editor?, file: PsiFile?, dataContext: DataContext) {
editor?.let {
CodeInsightUtils.showErrorHint(project, editor, "Rename is not applicable to backing field reference", "Rename", null)
CodeInsightUtils.showErrorHint(
project,
editor,
KotlinBundle.message("text.rename.not.applicable.to.backing.field.reference"),
RefactoringBundle.message("rename.title"),
null
)
}
}
@@ -11,6 +11,8 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.refactoring.RefactoringBundle
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.core.util.CodeInsightUtils
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
@@ -28,7 +30,13 @@ class RenameDynamicMemberHandler : KotlinVariableInplaceRenameHandler() {
override fun invoke(project: Project, editor: Editor?, file: PsiFile?, dataContext: DataContext) {
super.invoke(project, editor, file, dataContext)
editor?.let {
CodeInsightUtils.showErrorHint(project, it, "Rename is not applicable to dynamically invoked members", "Rename", null)
CodeInsightUtils.showErrorHint(
project,
it,
KotlinBundle.message("text.rename.not.applicable.to.dynamically.invoked.methods"),
RefactoringBundle.message("rename.title"),
null
)
}
}
@@ -10,6 +10,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Pass
import com.intellij.psi.*
import com.intellij.psi.search.SearchScope
import com.intellij.refactoring.RefactoringBundle
import com.intellij.refactoring.listeners.RefactoringElementListener
import com.intellij.refactoring.rename.*
import com.intellij.refactoring.util.CommonRefactoringUtil
@@ -25,6 +26,7 @@ import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper.InternalNameMapper.de
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper.InternalNameMapper.getModuleNameSuffix
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper.InternalNameMapper.mangleInternalName
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
import org.jetbrains.kotlin.idea.refactoring.*
import org.jetbrains.kotlin.idea.references.KtReference
@@ -111,7 +113,7 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
javaMethodProcessorInstance.substituteElementToRename(wrappedMethod, editor)
}
else -> {
val chosenElements = checkSuperMethods(element, null, "rename")
val chosenElements = checkSuperMethods(element, null, KotlinBundle.message("text.rename.as.part.of.phrase"))
if (chosenElements.size > 1) FunctionWithSupersWrapper(element, chosenElements) else wrappedMethod
}
}
@@ -154,7 +156,7 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
}
else -> {
val declaration = element.unwrapped as? KtNamedFunction ?: return
checkSuperMethodsWithPopup(declaration, deepestSuperMethods.toList(), "Rename", editor) {
checkSuperMethodsWithPopup(declaration, deepestSuperMethods.toList(), RefactoringBundle.message("rename.title"), editor) {
preprocessAndPass(if (it.size > 1) FunctionWithSupersWrapper(declaration, it) else wrappedMethod ?: element)
}
}
@@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.intentions.ReplaceItWithExplicitFunctionLiteralParamIntention
import org.jetbrains.kotlin.idea.intentions.isAutoCreatedItUsage
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
@@ -35,7 +36,7 @@ class RenameKotlinImplicitLambdaParameter : KotlinVariableInplaceRenameHandler()
override fun invoke(project: Project, editor: Editor?, file: PsiFile?, dataContext: DataContext) {
val intention = ReplaceItWithExplicitFunctionLiteralParamIntention()
project.executeWriteCommand("Convert 'it' to explicit lambda parameter") {
project.executeWriteCommand(KotlinBundle.message("text.convert._it_.to.explicit.lambda.parameter")) {
if (file != null) intention.invoke(project, editor, file)
}
}
@@ -14,6 +14,7 @@ import com.intellij.psi.*
import com.intellij.psi.search.SearchScope
import com.intellij.psi.search.searches.DirectClassInheritorsSearch
import com.intellij.psi.search.searches.OverridingMethodsSearch
import com.intellij.refactoring.RefactoringBundle
import com.intellij.refactoring.listeners.RefactoringElementListener
import com.intellij.refactoring.rename.RenameProcessor
import com.intellij.refactoring.util.MoveRenameUsageInfo
@@ -31,6 +32,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
@@ -112,7 +114,7 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
val what = UsageViewUtil.getType(declaration).capitalize()
val withWhat = candidate.renderDescription()
val where = candidate.representativeContainer()?.renderDescription() ?: return
val message = "$what after rename will clash with existing $withWhat in $where"
val message = KotlinBundle.message("text.0.will.clash.with.existing.1.in.2", what, withWhat, where)
result += BasicUnresolvableCollisionUsageInfo(candidate, candidate, message)
}
@@ -214,10 +216,15 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
val containsText: String? =
deepestSuperDeclaration.fqName?.parent()?.asString() ?: (deepestSuperDeclaration.parent as? KtClassOrObject)?.name
val message = if (containsText != null)
KotlinBundle.message("text.do.you.want.to.rename.base.property.from.0", containsText)
else
KotlinBundle.message("text.do.you.want.to.rename.base.property")
val result = Messages.showYesNoCancelDialog(
deepestSuperDeclaration.project,
if (containsText != null) "Do you want to rename base property from \n$containsText" else "Do you want to rename base property",
"Rename warning",
message,
KotlinBundle.message("text.rename.warning"),
Messages.getQuestionIcon()
)
@@ -271,7 +278,7 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
}
val superPsiMethods = listOfNotNull(deepestSuperDeclaration.getRepresentativeLightMethod())
checkSuperMethodsWithPopup(callableDeclaration, superPsiMethods, "Rename", editor) {
checkSuperMethodsWithPopup(callableDeclaration, superPsiMethods, RefactoringBundle.message("rename.title"), editor) {
preprocessAndPass(if (it.size > 1) deepestSuperDeclaration else callableDeclaration)
}
}
@@ -307,8 +314,8 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
val accessorToRename = if (element == getter) setter else getter
val newAccessorName = if (element == getter) JvmAbi.setterName(newPropertyName) else JvmAbi.getterName(newPropertyName)
if (ApplicationManager.getApplication().isUnitTestMode || Messages.showYesNoDialog(
"Do you want to rename ${accessorToRename.name}() as well?",
"Rename",
KotlinBundle.message("text.do.you.want.to.rename.0.as.well", accessorToRename.name),
RefactoringBundle.message("rename.title"),
Messages.getQuestionIcon()
) == Messages.YES
) {
@@ -12,7 +12,9 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.refactoring.RefactoringBundle
import com.intellij.refactoring.rename.RenameHandler
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.util.CodeInsightUtils
import org.jetbrains.kotlin.psi.*
@@ -38,7 +40,13 @@ class RenameOnSecondaryConstructorHandler : RenameHandler {
override fun isRenaming(dataContext: DataContext): Boolean = isAvailableOnDataContext(dataContext)
override fun invoke(project: Project, editor: Editor, file: PsiFile, dataContext: DataContext?) {
CodeInsightUtils.showErrorHint(project, editor, "Rename is not applicable to secondary constructors", "Rename", null)
CodeInsightUtils.showErrorHint(
project,
editor,
KotlinBundle.message("text.rename.is.not.applicable.to.secondary.constructors"),
RefactoringBundle.message("rename.title"),
null
)
}
override fun invoke(project: Project, elements: Array<out PsiElement>, dataContext: DataContext?) {
@@ -11,7 +11,9 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.refactoring.RefactoringBundle
import com.intellij.refactoring.rename.RenameHandler
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.core.util.CodeInsightUtils
import org.jetbrains.kotlin.idea.statistics.FUSEventGroups
@@ -30,7 +32,13 @@ class RenameSyntheticDeclarationByReferenceHandler : RenameHandler {
override fun isRenaming(dataContext: DataContext) = isAvailableOnDataContext(dataContext)
override fun invoke(project: Project, editor: Editor, file: PsiFile, dataContext: DataContext?) {
CodeInsightUtils.showErrorHint(project, editor, "Rename is not applicable to synthetic declaration", "Rename", null)
CodeInsightUtils.showErrorHint(
project,
editor,
KotlinBundle.message("text.rename.is.not.applicable.to.synthetic.declarations"),
RefactoringBundle.message("rename.title"),
null
)
KotlinFUSLogger.log(FUSEventGroups.Refactoring, this::class.java.name)
}
@@ -11,6 +11,7 @@ import com.intellij.refactoring.util.MoveRenameUsageInfo
import com.intellij.usageView.UsageInfo
import com.intellij.usageView.UsageViewUtil
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
@@ -160,9 +161,9 @@ internal fun checkRedeclarations(
for (candidateDescriptor in getSiblingsWithNewName()) {
val candidate = (candidateDescriptor as? DeclarationDescriptorWithSource)?.source?.getPsi() as? KtNamedDeclaration ?: continue
if (overloadChecker != null && overloadChecker.isOverloadable(descriptor, candidateDescriptor)) continue
val what = candidate.renderDescription().capitalize()
val what = candidate.renderDescription()
val where = candidate.representativeContainer()?.renderDescription() ?: continue
val message = "$what is already declared in $where"
val message = KotlinBundle.message("text.0.already.declared.in.1", what, where).capitalize()
result += BasicUnresolvableCollisionUsageInfo(candidate, candidate, message)
}
}
@@ -189,7 +190,11 @@ fun reportShadowing(
) {
val candidate = DescriptorToSourceUtilsIde.getAnyDeclaration(declaration.project, candidateDescriptor) as? PsiNamedElement ?: return
if (declaration.parent == candidate.parent) return
val message = "${declaration.renderDescription().capitalize()} will be shadowed by ${candidate.renderDescription()}"
val message = KotlinBundle.message(
"text.0.will.be.shadowed.by.1",
declaration.renderDescription(),
candidate.renderDescription()
).capitalize()
result += BasicUnresolvableCollisionUsageInfo(refElement, elementToBindUsageInfoTo, message)
}