Convert Parameter to Receiver: Do not qualify companion members with labeled 'this'

#KT-13933 Fixed
This commit is contained in:
Alexey Sedunov
2016-09-19 19:34:01 +03:00
parent 75481c34b4
commit 79f50975b1
5 changed files with 53 additions and 1 deletions
+1
View File
@@ -116,6 +116,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
- [`KT-13883`](https://youtrack.jetbrains.com/issue/KT-13883) Move to Companion Object: Fix exception when applied to class
- [`KT-13876`](https://youtrack.jetbrains.com/issue/KT-13876) Move to Companion Object: Forbid for functions/properties referencing type parameters of the containing class
- [`KT-13877`](https://youtrack.jetbrains.com/issue/KT-13877) Move to Companion Object: Warn if companion object already contains function with the same signature
- [`KT-13933`](https://youtrack.jetbrains.com/issue/KT-13933) Convert Parameter to Receiver: Do not qualify companion members with labeled 'this'
##### New features
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.idea.refactoring.changeSignature.usages
import com.intellij.usageView.UsageInfo
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinChangeInfo
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinParameterInfo
import org.jetbrains.kotlin.psi.KtPsiFactory
@@ -25,6 +26,8 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.idea.codeInsight.shorten.addToShorteningWaitSet
import org.jetbrains.kotlin.idea.core.ShortenReferences.Options
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.resolve.DescriptorUtils
abstract class KotlinImplicitReceiverUsage(callElement: KtElement): KotlinUsageInfo<KtElement>(callElement) {
protected abstract fun getNewReceiverText(): String
@@ -60,7 +63,11 @@ class KotlinImplicitThisUsage(
): KotlinImplicitReceiverUsage(callElement) {
override fun getNewReceiverText(): String {
val name = targetDescriptor.name
return if (name.isSpecial) "this" else "this@${name.asString()}"
return when {
name.isSpecial -> "this"
DescriptorUtils.isCompanionObject(targetDescriptor) -> IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(targetDescriptor as ClassifierDescriptor)
else -> "this@${name.asString()}"
}
}
override fun processReplacedElement(element: KtElement) {
@@ -0,0 +1,19 @@
interface Application {
fun put(testKey: String, s: String)
}
abstract class ApplicationModule {
abstract fun install(<caret>application: Application)
}
class AppTest {
class ApplicationLoaderTestApplicationFeatureWithEnvironment() : ApplicationModule() {
override fun install(application: Application) {
application.put(TestKey, "2")
}
}
companion object {
val TestKey = ""
}
}
@@ -0,0 +1,19 @@
interface Application {
fun put(testKey: String, s: String)
}
abstract class ApplicationModule {
abstract fun Application.install()
}
class AppTest {
class ApplicationLoaderTestApplicationFeatureWithEnvironment() : ApplicationModule() {
override fun Application.install() {
put(TestKey, "2")
}
}
companion object {
val TestKey = ""
}
}
@@ -4285,6 +4285,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("companionAsReceiver.kt")
public void testCompanionAsReceiver() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertParameterToReceiver/companionAsReceiver.kt");
doTest(fileName);
}
@TestMetadata("functionExpression.kt")
public void testFunctionExpression() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertParameterToReceiver/functionExpression.kt");