Android synthetic properties are now properties with flexible type
This commit is contained in:
+13
-5
@@ -52,6 +52,7 @@ import com.intellij.openapi.vfs.impl.*
|
|||||||
import com.intellij.openapi.vfs.*
|
import com.intellij.openapi.vfs.*
|
||||||
import kotlin.properties.*
|
import kotlin.properties.*
|
||||||
import com.intellij.psi.impl.*
|
import com.intellij.psi.impl.*
|
||||||
|
import org.jetbrains.kotlin.types.Flexibility
|
||||||
|
|
||||||
public abstract class AndroidUIXmlProcessor(protected val project: Project) {
|
public abstract class AndroidUIXmlProcessor(protected val project: Project) {
|
||||||
|
|
||||||
@@ -91,7 +92,7 @@ public abstract class AndroidUIXmlProcessor(protected val project: Project) {
|
|||||||
val commonFiles = if (generateCommonFiles) {
|
val commonFiles = if (generateCommonFiles) {
|
||||||
val clearCacheFile = renderLayoutFile("kotlinx.android.synthetic") {} +
|
val clearCacheFile = renderLayoutFile("kotlinx.android.synthetic") {} +
|
||||||
renderClearCacheFunction("Activity") + renderClearCacheFunction("Fragment")
|
renderClearCacheFunction("Activity") + renderClearCacheFunction("Fragment")
|
||||||
listOf(clearCacheFile)
|
listOf(clearCacheFile, FLEXIBLE_TYPE_FILE)
|
||||||
} else listOf()
|
} else listOf()
|
||||||
|
|
||||||
return resourceManager.getLayoutXmlFiles().flatMap { file ->
|
return resourceManager.getLayoutXmlFiles().flatMap { file ->
|
||||||
@@ -131,7 +132,7 @@ public abstract class AndroidUIXmlProcessor(protected val project: Project) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun KotlinStringWriter.writeAndroidImports() {
|
private fun KotlinStringWriter.writeAndroidImports() {
|
||||||
androidImports.forEach { writeImport(it) }
|
ANDROID_IMPORTS.forEach { writeImport(it) }
|
||||||
writeEmptyLine()
|
writeEmptyLine()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,9 +142,10 @@ public abstract class AndroidUIXmlProcessor(protected val project: Project) {
|
|||||||
|
|
||||||
private fun KotlinStringWriter.writeSyntheticProperty(receiver: String, widget: AndroidWidget, stubCall: String) {
|
private fun KotlinStringWriter.writeSyntheticProperty(receiver: String, widget: AndroidWidget, stubCall: String) {
|
||||||
val body = arrayListOf("return $stubCall as ${widget.className}")
|
val body = arrayListOf("return $stubCall as ${widget.className}")
|
||||||
|
val type = widget.className
|
||||||
writeImmutableExtensionProperty(receiver,
|
writeImmutableExtensionProperty(receiver,
|
||||||
name = widget.id,
|
name = widget.id,
|
||||||
retType = widget.className,
|
retType = "$EXPLICIT_FLEXIBLE_CLASS_NAME<$type, $type?>",
|
||||||
getterBody = body)
|
getterBody = body)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,11 +156,17 @@ public abstract class AndroidUIXmlProcessor(protected val project: Project) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class object {
|
class object {
|
||||||
private val androidImports = listOf(
|
private val EXPLICIT_FLEXIBLE_PACKAGE = Flexibility.FLEXIBLE_TYPE_CLASSIFIER.getPackageFqName().asString()
|
||||||
|
private val EXPLICIT_FLEXIBLE_CLASS_NAME = Flexibility.FLEXIBLE_TYPE_CLASSIFIER.getRelativeClassName().asString()
|
||||||
|
|
||||||
|
private val ANDROID_IMPORTS = listOf(
|
||||||
"android.app.Activity",
|
"android.app.Activity",
|
||||||
"android.app.Fragment",
|
"android.app.Fragment",
|
||||||
"android.view.View",
|
"android.view.View",
|
||||||
"android.widget.*")
|
"android.widget.*",
|
||||||
|
Flexibility.FLEXIBLE_TYPE_CLASSIFIER.asSingleFqName().asString())
|
||||||
|
|
||||||
|
private val FLEXIBLE_TYPE_FILE = "package $EXPLICIT_FLEXIBLE_PACKAGE\n\nclass $EXPLICIT_FLEXIBLE_CLASS_NAME<L, U>"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+3
-2
@@ -4,10 +4,11 @@ import android.app.Activity
|
|||||||
import android.app.Fragment
|
import android.app.Fragment
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import kotlin.internal.flexible.ft
|
||||||
|
|
||||||
val Activity.MyButton: org.my.cool.Button
|
val Activity.MyButton: ft<org.my.cool.Button, org.my.cool.Button?>
|
||||||
get() = findViewById(0) as org.my.cool.Button
|
get() = findViewById(0) as org.my.cool.Button
|
||||||
|
|
||||||
val Fragment.MyButton: org.my.cool.Button
|
val Fragment.MyButton: ft<org.my.cool.Button, org.my.cool.Button?>
|
||||||
get() = getView().findViewById(0) as org.my.cool.Button
|
get() = getView().findViewById(0) as org.my.cool.Button
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -4,7 +4,8 @@ import android.app.Activity
|
|||||||
import android.app.Fragment
|
import android.app.Fragment
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import kotlin.internal.flexible.ft
|
||||||
|
|
||||||
val View.MyButton: org.my.cool.Button
|
val View.MyButton: ft<org.my.cool.Button, org.my.cool.Button?>
|
||||||
get() = findViewById(0) as org.my.cool.Button
|
get() = findViewById(0) as org.my.cool.Button
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -4,10 +4,11 @@ import android.app.Activity
|
|||||||
import android.app.Fragment
|
import android.app.Fragment
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import kotlin.internal.flexible.ft
|
||||||
|
|
||||||
val Activity.MyButton: org.my.cool.Button
|
val Activity.MyButton: ft<org.my.cool.Button, org.my.cool.Button?>
|
||||||
get() = findViewById(0) as org.my.cool.Button
|
get() = findViewById(0) as org.my.cool.Button
|
||||||
|
|
||||||
val Fragment.MyButton: org.my.cool.Button
|
val Fragment.MyButton: ft<org.my.cool.Button, org.my.cool.Button?>
|
||||||
get() = getView().findViewById(0) as org.my.cool.Button
|
get() = getView().findViewById(0) as org.my.cool.Button
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -4,7 +4,8 @@ import android.app.Activity
|
|||||||
import android.app.Fragment
|
import android.app.Fragment
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import kotlin.internal.flexible.ft
|
||||||
|
|
||||||
val View.MyButton: org.my.cool.Button
|
val View.MyButton: ft<org.my.cool.Button, org.my.cool.Button?>
|
||||||
get() = findViewById(0) as org.my.cool.Button
|
get() = findViewById(0) as org.my.cool.Button
|
||||||
|
|
||||||
|
|||||||
+9
-8
@@ -4,28 +4,29 @@ import android.app.Activity
|
|||||||
import android.app.Fragment
|
import android.app.Fragment
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import kotlin.internal.flexible.ft
|
||||||
|
|
||||||
val Activity.item_detail_container: FrameLayout
|
val Activity.item_detail_container: ft<FrameLayout, FrameLayout?>
|
||||||
get() = findViewById(0) as FrameLayout
|
get() = findViewById(0) as FrameLayout
|
||||||
|
|
||||||
val Fragment.item_detail_container: FrameLayout
|
val Fragment.item_detail_container: ft<FrameLayout, FrameLayout?>
|
||||||
get() = getView().findViewById(0) as FrameLayout
|
get() = getView().findViewById(0) as FrameLayout
|
||||||
|
|
||||||
val Activity.textView1: TextView
|
val Activity.textView1: ft<TextView, TextView?>
|
||||||
get() = findViewById(0) as TextView
|
get() = findViewById(0) as TextView
|
||||||
|
|
||||||
val Fragment.textView1: TextView
|
val Fragment.textView1: ft<TextView, TextView?>
|
||||||
get() = getView().findViewById(0) as TextView
|
get() = getView().findViewById(0) as TextView
|
||||||
|
|
||||||
val Activity.password: EditText
|
val Activity.password: ft<EditText, EditText?>
|
||||||
get() = findViewById(0) as EditText
|
get() = findViewById(0) as EditText
|
||||||
|
|
||||||
val Fragment.password: EditText
|
val Fragment.password: ft<EditText, EditText?>
|
||||||
get() = getView().findViewById(0) as EditText
|
get() = getView().findViewById(0) as EditText
|
||||||
|
|
||||||
val Activity.login: Button
|
val Activity.login: ft<Button, Button?>
|
||||||
get() = findViewById(0) as Button
|
get() = findViewById(0) as Button
|
||||||
|
|
||||||
val Fragment.login: Button
|
val Fragment.login: ft<Button, Button?>
|
||||||
get() = getView().findViewById(0) as Button
|
get() = getView().findViewById(0) as Button
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -4,16 +4,17 @@ import android.app.Activity
|
|||||||
import android.app.Fragment
|
import android.app.Fragment
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import kotlin.internal.flexible.ft
|
||||||
|
|
||||||
val View.item_detail_container: FrameLayout
|
val View.item_detail_container: ft<FrameLayout, FrameLayout?>
|
||||||
get() = findViewById(0) as FrameLayout
|
get() = findViewById(0) as FrameLayout
|
||||||
|
|
||||||
val View.textView1: TextView
|
val View.textView1: ft<TextView, TextView?>
|
||||||
get() = findViewById(0) as TextView
|
get() = findViewById(0) as TextView
|
||||||
|
|
||||||
val View.password: EditText
|
val View.password: ft<EditText, EditText?>
|
||||||
get() = findViewById(0) as EditText
|
get() = findViewById(0) as EditText
|
||||||
|
|
||||||
val View.login: Button
|
val View.login: ft<Button, Button?>
|
||||||
get() = findViewById(0) as Button
|
get() = findViewById(0) as Button
|
||||||
|
|
||||||
|
|||||||
+9
-8
@@ -4,28 +4,29 @@ import android.app.Activity
|
|||||||
import android.app.Fragment
|
import android.app.Fragment
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import kotlin.internal.flexible.ft
|
||||||
|
|
||||||
val Activity.frameLayout: FrameLayout
|
val Activity.frameLayout: ft<FrameLayout, FrameLayout?>
|
||||||
get() = findViewById(0) as FrameLayout
|
get() = findViewById(0) as FrameLayout
|
||||||
|
|
||||||
val Fragment.frameLayout: FrameLayout
|
val Fragment.frameLayout: ft<FrameLayout, FrameLayout?>
|
||||||
get() = getView().findViewById(0) as FrameLayout
|
get() = getView().findViewById(0) as FrameLayout
|
||||||
|
|
||||||
val Activity.passwordField: TextView
|
val Activity.passwordField: ft<TextView, TextView?>
|
||||||
get() = findViewById(0) as TextView
|
get() = findViewById(0) as TextView
|
||||||
|
|
||||||
val Fragment.passwordField: TextView
|
val Fragment.passwordField: ft<TextView, TextView?>
|
||||||
get() = getView().findViewById(0) as TextView
|
get() = getView().findViewById(0) as TextView
|
||||||
|
|
||||||
val Activity.passwordCaption: EditText
|
val Activity.passwordCaption: ft<EditText, EditText?>
|
||||||
get() = findViewById(0) as EditText
|
get() = findViewById(0) as EditText
|
||||||
|
|
||||||
val Fragment.passwordCaption: EditText
|
val Fragment.passwordCaption: ft<EditText, EditText?>
|
||||||
get() = getView().findViewById(0) as EditText
|
get() = getView().findViewById(0) as EditText
|
||||||
|
|
||||||
val Activity.loginButton: Button
|
val Activity.loginButton: ft<Button, Button?>
|
||||||
get() = findViewById(0) as Button
|
get() = findViewById(0) as Button
|
||||||
|
|
||||||
val Fragment.loginButton: Button
|
val Fragment.loginButton: ft<Button, Button?>
|
||||||
get() = getView().findViewById(0) as Button
|
get() = getView().findViewById(0) as Button
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -4,16 +4,17 @@ import android.app.Activity
|
|||||||
import android.app.Fragment
|
import android.app.Fragment
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import kotlin.internal.flexible.ft
|
||||||
|
|
||||||
val View.frameLayout: FrameLayout
|
val View.frameLayout: ft<FrameLayout, FrameLayout?>
|
||||||
get() = findViewById(0) as FrameLayout
|
get() = findViewById(0) as FrameLayout
|
||||||
|
|
||||||
val View.passwordField: TextView
|
val View.passwordField: ft<TextView, TextView?>
|
||||||
get() = findViewById(0) as TextView
|
get() = findViewById(0) as TextView
|
||||||
|
|
||||||
val View.passwordCaption: EditText
|
val View.passwordCaption: ft<EditText, EditText?>
|
||||||
get() = findViewById(0) as EditText
|
get() = findViewById(0) as EditText
|
||||||
|
|
||||||
val View.loginButton: Button
|
val View.loginButton: ft<Button, Button?>
|
||||||
get() = findViewById(0) as Button
|
get() = findViewById(0) as Button
|
||||||
|
|
||||||
|
|||||||
+9
-8
@@ -4,28 +4,29 @@ import android.app.Activity
|
|||||||
import android.app.Fragment
|
import android.app.Fragment
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import kotlin.internal.flexible.ft
|
||||||
|
|
||||||
val Activity.item_detail_container: FrameLayout
|
val Activity.item_detail_container: ft<FrameLayout, FrameLayout?>
|
||||||
get() = findViewById(0) as FrameLayout
|
get() = findViewById(0) as FrameLayout
|
||||||
|
|
||||||
val Fragment.item_detail_container: FrameLayout
|
val Fragment.item_detail_container: ft<FrameLayout, FrameLayout?>
|
||||||
get() = getView().findViewById(0) as FrameLayout
|
get() = getView().findViewById(0) as FrameLayout
|
||||||
|
|
||||||
val Activity.textView1: TextView
|
val Activity.textView1: ft<TextView, TextView?>
|
||||||
get() = findViewById(0) as TextView
|
get() = findViewById(0) as TextView
|
||||||
|
|
||||||
val Fragment.textView1: TextView
|
val Fragment.textView1: ft<TextView, TextView?>
|
||||||
get() = getView().findViewById(0) as TextView
|
get() = getView().findViewById(0) as TextView
|
||||||
|
|
||||||
val Activity.password: EditText
|
val Activity.password: ft<EditText, EditText?>
|
||||||
get() = findViewById(0) as EditText
|
get() = findViewById(0) as EditText
|
||||||
|
|
||||||
val Fragment.password: EditText
|
val Fragment.password: ft<EditText, EditText?>
|
||||||
get() = getView().findViewById(0) as EditText
|
get() = getView().findViewById(0) as EditText
|
||||||
|
|
||||||
val Activity.login: Button
|
val Activity.login: ft<Button, Button?>
|
||||||
get() = findViewById(0) as Button
|
get() = findViewById(0) as Button
|
||||||
|
|
||||||
val Fragment.login: Button
|
val Fragment.login: ft<Button, Button?>
|
||||||
get() = getView().findViewById(0) as Button
|
get() = getView().findViewById(0) as Button
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -4,16 +4,17 @@ import android.app.Activity
|
|||||||
import android.app.Fragment
|
import android.app.Fragment
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import kotlin.internal.flexible.ft
|
||||||
|
|
||||||
val View.item_detail_container: FrameLayout
|
val View.item_detail_container: ft<FrameLayout, FrameLayout?>
|
||||||
get() = findViewById(0) as FrameLayout
|
get() = findViewById(0) as FrameLayout
|
||||||
|
|
||||||
val View.textView1: TextView
|
val View.textView1: ft<TextView, TextView?>
|
||||||
get() = findViewById(0) as TextView
|
get() = findViewById(0) as TextView
|
||||||
|
|
||||||
val View.password: EditText
|
val View.password: ft<EditText, EditText?>
|
||||||
get() = findViewById(0) as EditText
|
get() = findViewById(0) as EditText
|
||||||
|
|
||||||
val View.login: Button
|
val View.login: ft<Button, Button?>
|
||||||
get() = findViewById(0) as Button
|
get() = findViewById(0) as Button
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user