Create from Usage: Do not add bodies to expect class members
#KT-21122 Fixed
This commit is contained in:
+6
-1
@@ -463,6 +463,10 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
else if (isExtension) "private "
|
else if (isExtension) "private "
|
||||||
else ""
|
else ""
|
||||||
|
|
||||||
|
val isExpectClassMember by lazy {
|
||||||
|
containingElement is KtClassOrObject && (containingElement.resolveToDescriptorIfAny() as? ClassDescriptor)?.isExpect ?: false
|
||||||
|
}
|
||||||
|
|
||||||
val declaration: KtNamedDeclaration = when (callableInfo.kind) {
|
val declaration: KtNamedDeclaration = when (callableInfo.kind) {
|
||||||
CallableKind.FUNCTION, CallableKind.SECONDARY_CONSTRUCTOR -> {
|
CallableKind.FUNCTION, CallableKind.SECONDARY_CONSTRUCTOR -> {
|
||||||
val body = when {
|
val body = when {
|
||||||
@@ -473,6 +477,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
containingElement is KtObjectDeclaration && containingElement.isCompanion()
|
containingElement is KtObjectDeclaration && containingElement.isCompanion()
|
||||||
&& containingElement.parent.parent is KtClass
|
&& containingElement.parent.parent is KtClass
|
||||||
&& (containingElement.parent.parent as KtClass).hasModifier(KtTokens.EXTERNAL_KEYWORD) -> ""
|
&& (containingElement.parent.parent as KtClass).hasModifier(KtTokens.EXTERNAL_KEYWORD) -> ""
|
||||||
|
isExpectClassMember -> ""
|
||||||
else -> "{}"
|
else -> "{}"
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -517,7 +522,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
CallableKind.PROPERTY -> {
|
CallableKind.PROPERTY -> {
|
||||||
val isVar = (callableInfo as PropertyInfo).writable
|
val isVar = (callableInfo as PropertyInfo).writable
|
||||||
val valVar = if (isVar) "var" else "val"
|
val valVar = if (isVar) "var" else "val"
|
||||||
val accessors = if (isExtension) {
|
val accessors = if (isExtension && !isExpectClassMember) {
|
||||||
buildString {
|
buildString {
|
||||||
append("\nget() {}")
|
append("\nget() {}")
|
||||||
if (isVar) {
|
if (isVar) {
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create member function 'Foo.foo'" "true"
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
expect class Foo
|
||||||
|
|
||||||
|
fun test(f: Foo) {
|
||||||
|
f.<caret>foo("a", 1)
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// "Create member function 'Foo.foo'" "true"
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
expect class Foo {
|
||||||
|
fun foo(s: String, i: Int)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(f: Foo) {
|
||||||
|
f.foo("a", 1)
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
actual class Foo
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
actual class Foo
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// "Create member property 'Foo.foo'" "true"
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
expect class Foo
|
||||||
|
|
||||||
|
fun test(f: Foo) {
|
||||||
|
takeInt(f.<caret>foo)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun takeInt(n: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
// "Create member property 'Foo.foo'" "true"
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
expect class Foo {
|
||||||
|
val foo: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(f: Foo) {
|
||||||
|
takeInt(f.foo)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun takeInt(n: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
actual class Foo
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
actual class Foo
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create member property 'Foo.foo'" "true"
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
expect class Foo
|
||||||
|
|
||||||
|
fun test(f: Foo) {
|
||||||
|
f.<caret>foo = 1
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// "Create member property 'Foo.foo'" "true"
|
||||||
|
// ERROR: Unresolved reference: foo
|
||||||
|
|
||||||
|
expect class Foo {
|
||||||
|
var foo: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(f: Foo) {
|
||||||
|
f.foo = 1
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
actual class Foo
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
actual class Foo
|
||||||
@@ -249,4 +249,13 @@ class QuickFixMultiModuleTest : AbstractQuickFixMultiModuleTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAddActualToTopLevelMember() = doMultiPlatformTest()
|
fun testAddActualToTopLevelMember() = doMultiPlatformTest()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testCreateFunInExpectClass() = doMultiPlatformTest()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testCreateValInExpectClass() = doMultiPlatformTest()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testCreateVarInExpectClass() = doMultiPlatformTest()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user