Change parsing of annotations on block level expressions

Attach annotations to the closest prefix expression instead of
whole statement if no new line found after annotations

The motivation is for a simple annotated expression like '@ann x + y'
its syntax form must not change after prepending 'val z = ' just before it
This commit is contained in:
Denis Zharkov
2016-10-06 16:22:12 +03:00
parent 9ff439e39e
commit bec84b1d7b
13 changed files with 745 additions and 91 deletions
@@ -2,6 +2,8 @@ fun <T : CharSequence> foo(x: Array<Any>, y: IntArray, block: (T, Int) -> Int) {
var r: Any?
@Suppress("UNCHECKED_CAST")
// comment
/* comment */
r = block(x[0] as T, "" <!CAST_NEVER_SUCCEEDS!>as<!> Int)
// to prevent unused assignment diagnostic for the above statement
@@ -50,6 +52,9 @@ fun <T : CharSequence> foo(x: Array<Any>, y: IntArray, block: (T, Int) -> Int) {
}
l()
// many empty new lines
@Suppress("UNCHECKED_CAST")
y[i] += block(x[0] as T, "" <!CAST_NEVER_SUCCEEDS!>as<!> Int).toInt()
}
@@ -0,0 +1,19 @@
fun <T : CharSequence> foo(x: Array<Any>, block: (T, Int) -> Int) {
var r: Any?
@Suppress("UNCHECKED_CAST") r = block(<!UNCHECKED_CAST!>x[0] as T<!>, "" <!CAST_NEVER_SUCCEEDS!>as<!> Int)
// to prevent unused assignment diagnostic for the above statement
<!DEBUG_INFO_SMARTCAST!>r<!>.hashCode()
var i = 1
if (i != 1) {
@Suppress("UNCHECKED_CAST") i += block(<!UNCHECKED_CAST!>x[0] as T<!>, "" <!CAST_NEVER_SUCCEEDS!>as<!> Int).toInt()
}
if (i != 1) @Suppress("UNCHECKED_CAST")
i += block(x[0] as T, "" <!CAST_NEVER_SUCCEEDS!>as<!> Int).toInt()
if (i != 1) @Suppress("UNCHECKED_CAST") i += block(<!UNCHECKED_CAST!>x[0] as T<!>, "" <!CAST_NEVER_SUCCEEDS!>as<!> Int).toInt()
}
@@ -0,0 +1,3 @@
package
public fun </*0*/ T : kotlin.CharSequence> foo(/*0*/ x: kotlin.Array<kotlin.Any>, /*1*/ block: (T, kotlin.Int) -> kotlin.Int): kotlin.Unit