Implement quickfix for wrong primitive literal (#885)

* Implement quickfix for wrong primitive literal
Fixes: KT-12251

* fix style issue
This commit is contained in:
Kirill Rakhman
2016-07-05 13:34:14 +02:00
committed by Dmitry Jemerov
parent 3b290ce3dd
commit b50176fa2e
27 changed files with 271 additions and 8 deletions
@@ -1,6 +1,6 @@
// "Convert expression to 'Int'" "true"
fun foo() {
bar(1L<caret>)
bar("1".toLong()<caret>)
}
fun bar(l: Int) {
@@ -1,6 +1,6 @@
// "Convert expression to 'Int'" "true"
fun foo() {
bar(1L.toInt()<caret>)
bar("1".toLong().toInt()<caret>)
}
fun bar(l: Int) {
@@ -0,0 +1,8 @@
// "Change to '1'" "false"
// ACTION: Add 'const' modifier
// ACTION: Change 'a' type to 'Double'
// ACTION: Convert expression to 'Int'
// ACTION: Convert property initializer to getter
// ERROR: The floating-point literal does not conform to the expected type Int
val a : Int = 1.12<caret>
@@ -0,0 +1,8 @@
// "Change to '10000000000000000000L'" "false"
// ACTION: Add 'const' modifier
// ACTION: Change 'a' type to 'Double'
// ACTION: Convert expression to 'Long'
// ACTION: Convert property initializer to getter
// ERROR: The floating-point literal does not conform to the expected type Long
val a : Long = 10000000000000000000.0<caret>
@@ -0,0 +1,8 @@
// "Change to '65000'" "false"
// ACTION: Add 'const' modifier
// ACTION: Change 'a' type to 'Double'
// ACTION: Convert expression to 'Short'
// ACTION: Convert property initializer to getter
// ERROR: The floating-point literal does not conform to the expected type Short
val a : Short = 65000.0<caret>
@@ -0,0 +1,2 @@
// "Change to '1.2'" "true"
val a : Double = 1.2F<caret>
@@ -0,0 +1,2 @@
// "Change to '1.2'" "true"
val a : Double = 1.2<caret>
@@ -0,0 +1,7 @@
// "Change to '1'" "true"
// ACTION: Add 'const' modifier
// ACTION: Change 'a' type to 'Double'
// ACTION: Convert expression to 'Int'
// ACTION: Convert property initializer to getter
val a : Int = 1.0F<caret>
@@ -0,0 +1,7 @@
// "Change to '1'" "true"
// ACTION: Add 'const' modifier
// ACTION: Change 'a' type to 'Double'
// ACTION: Convert expression to 'Int'
// ACTION: Convert property initializer to getter
val a : Int = 1<caret>
@@ -0,0 +1,2 @@
// "Change to '1'" "true"
val a : Int = 1F<caret>
@@ -0,0 +1,2 @@
// "Change to '1'" "true"
val a : Int = 1<caret>
@@ -0,0 +1,3 @@
// "Change to '1L'" "true"
val a = foo(1.0<caret>)
fun foo(l: Long) = l
@@ -0,0 +1,3 @@
// "Change to '1L'" "true"
val a = foo(1L<caret>)
fun foo(l: Long) = l
@@ -0,0 +1,3 @@
// "Change to '15F'" "true"
val a : Float = 0xF<caret>
@@ -0,0 +1,3 @@
// "Change to '15F'" "true"
val a : Float = 15F<caret>
@@ -0,0 +1,2 @@
// "Change to '1F'" "true"
val a : Float = 1<caret>
@@ -0,0 +1,2 @@
// "Change to '1F'" "true"
val a : Float = 1F<caret>
@@ -0,0 +1,2 @@
// "Change to '1.0'" "true"
val a : Double = 1L<caret>
@@ -0,0 +1,2 @@
// "Change to '1.0'" "true"
val a : Double = 1.0<caret>
@@ -0,0 +1,2 @@
// "Change to '1'" "true"
val a : Int = 1L<caret>
@@ -0,0 +1,2 @@
// "Change to '1'" "true"
val a : Int = 1<caret>
@@ -0,0 +1,2 @@
// "Change to '0b10'" "true"
val a : Int = 0b10L<caret>
@@ -0,0 +1,2 @@
// "Change to '0b10'" "true"
val a : Int = 0b10<caret>