From c40598b3e986f7294db496c24093b311ab846197 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 20 Mar 2015 19:44:41 +0300 Subject: [PATCH] Do not cast findViewById to View --- .../lang/resolve/android/AndroidUIXmlProcessor.kt | 3 ++- .../android/converter/simple/specialTags/layout.kt | 12 ++++++------ .../android/converter/simple/specialTags/layout1.kt | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidUIXmlProcessor.kt b/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidUIXmlProcessor.kt index 02d8504c71d..511a74b6a03 100644 --- a/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidUIXmlProcessor.kt +++ b/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidUIXmlProcessor.kt @@ -135,7 +135,8 @@ public abstract class AndroidUIXmlProcessor(protected val project: Project) { } private fun KotlinStringWriter.writeSyntheticProperty(receiver: String, widget: AndroidWidget, stubCall: String) { - val body = arrayListOf("return $stubCall as ${widget.className}") + val cast = if (widget.className == "View") ":" else "as" + val body = arrayListOf("return $stubCall $cast ${widget.className}") val type = widget.className writeImmutableExtensionProperty(receiver, name = widget.id, diff --git a/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout.kt b/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout.kt index 50662a47f3c..0d8202b99df 100644 --- a/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout.kt +++ b/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout.kt @@ -7,20 +7,20 @@ import android.widget.* import kotlin.internal.flexible.ft val Activity.includeTag: ft - get() = findViewById(0) as View + get() = findViewById(0) : View val Fragment.includeTag: ft - get() = getView().findViewById(0) as View + get() = getView().findViewById(0) : View val Activity.mergeTag: ft - get() = findViewById(0) as View + get() = findViewById(0) : View val Fragment.mergeTag: ft - get() = getView().findViewById(0) as View + get() = getView().findViewById(0) : View val Activity.fragmentTag: ft - get() = findViewById(0) as View + get() = findViewById(0) : View val Fragment.fragmentTag: ft - get() = getView().findViewById(0) as View + get() = getView().findViewById(0) : View diff --git a/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout1.kt b/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout1.kt index d58b635d302..bfa76cfeabb 100644 --- a/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout1.kt +++ b/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout1.kt @@ -7,11 +7,11 @@ import android.widget.* import kotlin.internal.flexible.ft val View.includeTag: ft - get() = findViewById(0) as View + get() = findViewById(0) : View val View.mergeTag: ft - get() = findViewById(0) as View + get() = findViewById(0) : View val View.fragmentTag: ft - get() = findViewById(0) as View + get() = findViewById(0) : View