Fixed KT-4431 Override/implement val: generate getter instead of initializer

#KT-4431 Fixed
This commit is contained in:
Valentin Kipyatkov
2014-12-05 07:02:30 +03:00
parent eae4cdbd8f
commit 4b9bcce07a
9 changed files with 44 additions and 26 deletions
@@ -206,15 +206,10 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
StringBuilder body = new StringBuilder();
String defaultInitializer = CodeInsightUtils.defaultInitializer(descriptor.getType());
String initializer = defaultInitializer != null ? " = " + defaultInitializer : " = ?";
if (descriptor.getExtensionReceiverParameter() != null) {
body.append("\nget()");
body.append(initializer);
if (descriptor.isVar()) {
body.append("\nset(value) {}");
}
}
else {
body.append(initializer);
body.append("\nget()");
body.append(initializer);
if (descriptor.isVar()) {
body.append("\nset(value) {}");
}
return JetPsiFactory(project).createProperty(OVERRIDE_RENDERER.render(newDescriptor) + body);
}
@@ -21,7 +21,9 @@ class C : Base<String, C, Unit>() {
return super<Base>.hashCode()
}
override val method: (String?) -> String = ?
override val method: (String?) -> String
get() = ?
override fun toString(): String {
return super<Base>.toString()
}
@@ -5,7 +5,8 @@ trait A {
fun some() : A {
return object : A {<caret>
override val method: () -> Unit? = ?
override val method: () -> Unit?
get() = ?
}
}
@@ -23,17 +23,23 @@ class C : A(), B {
super<A>.internalFun()
}
override val internalProperty: Int = 0
override val internalProperty: Int
get() = 0
override fun protectedFun() {
super<A>.protectedFun()
}
override val protectedProperty: Int = 0
override val protectedProperty: Int
get() = 0
override fun publicFun() {
super<A>.publicFun()
}
override val publicProperty: Int = 0
override val publicProperty: Int
get() = 0
override fun toString(): String {
return super<A>.toString()
}
@@ -4,7 +4,8 @@ open class A() {
fun some() : A {
return object : A() {<caret>
override val method: () -> Unit? = ?
override val method: () -> Unit?
get() = ?
}
}
@@ -10,12 +10,20 @@ trait T {
}
class C : T {
override val a1: Byte = <selection><caret>0</selection>
override val a2: Short = 0
override val a3: Int = 0
override val a4: Long = 0
override val a5: Float = 0.0f
override val a6: Double = 0.0
override val a7: Char = '\u0000'
override val a8: Boolean = false
override val a1: Byte
get() = <selection><caret>0</selection>
override val a2: Short
get() = 0
override val a3: Int
get() = 0
override val a4: Long
get() = 0
override val a5: Float
get() = 0.0f
override val a6: Double
get() = 0.0
override val a7: Char
get() = '\u0000'
override val a8: Boolean
get() = false
}
@@ -6,7 +6,9 @@ open class A() {
class C : A() {
val constant = 42
// Some comment
override val bar: Int = <selection><caret>0</selection>
override val bar: Int
get() = <selection><caret>0</selection>
override fun equals(other: Any?): Boolean {
return super<A>.equals(other)
}
@@ -3,5 +3,6 @@ trait T {
}
class GC() : T {
override val v: Int = <selection><caret>0</selection>
override val v: Int
get() = <selection><caret>0</selection>
}
@@ -9,7 +9,9 @@ class SomeTest : Test {
<selection><caret>throw UnsupportedOperationException()</selection>
}
override val testProp: Int = 0
override val testProp: Int
get() = 0
/**
* test
*/