Insert proper default value when overriding property of type float, double, char

This commit is contained in:
Natalia Ukhorskaya
2014-01-17 16:38:16 +04:00
parent 84c76507f0
commit a71e062504
5 changed files with 52 additions and 7 deletions
@@ -146,11 +146,18 @@ public class CodeInsightUtils {
return "null"; return "null";
} }
else if (type.equals(builtIns.getIntType()) || type.equals(builtIns.getLongType()) || else if (type.equals(builtIns.getIntType()) || type.equals(builtIns.getLongType()) ||
type.equals(builtIns.getShortType()) || type.equals(builtIns.getByteType()) || type.equals(builtIns.getShortType()) || type.equals(builtIns.getByteType())) {
type.equals(builtIns.getFloatType()) || type.equals(builtIns.getDoubleType()) ||
type.equals(builtIns.getCharType())) {
return "0"; return "0";
} }
else if (type.equals(builtIns.getFloatType())) {
return "0.0f";
}
else if (type.equals(builtIns.getDoubleType())) {
return "0.0";
}
else if (type.equals(builtIns.getCharType())) {
return "'\\u0000'";
}
else if (type.equals(builtIns.getBooleanType())) { else if (type.equals(builtIns.getBooleanType())) {
return "false"; return "false";
} }
@@ -0,0 +1,13 @@
trait T {
val a1: Byte
val a2: Short
val a3: Int
val a4: Long
val a5: Float
val a6: Double
val a7: Char
val a8: Boolean
}
class C : T {<caret>
}
@@ -0,0 +1,21 @@
trait T {
val a1: Byte
val a2: Short
val a3: Int
val a4: Long
val a5: Float
val a6: Double
val a7: Char
val a8: Boolean
}
class C : T {
override val a1: Byte = 0
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
}
@@ -1,12 +1,12 @@
fun foo() { fun foo() {
var a: Int = 0 var a: Int = 0
var b: Char = 0 var b: Char = '\u0000'
var c: Byte = 0 var c: Byte = 0
var d: Long = 0 var d: Long = 0
var e: Short = 0 var e: Short = 0
var f: Double = 0 var f: Double = 0.0
var g: Float = 0 var g: Float = 0.0f
if (<caret>) { if () {
a = 1 a = 1
b = 1 b = 1
c = 1 c = 1
@@ -94,6 +94,10 @@ public final class OverrideImplementTest extends AbstractOverrideImplementTest {
doOverrideFileTest(); doOverrideFileTest();
} }
public void testOverridePrimitiveProperty() {
doMultiImplementFileTest();
}
public void testOverrideGenericFunction() { public void testOverrideGenericFunction() {
doOverrideFileTest(); doOverrideFileTest();
} }