Android Extensions: Allow LayoutContainers in inner/local classes and objects
This commit is contained in:
committed by
Yan Zhulanow
parent
07be1e9d10
commit
7b4e24a454
+1
-1
@@ -154,7 +154,7 @@ abstract class AbstractAndroidExtensionsExpressionCodegenExtension : ExpressionC
|
|||||||
val targetClass = codegen.myClass as? KtClass ?: return
|
val targetClass = codegen.myClass as? KtClass ?: return
|
||||||
|
|
||||||
val container = codegen.descriptor
|
val container = codegen.descriptor
|
||||||
if (container.kind != ClassKind.CLASS || container.isInner || DescriptorUtils.isLocal(container)) return
|
if (container.kind != ClassKind.CLASS && container.kind != ClassKind.OBJECT) return
|
||||||
|
|
||||||
val containerOptions = ContainerOptionsProxy.create(container)
|
val containerOptions = ContainerOptionsProxy.create(container)
|
||||||
if (containerOptions.getCacheOrDefault(targetClass) == NO_CACHE) return
|
if (containerOptions.getCacheOrDefault(targetClass) == NO_CACHE) return
|
||||||
|
|||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.*
|
||||||
|
import kotlinx.android.synthetic.main.layout.*
|
||||||
|
import kotlinx.android.extensions.*
|
||||||
|
|
||||||
|
class R {
|
||||||
|
class id {
|
||||||
|
companion object {
|
||||||
|
const val login = 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyActivity(): Activity() {
|
||||||
|
val loginItem = Button(this)
|
||||||
|
|
||||||
|
val entity = MyEntity(object : FrameLayout(this) {
|
||||||
|
override fun findViewById(id: Int) : View? = when(id) {
|
||||||
|
R.id.login -> loginItem
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
val entity2: LayoutContainer = entity
|
||||||
|
|
||||||
|
public fun box(): String {
|
||||||
|
val o = if (entity.login.toString() == "Button") "O" else ""
|
||||||
|
val k = if (entity2.login.toString() == "Button") "K" else ""
|
||||||
|
return o + k // "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class MyEntity(override val containerView: View) : LayoutContainer
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return MyActivity().box()
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.*
|
||||||
|
import kotlinx.android.synthetic.main.layout.*
|
||||||
|
import kotlinx.android.extensions.*
|
||||||
|
|
||||||
|
class R {
|
||||||
|
class id {
|
||||||
|
companion object {
|
||||||
|
const val login = 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyActivity(): Activity() {
|
||||||
|
val loginItem = Button(this)
|
||||||
|
val entity = MyEntity(loginItem)
|
||||||
|
|
||||||
|
init {
|
||||||
|
entity.login
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class MyEntity(override val containerView: View) : LayoutContainer
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="test"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0" >
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.READ_CONTACTS"/>
|
||||||
|
<uses-sdk
|
||||||
|
android:minSdkVersion="18"
|
||||||
|
android:targetSdkVersion="18" />
|
||||||
|
<permission android:name="android"></permission>
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:icon="@drawable/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:theme="@style/Theme.Sample" >
|
||||||
|
<activity
|
||||||
|
android:name="com.example.android.basiccontactables.MainActivity"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:launchMode="singleTop">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.app.searchable"
|
||||||
|
android:resource="@xml/searchable" />
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEARCH" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/login"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
+12
@@ -44,6 +44,12 @@ public class AndroidBoxTestGenerated extends AbstractAndroidBoxTest {
|
|||||||
doCompileAgainstAndroidSdkTest(fileName);
|
doCompileAgainstAndroidSdkTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("androidEntityInnerClass")
|
||||||
|
public void testAndroidEntityInnerClass() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/android/androidEntityInnerClass/");
|
||||||
|
doCompileAgainstAndroidSdkTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("fqNameInAttr")
|
@TestMetadata("fqNameInAttr")
|
||||||
public void testFqNameInAttr() throws Exception {
|
public void testFqNameInAttr() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/android/fqNameInAttr/");
|
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/android/fqNameInAttr/");
|
||||||
@@ -107,6 +113,12 @@ public class AndroidBoxTestGenerated extends AbstractAndroidBoxTest {
|
|||||||
doFakeInvocationTest(fileName);
|
doFakeInvocationTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("androidEntityInnerClass")
|
||||||
|
public void testAndroidEntityInnerClass() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/android/androidEntityInnerClass/");
|
||||||
|
doFakeInvocationTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("fqNameInAttr")
|
@TestMetadata("fqNameInAttr")
|
||||||
public void testFqNameInAttr() throws Exception {
|
public void testFqNameInAttr() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/android/fqNameInAttr/");
|
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/android/fqNameInAttr/");
|
||||||
|
|||||||
Reference in New Issue
Block a user