Created
February 19, 2016 09:46
-
-
Save fboldog/2990135ff21669d6e7dc to your computer and use it in GitHub Desktop.
Required changes in Android Data Binding for Kotlin 1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/compiler/src/main/kotlin/android/databinding/tool/ext/list_ext.kt b/compiler/src/main/kotlin/android/databinding/tool/ext/list_ext.kt | |
index 3d23e13..70317f6 100644 | |
--- a/compiler/src/main/kotlin/android/databinding/tool/ext/list_ext.kt | |
+++ b/compiler/src/main/kotlin/android/databinding/tool/ext/list_ext.kt | |
@@ -31,13 +31,13 @@ public fun List<String>.joinToCamelCaseAsVar(): String = when(size) { | |
else -> get(0).toCamelCaseAsVar() + drop(1).joinToCamelCase() | |
} | |
-public fun Array<String>.joinToCamelCase(): String = when(size()) { | |
+public fun Array<String>.joinToCamelCase(): String = when(size) { | |
0 -> throw IllegalArgumentException("invalid section size, cannot be zero") | |
1 -> this.get(0).toCamelCase() | |
else -> this.map {it.toCamelCase()}.joinToString("") | |
} | |
-public fun Array<String>.joinToCamelCaseAsVar(): String = when(size()) { | |
+public fun Array<String>.joinToCamelCaseAsVar(): String = when(size) { | |
0 -> throw IllegalArgumentException("invalid section size, cannot be zero") | |
1 -> this.get(0).toCamelCaseAsVar() | |
else -> get(0).toCamelCaseAsVar() + drop(1).joinToCamelCase() | |
diff --git a/compiler/src/main/kotlin/android/databinding/tool/writer/KCode.kt b/compiler/src/main/kotlin/android/databinding/tool/writer/KCode.kt | |
index fe961b4..4fc4ec1 100644 | |
--- a/compiler/src/main/kotlin/android/databinding/tool/writer/KCode.kt | |
+++ b/compiler/src/main/kotlin/android/databinding/tool/writer/KCode.kt | |
@@ -55,7 +55,7 @@ class KCode (private val s : String? = null){ | |
return this | |
} | |
- infix fun tab(s : String?, init : (KCode.() -> Unit)? = null) : KCode { | |
+ fun tab(s : String?, init : (KCode.() -> Unit)? = null) : KCode { | |
val c = KCode(s) | |
if (init != null) { | |
c.init() | |
@@ -63,6 +63,8 @@ class KCode (private val s : String? = null){ | |
return tab(c) | |
} | |
+ infix fun tab(s: String): KCode = tab(s, null) | |
+ | |
private fun tab(c : KCode?) : KCode { | |
if (c == null || isNull(c)) { | |
return this | |
@@ -86,7 +88,7 @@ class KCode (private val s : String? = null){ | |
return this | |
} | |
nodes.add(c) | |
- c!!.sameLine = true | |
+ c.sameLine = true | |
return this | |
} | |
@@ -98,6 +100,8 @@ class KCode (private val s : String? = null){ | |
return nl(c) | |
} | |
+ infix fun nl(s: String): KCode = nl(s, null) | |
+ | |
fun apps(glue : String = "", vararg codes : KCode?) : KCode { | |
codes.forEach { app(glue, it)} | |
return this | |
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 7874d40..dca7417 100644 | |
--- a/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt | |
+++ b/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt | |
@@ -48,7 +48,7 @@ enum class Scope { | |
class ExprModelExt { | |
val usedFieldNames = hashMapOf<Scope, MutableSet<String>>(); | |
init { | |
- Scope.values.forEach { usedFieldNames[it] = hashSetOf<String>() } | |
+ Scope.values().forEach { usedFieldNames[it] = hashSetOf<String>() } | |
} | |
val localizedFlags = arrayListOf<FlagSet>() | |
@@ -669,7 +669,7 @@ class LayoutBinderWriter(val layoutBinder : LayoutBinder) { | |
layoutBinder.sortedTargets.filter { it.isUsed } | |
.flatMap { it.bindings } | |
.filter { it.requiresOldValue() } | |
- .flatMap{ it.componentExpressions.toArrayList() } | |
+ .flatMap{ it.componentExpressions.toList() } | |
.groupBy { it } | |
.forEach { | |
val expr = it.key | |
@@ -725,7 +725,7 @@ class LayoutBinderWriter(val layoutBinder : LayoutBinder) { | |
} | |
L.d("writing executePendingBindings for %s", className) | |
do { | |
- val batch = ExprModel.filterShouldRead(model.pendingExpressions).toArrayList() | |
+ val batch = ExprModel.filterShouldRead(model.pendingExpressions).toMutableList() | |
val justRead = arrayListOf<Expr>() | |
L.d("batch: %s", batch) | |
while (!batch.none()) { | |
@@ -740,7 +740,7 @@ class LayoutBinderWriter(val layoutBinder : LayoutBinder) { | |
tab("// batch finished") | |
} while (model.markBitsRead()) | |
// verify everything is read. | |
- val batch = ExprModel.filterShouldRead(model.pendingExpressions).toArrayList() | |
+ val batch = ExprModel.filterShouldRead(model.pendingExpressions).toMutableList() | |
if (batch.isNotEmpty()) { | |
L.e("could not generate code for %s. This might be caused by circular dependencies." | |
+ "Please report on b.android.com. %d %s %s", layoutBinder.layoutname, | |
@@ -984,7 +984,7 @@ class LayoutBinderWriter(val layoutBinder : LayoutBinder) { | |
} | |
val listenerMethod = expr.method | |
val parameterTypes = listenerMethod.parameterTypes | |
- val returnType = listenerMethod.getReturnType(parameterTypes.toArrayList()) | |
+ val returnType = listenerMethod.getReturnType(parameterTypes.toList()) | |
tab("@Override") | |
tab("public $returnType ${listenerMethod.name}(${ | |
parameterTypes.withIndex().map { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment