summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt6
-rw-r--r--integration-tests/KotlinTestApp/app/src/androidTest/java/androidx/databinding/kotlintestapp/GenericInterfaceTest.kt49
-rw-r--r--integration-tests/KotlinTestApp/app/src/main/java/androidx/databinding/kotlintestapp/GenericInterface.kt56
-rw-r--r--integration-tests/KotlinTestApp/app/src/main/res/layout/generic_interface.xml45
-rw-r--r--integration-tests/ideCommonBuildScript.gradle2
5 files changed, 154 insertions, 4 deletions
diff --git a/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt b/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt
index 69853d91..3b8fa997 100644
--- a/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt
+++ b/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt
@@ -956,17 +956,17 @@ class LayoutBinderWriter(val layoutBinder : LayoutBinder, val libTypes: LibTypes
block("protected void executeBindings()") {
val tmpDirtyFlags = FlagSet(mDirtyFlags.buckets)
tmpDirtyFlags.localName = "dirtyFlags";
- for (i in (0..mDirtyFlags.buckets.size - 1)) {
+ for (i in (0 until mDirtyFlags.buckets.size)) {
nl("${tmpDirtyFlags.type} ${tmpDirtyFlags.localValue(i)} = 0;")
}
block("synchronized(this)") {
- for (i in (0..mDirtyFlags.buckets.size - 1)) {
+ for (i in (0 until mDirtyFlags.buckets.size)) {
nl("${tmpDirtyFlags.localValue(i)} = ${mDirtyFlags.localValue(i)};")
nl("${mDirtyFlags.localValue(i)} = 0;")
}
}
model.pendingExpressions.filter { it.needsLocalField }.forEach {
- nl("${it.resolvedType.toJavaCode()} ${it.executePendingLocalName} = ${if (it.isVariable()) it.fieldName else it.defaultValue};")
+ nl("${it.resolvedType.typeName} ${it.executePendingLocalName} = ${if (it.isVariable()) it.fieldName else it.defaultValue};")
}
L.d("writing executePendingBindings for %s", className)
do {
diff --git a/integration-tests/KotlinTestApp/app/src/androidTest/java/androidx/databinding/kotlintestapp/GenericInterfaceTest.kt b/integration-tests/KotlinTestApp/app/src/androidTest/java/androidx/databinding/kotlintestapp/GenericInterfaceTest.kt
new file mode 100644
index 00000000..1d310852
--- /dev/null
+++ b/integration-tests/KotlinTestApp/app/src/androidTest/java/androidx/databinding/kotlintestapp/GenericInterfaceTest.kt
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package androidx.databinding.kotlintestapp
+
+import androidx.databinding.kotlintestapp.databinding.GenericInterfaceBinding
+import androidx.test.espresso.Espresso.onView
+import androidx.test.espresso.assertion.ViewAssertions.matches
+import androidx.test.espresso.matcher.ViewMatchers.withId
+import androidx.test.espresso.matcher.ViewMatchers.withText
+import androidx.test.runner.AndroidJUnit4
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class GenericInterfaceTest {
+ @Suppress("MemberVisibilityCanPrivate")
+ @Rule
+ @JvmField
+ val rule = BindingActivityRule<GenericInterfaceBinding>(R.layout.generic_interface)
+
+ @Test
+ fun test() {
+ rule.runOnUiThread {
+ rule.binding.model = GenericModel().apply {
+ observable.set(listOf(GenericImpl("a"), GenericImpl("b")))
+ liveData.value = listOf(GenericImpl("c"), GenericImpl("d"))
+ }
+ rule.executePendingBindings()
+ }
+ onView(withId(R.id.textObservable))
+ .check(matches(withText("a,b")))
+ onView(withId(R.id.textLiveData))
+ .check(matches(withText("c-d")))
+ }
+} \ No newline at end of file
diff --git a/integration-tests/KotlinTestApp/app/src/main/java/androidx/databinding/kotlintestapp/GenericInterface.kt b/integration-tests/KotlinTestApp/app/src/main/java/androidx/databinding/kotlintestapp/GenericInterface.kt
new file mode 100644
index 00000000..78041b35
--- /dev/null
+++ b/integration-tests/KotlinTestApp/app/src/main/java/androidx/databinding/kotlintestapp/GenericInterface.kt
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package androidx.databinding.kotlintestapp
+
+import android.widget.TextView
+import androidx.databinding.BindingAdapter
+import androidx.databinding.ObservableField
+import androidx.lifecycle.MutableLiveData
+
+// helpers for GenericInterfaceTest
+
+// a sample generic interface accessed from layout
+interface Generic<T> {
+ fun getValue() : T
+}
+
+// implementation of it
+class GenericImpl(val data : String) : Generic<String> {
+ override fun getValue() = data
+
+}
+
+// model with nested generic data
+class GenericModel {
+ val observable = ObservableField<List<Generic<*>>>()
+ val liveData = MutableLiveData<List<Generic<*>>>()
+}
+
+
+// binding adapter to test results
+@BindingAdapter("genericList")
+fun TextView.genericList(items : List<Generic<*>>?) {
+ text = items?.joinToString(",") {
+ it.getValue().toString()
+ }
+}
+
+@BindingAdapter("genericList2")
+fun TextView.genericList2(items : List<Generic<*>>?) {
+ text = items?.joinToString("-") {
+ it.getValue().toString()
+ }
+} \ No newline at end of file
diff --git a/integration-tests/KotlinTestApp/app/src/main/res/layout/generic_interface.xml b/integration-tests/KotlinTestApp/app/src/main/res/layout/generic_interface.xml
new file mode 100644
index 00000000..18b73506
--- /dev/null
+++ b/integration-tests/KotlinTestApp/app/src/main/res/layout/generic_interface.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ Copyright (C) 2019 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+
+ <data>
+
+ <variable
+ name="model"
+ type="androidx.databinding.kotlintestapp.GenericModel" />
+ </data>
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <TextView
+ android:id="@+id/textObservable"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ app:genericList="@{model.observable}" />
+
+ <TextView
+ android:id="@+id/textLiveData"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ app:genericList2="@{model.liveData}" />
+ </LinearLayout>
+</layout> \ No newline at end of file
diff --git a/integration-tests/ideCommonBuildScript.gradle b/integration-tests/ideCommonBuildScript.gradle
index e4129487..72cb6fe2 100644
--- a/integration-tests/ideCommonBuildScript.gradle
+++ b/integration-tests/ideCommonBuildScript.gradle
@@ -3,7 +3,7 @@ rootProject.buildscript {
apply from: "${rootProject.ext.checkoutDir}/tools/buildSrc/base/version.gradle"
rootProject.ext.latestCompileSdk = 28
rootProject.ext.buildToolsVersion = "28.0.2"
- rootProject.ext.kotlinVersion = '1.2.71'
+ rootProject.ext.kotlinVersion = '1.3.10'
repositories {
maven { url "file://${rootProject.ext.checkoutDir}/out/repo/" }