diff --git a/ChangeLog.md b/ChangeLog.md index 54315e91c0d..df52abf4e9c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -242,6 +242,7 @@ Using 'this' as function argument in constructor of non-final class - [`KT-13207`](https://youtrack.jetbrains.com/issue/KT-13207) Safe delete: Fix exception when removing any function in 2016.2 - [`KT-12945`](https://youtrack.jetbrains.com/issue/KT-12945) Rename: Fix function description in super method warning dialog - [`KT-12922`](https://youtrack.jetbrains.com/issue/KT-12922) Introduce Variable: Do not suggest expressions without type +- [`KT-12943`](https://youtrack.jetbrains.com/issue/KT-12943) Rename: Show function signatures in "Rename Overloads" dialog ##### New features diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRenderer.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRenderer.kt index ee07cc457ad..ac5294b69be 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRenderer.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRenderer.kt @@ -190,6 +190,7 @@ interface DescriptorRendererOptions { var renderAccessors: Boolean var renderDefaultAnnotationArguments: Boolean var alwaysRenderModifiers: Boolean + var renderConstructorKeyword: Boolean } object ExcludedTypeAnnotations { diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index 346f703b784..4001e2ddc03 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -626,10 +626,14 @@ internal class DescriptorRendererImpl( renderVisibility(constructor.visibility, builder) renderMemberKind(constructor, builder) - builder.append(renderKeyword("constructor")) + if (renderConstructorKeyword) { + builder.append(renderKeyword("constructor")) + } if (secondaryConstructorsAsPrimary) { val classDescriptor = constructor.containingDeclaration - builder.append(" ") + if (renderConstructorKeyword) { + builder.append(" ") + } renderName(classDescriptor, builder) renderTypeParameters(constructor.typeParameters, builder, false) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererOptionsImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererOptionsImpl.kt index 2c805df6f27..9fd102e497f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererOptionsImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererOptionsImpl.kt @@ -97,4 +97,6 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions { + ExcludedTypeAnnotations.internalAnnotationsForResolve) override var alwaysRenderModifiers by property(false) + + override var renderConstructorKeyword by property(true) } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt b/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt index ad303f1a401..fac545f36d1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt @@ -28,16 +28,24 @@ import com.intellij.usageView.UsageViewShortNameLocation import com.intellij.usageView.UsageViewTypeLocation import org.jetbrains.kotlin.asJava.classes.KtLightClassForFacade import org.jetbrains.kotlin.asJava.unwrapped -import org.jetbrains.kotlin.descriptors.ConstructorDescriptor -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.idea.refactoring.rename.RenameJavaSyntheticPropertyHandler import org.jetbrains.kotlin.idea.refactoring.rename.RenameKotlinPropertyProcessor import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe class KotlinElementDescriptionProvider : ElementDescriptionProvider { + companion object { + val REFACTORING_RENDERER = DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES.withOptions { + withoutReturnType = true + renderConstructorKeyword = false + } + } + override fun getElementDescription(element: PsiElement, location: ElementDescriptionLocation): String? { val shouldUnwrap = location !is UsageViewShortNameLocation && location !is UsageViewLongNameLocation val targetElement = if (shouldUnwrap) element.unwrapped ?: element else element @@ -57,34 +65,31 @@ class KotlinElementDescriptionProvider : ElementDescriptionProvider { else -> null } - fun targetDescriptor(): DeclarationDescriptor? { - val descriptor = (targetElement as KtDeclaration).descriptor ?: return null - if (descriptor is ConstructorDescriptor) { - return descriptor.containingDeclaration - } - return descriptor - } - if (targetElement !is PsiNamedElement || targetElement.language != KotlinLanguage.INSTANCE) return null return when(location) { is UsageViewTypeLocation -> elementKind() is UsageViewShortNameLocation, is UsageViewLongNameLocation -> targetElement.name is RefactoringDescriptionLocation -> { val kind = elementKind() ?: return null - val descriptor = targetDescriptor() ?: return null - val desc = - if (location.includeParent() && targetElement !is KtTypeParameter && targetElement !is KtParameter) { - DescriptorUtils.getFqName(descriptor).asString() - } - else { - descriptor.name.asString() - } + val descriptor = (targetElement as KtDeclaration).descriptor ?: return null + val renderFqName = location.includeParent() && + targetElement !is KtTypeParameter && + targetElement !is KtParameter && + targetElement !is KtConstructor<*> + val desc = when (descriptor) { + is FunctionDescriptor -> { + val baseText = REFACTORING_RENDERER.render(descriptor) + val parentFqName = if (renderFqName) descriptor.containingDeclaration.fqNameSafe else null + if (parentFqName?.isRoot ?: true) baseText else "${parentFqName!!.asString()}.$baseText" + } + else -> if (renderFqName) DescriptorUtils.getFqName(descriptor).asString() else descriptor.name.asString() + } "$kind ${CommonRefactoringUtil.htmlEmphasize(desc)}" } is HighlightUsagesDescriptionLocation -> { val kind = elementKind() ?: return null - val descriptor = targetDescriptor() ?: return null + val descriptor = (targetElement as KtDeclaration).descriptor ?: return null "$kind ${descriptor.name.asString()}" } else -> null diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt index 11ed586c2dd..c845816dc7b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt @@ -251,10 +251,7 @@ class MoveKotlinDeclarationsProcessor( } } - fun render(declaration: PsiElement): String { - val text = RefactoringUIUtil.getDescription(declaration, false) - return if (declaration is KtFunction) "$text()" else text - } + fun render(declaration: PsiElement) = RefactoringUIUtil.getDescription(declaration, false) fun checkVisibilityInUsages(usages: List) { val declarationToContainers = HashMap>() diff --git a/idea/testData/intentions/convertPropertyToFunction/existingFunConflict.kt b/idea/testData/intentions/convertPropertyToFunction/existingFunConflict.kt index 000d0661beb..f9ae90fb4b7 100644 --- a/idea/testData/intentions/convertPropertyToFunction/existingFunConflict.kt +++ b/idea/testData/intentions/convertPropertyToFunction/existingFunConflict.kt @@ -1,4 +1,4 @@ -// SHOULD_FAIL_WITH: Function foo already exists +// SHOULD_FAIL_WITH: Function foo() on A already exists class A(val n: Int) { val foo: Boolean = n > 1 } diff --git a/idea/testData/intentions/moveToCompanion/overriddenFunction.kt b/idea/testData/intentions/moveToCompanion/overriddenFunction.kt index 16ef47f6a48..badafdd738a 100644 --- a/idea/testData/intentions/moveToCompanion/overriddenFunction.kt +++ b/idea/testData/intentions/moveToCompanion/overriddenFunction.kt @@ -1,4 +1,4 @@ -// SHOULD_FAIL_WITH: Function foo is overridden by declaration(s) in a subclass +// SHOULD_FAIL_WITH: Function foo() is overridden by declaration(s) in a subclass open class A { open fun foo() { diff --git a/idea/testData/refactoring/changeSignature/AddNewReceiverConflictMessages.txt b/idea/testData/refactoring/changeSignature/AddNewReceiverConflictMessages.txt index a46d2af2029..f0cded6bfde 100644 --- a/idea/testData/refactoring/changeSignature/AddNewReceiverConflictMessages.txt +++ b/idea/testData/refactoring/changeSignature/AddNewReceiverConflictMessages.txt @@ -1 +1 @@ -Function length will no longer be accessible after signature change \ No newline at end of file +Function length() will no longer be accessible after signature change \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/basic/localFunctionRef.kt.conflicts b/idea/testData/refactoring/extractFunction/basic/localFunctionRef.kt.conflicts index 8c70616458b..71ad6d3a2ad 100644 --- a/idea/testData/refactoring/extractFunction/basic/localFunctionRef.kt.conflicts +++ b/idea/testData/refactoring/extractFunction/basic/localFunctionRef.kt.conflicts @@ -1 +1 @@ -Function foo.bar will no longer be accessible after extraction \ No newline at end of file +Function foo.bar() will no longer be accessible after extraction \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/basic/misdirectedRef.kt.conflicts b/idea/testData/refactoring/extractFunction/basic/misdirectedRef.kt.conflicts index 8c70616458b..71ad6d3a2ad 100644 --- a/idea/testData/refactoring/extractFunction/basic/misdirectedRef.kt.conflicts +++ b/idea/testData/refactoring/extractFunction/basic/misdirectedRef.kt.conflicts @@ -1 +1 @@ -Function foo.bar will no longer be accessible after extraction \ No newline at end of file +Function foo.bar() will no longer be accessible after extraction \ No newline at end of file diff --git a/idea/testData/refactoring/extractFunction/basic/unresolvedWrongReceiver.kt.conflicts b/idea/testData/refactoring/extractFunction/basic/unresolvedWrongReceiver.kt.conflicts index 2020837f73d..d2073c6418e 100644 --- a/idea/testData/refactoring/extractFunction/basic/unresolvedWrongReceiver.kt.conflicts +++ b/idea/testData/refactoring/extractFunction/basic/unresolvedWrongReceiver.kt.conflicts @@ -1 +1 @@ -Function A.unresolved will no longer be accessible after extraction \ No newline at end of file +Function A.unresolved() on B will no longer be accessible after extraction \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackageWithConflicts/conflicts.txt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackageWithConflicts/conflicts.txt index c653c57f588..8f39a515003 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackageWithConflicts/conflicts.txt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveClassToPackageWithConflicts/conflicts.txt @@ -1,4 +1,4 @@ Class Test uses class Foo which will be inaccessible after move -Class Test uses function foo() which will be inaccessible after move +Class Test uses function foo(Foo) which will be inaccessible after move Method bar() uses class Test which will be inaccessible after move Variable t uses class Test which will be inaccessible after move \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/conflicts.txt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/conflicts.txt index d84670a865b..c181c625b2a 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/conflicts.txt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveFunctionToPackageWithConflicts/conflicts.txt @@ -1,4 +1,4 @@ Function bar() uses function test() which will be inaccessible after move Function test() uses class Foo which will be inaccessible after move -Function test() uses function foo() which will be inaccessible after move +Function test() uses function foo(Foo) which will be inaccessible after move Method bar() uses function test() which will be inaccessible after move \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackageWithConflicts/conflicts.txt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackageWithConflicts/conflicts.txt index 95f62b709b1..2f1a7f43272 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackageWithConflicts/conflicts.txt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/moveObjectToPackageWithConflicts/conflicts.txt @@ -1,4 +1,4 @@ Method bar() uses object Test which will be inaccessible after move Object Test uses class Foo which will be inaccessible after move -Object Test uses function foo() which will be inaccessible after move +Object Test uses function foo(Foo) which will be inaccessible after move Variable t uses object Test which will be inaccessible after move \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackageWithConflicts/conflicts.txt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackageWithConflicts/conflicts.txt index 872be973a55..e38a822bd2f 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackageWithConflicts/conflicts.txt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePropertyToPackageWithConflicts/conflicts.txt @@ -1,4 +1,4 @@ Function bar() uses property test which will be inaccessible after move Method bar() uses property test which will be inaccessible after move Property test uses class Foo which will be inaccessible after move -Property test uses function foo() which will be inaccessible after move \ No newline at end of file +Property test uses function foo(Foo) which will be inaccessible after move \ No newline at end of file diff --git a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/fun2.kt.messages b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/fun2.kt.messages index 9294f312f7c..c53d8252ee4 100644 --- a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/fun2.kt.messages +++ b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/fun2.kt.messages @@ -1 +1 @@ -function test.foo has 1 usage that is not safe to delete. \ No newline at end of file +function test.foo() has 1 usage that is not safe to delete. \ No newline at end of file diff --git a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/funExt2.kt.messages b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/funExt2.kt.messages index 9294f312f7c..a2217e2c7fc 100644 --- a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/funExt2.kt.messages +++ b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/funExt2.kt.messages @@ -1 +1 @@ -function test.foo has 1 usage that is not safe to delete. \ No newline at end of file +function test.foo() on B has 1 usage that is not safe to delete. \ No newline at end of file diff --git a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/localFun1.kt.messages b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/localFun1.kt.messages index 32eb1cb56fe..f0b12749725 100644 --- a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/localFun1.kt.messages +++ b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/localFun1.kt.messages @@ -1 +1 @@ -function foo.bar has 1 usage that is not safe to delete. \ No newline at end of file +function foo.bar() has 1 usage that is not safe to delete. \ No newline at end of file diff --git a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/localFunExt1.kt.messages b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/localFunExt1.kt.messages index 32eb1cb56fe..b25df9825e1 100644 --- a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/localFunExt1.kt.messages +++ b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunction/localFunExt1.kt.messages @@ -1 +1 @@ -function foo.bar has 1 usage that is not safe to delete. \ No newline at end of file +function foo.bar() on String has 1 usage that is not safe to delete. \ No newline at end of file diff --git a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunctionWithJava/funExt.kt.messages b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunctionWithJava/funExt.kt.messages index 9294f312f7c..f8eddec61fd 100644 --- a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunctionWithJava/funExt.kt.messages +++ b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunctionWithJava/funExt.kt.messages @@ -1 +1 @@ -function test.foo has 1 usage that is not safe to delete. \ No newline at end of file +function test.foo() on String has 1 usage that is not safe to delete. \ No newline at end of file diff --git a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunctionWithJava/secondaryConstructor.kt.messages b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunctionWithJava/secondaryConstructor.kt.messages index 962630650b4..d2ad14d089e 100644 --- a/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunctionWithJava/secondaryConstructor.kt.messages +++ b/idea/testData/refactoring/safeDelete/deleteFunction/kotlinFunctionWithJava/secondaryConstructor.kt.messages @@ -1 +1 @@ -constructor B has 5 usages that are not safe to delete. \ No newline at end of file +constructor B(Int) has 5 usages that are not safe to delete. \ No newline at end of file