Move refactoring: suggest file name starting with an uppercase letter
Fixed #KT-30342
This commit is contained in:
committed by
Igor Yakovlev
parent
8219d9853c
commit
d1cbee44f1
@@ -125,11 +125,10 @@ fun KtElement.processInternalReferencesToUpdateOnPackageNameChange(
|
||||
val declaration by lazy {
|
||||
var result = DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) ?: return@lazy null
|
||||
|
||||
if (descriptor.isCompanionObject()
|
||||
&& bindingContext[BindingContext.SHORT_REFERENCE_TO_COMPANION_OBJECT, refExpr] != null
|
||||
if (descriptor.isCompanionObject() &&
|
||||
bindingContext[BindingContext.SHORT_REFERENCE_TO_COMPANION_OBJECT, refExpr] !== null
|
||||
) {
|
||||
if (result !is KtObjectDeclaration) return@lazy null
|
||||
result = result.containingClassOrObject ?: result
|
||||
result = (result as? KtObjectDeclaration)?.containingClassOrObject ?: result
|
||||
}
|
||||
|
||||
result
|
||||
@@ -148,10 +147,10 @@ fun KtElement.processInternalReferencesToUpdateOnPackageNameChange(
|
||||
}
|
||||
|
||||
if (!isExtension) {
|
||||
if (!(containingDescriptor is PackageFragmentDescriptor
|
||||
|| containingDescriptor is ClassDescriptor && containingDescriptor.kind == ClassKind.OBJECT
|
||||
|| descriptor is JavaCallableMemberDescriptor && ((declaration as? PsiMember)?.hasModifierProperty(PsiModifier.STATIC) == true))
|
||||
) return null
|
||||
val isCompatibleDescriptor = containingDescriptor is PackageFragmentDescriptor ||
|
||||
containingDescriptor is ClassDescriptor && containingDescriptor.kind == ClassKind.OBJECT ||
|
||||
descriptor is JavaCallableMemberDescriptor && ((declaration as? PsiMember)?.hasModifierProperty(PsiModifier.STATIC) == true)
|
||||
if (!isCompatibleDescriptor) return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,12 +386,11 @@ private fun isCallableReference(reference: PsiReference): Boolean {
|
||||
|
||||
fun guessNewFileName(declarationsToMove: Collection<KtNamedDeclaration>): String? {
|
||||
if (declarationsToMove.isEmpty()) return null
|
||||
|
||||
val representative = declarationsToMove.singleOrNull()
|
||||
?: declarationsToMove.filterIsInstance<KtClassOrObject>().singleOrNull()
|
||||
representative?.let { return "${it.name}.${KotlinFileType.EXTENSION}" }
|
||||
|
||||
return declarationsToMove.first().containingFile.name
|
||||
val newFileName = representative?.run { "$name.${KotlinFileType.EXTENSION}" }
|
||||
?: declarationsToMove.first().containingFile.name
|
||||
return newFileName.capitalize()
|
||||
}
|
||||
|
||||
// returns true if successful
|
||||
|
||||
+1
-1
@@ -581,7 +581,7 @@ public class MoveTestGenerated extends AbstractMoveTest {
|
||||
|
||||
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/mutualDependency/mutualDependency.test")
|
||||
public void testKotlin_moveTopLevelDeclarations_misc_mutualDependency_MutualDependency() throws Exception {
|
||||
runTest("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/mutualDependency/mutualDependency.test");
|
||||
runTest("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/MutualDependency/mutualDependency.test");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/nonCodeUsagesWithQuotedName/nonCodeUsageWithQuotedName.test")
|
||||
|
||||
Reference in New Issue
Block a user