Support androidx packages

... in the IDE plugin and the Android extensions compiler.

Change-Id: Iffd58351b0592e12ffc937c06d871d26958fe161
This commit is contained in:
Raluca Sauciuc
2018-04-06 08:42:17 -07:00
committed by Yan Zhulanow
parent 612baacc25
commit 89d61ee12d
13 changed files with 166 additions and 8 deletions
@@ -49,6 +49,8 @@ object AndroidConst {
val SUPPORT_V4_PACKAGE = "android.support.v4"
val SUPPORT_FRAGMENT_FQNAME = "$SUPPORT_V4_PACKAGE.app.Fragment"
val SUPPORT_FRAGMENT_ACTIVITY_FQNAME = "$SUPPORT_V4_PACKAGE.app.FragmentActivity"
val ANDROIDX_SUPPORT_FRAGMENT_FQNAME = "androidx.fragment.app.Fragment"
val ANDROIDX_SUPPORT_FRAGMENT_ACTIVITY_FQNAME = "androidx.fragment.app.FragmentActivity"
val IGNORED_XML_WIDGET_TYPES = setOf("requestFocus", "merge", "tag", "check", "blink")
@@ -252,11 +252,11 @@ abstract class AbstractAndroidExtensionsExpressionCodegenExtension : ExpressionC
val containerType = containerOptions.containerType
when (containerType) {
AndroidContainerType.ACTIVITY, AndroidContainerType.SUPPORT_FRAGMENT_ACTIVITY, AndroidContainerType.VIEW, AndroidContainerType.DIALOG -> {
AndroidContainerType.ACTIVITY, AndroidContainerType.ANDROIDX_SUPPORT_FRAGMENT_ACTIVITY, AndroidContainerType.SUPPORT_FRAGMENT_ACTIVITY, AndroidContainerType.VIEW, AndroidContainerType.DIALOG -> {
loadId()
iv.invokevirtual(containerType.internalClassName, "findViewById", "(I)Landroid/view/View;", false)
}
AndroidContainerType.FRAGMENT, AndroidContainerType.SUPPORT_FRAGMENT, LAYOUT_CONTAINER -> {
AndroidContainerType.FRAGMENT, AndroidContainerType.ANDROIDX_SUPPORT_FRAGMENT, AndroidContainerType.SUPPORT_FRAGMENT, LAYOUT_CONTAINER -> {
if (containerType == LAYOUT_CONTAINER) {
iv.invokeinterface(containerType.internalClassName, "getContainerView", "()Landroid/view/View;")
} else {
@@ -25,6 +25,8 @@ enum class AndroidContainerType(className: String, val doesSupportCache: Boolean
ACTIVITY(AndroidConst.ACTIVITY_FQNAME, doesSupportCache = true),
FRAGMENT(AndroidConst.FRAGMENT_FQNAME, doesSupportCache = true, isFragment = true),
DIALOG(AndroidConst.DIALOG_FQNAME, doesSupportCache = false),
ANDROIDX_SUPPORT_FRAGMENT_ACTIVITY(AndroidConst.ANDROIDX_SUPPORT_FRAGMENT_ACTIVITY_FQNAME, doesSupportCache = true),
ANDROIDX_SUPPORT_FRAGMENT(AndroidConst.ANDROIDX_SUPPORT_FRAGMENT_FQNAME, doesSupportCache = true, isFragment = true),
SUPPORT_FRAGMENT_ACTIVITY(AndroidConst.SUPPORT_FRAGMENT_ACTIVITY_FQNAME, doesSupportCache = true),
SUPPORT_FRAGMENT(AndroidConst.SUPPORT_FRAGMENT_FQNAME, doesSupportCache = true, isFragment = true),
VIEW(AndroidConst.VIEW_FQNAME, doesSupportCache = true),
@@ -41,6 +43,8 @@ enum class AndroidContainerType(className: String, val doesSupportCache: Boolean
AndroidConst.ACTIVITY_FQNAME -> AndroidContainerType.ACTIVITY
AndroidConst.FRAGMENT_FQNAME -> AndroidContainerType.FRAGMENT
AndroidConst.DIALOG_FQNAME -> AndroidContainerType.DIALOG
AndroidConst.ANDROIDX_SUPPORT_FRAGMENT_ACTIVITY_FQNAME -> AndroidContainerType.ANDROIDX_SUPPORT_FRAGMENT_ACTIVITY
AndroidConst.ANDROIDX_SUPPORT_FRAGMENT_FQNAME -> AndroidContainerType.ANDROIDX_SUPPORT_FRAGMENT
AndroidConst.SUPPORT_FRAGMENT_ACTIVITY_FQNAME -> AndroidContainerType.SUPPORT_FRAGMENT_ACTIVITY
AndroidConst.SUPPORT_FRAGMENT_FQNAME -> AndroidContainerType.SUPPORT_FRAGMENT
AndroidConst.VIEW_FQNAME -> AndroidContainerType.VIEW
@@ -38,7 +38,7 @@ class ResourcePropertyStackValue(
override fun putSelector(type: Type, kotlinType: KotlinType?, v: InstructionAdapter) {
val returnTypeString = typeMapper.mapType(resource.type.lowerIfFlexible()).className
if (AndroidConst.FRAGMENT_FQNAME == returnTypeString || AndroidConst.SUPPORT_FRAGMENT_FQNAME == returnTypeString) {
if (AndroidConst.FRAGMENT_FQNAME == returnTypeString || AndroidConst.SUPPORT_FRAGMENT_FQNAME == returnTypeString || AndroidConst.ANDROIDX_SUPPORT_FRAGMENT_FQNAME == returnTypeString) {
return putSelectorForFragment(v)
}
@@ -56,12 +56,12 @@ class ResourcePropertyStackValue(
}
else {
when (containerType) {
AndroidContainerType.ACTIVITY, AndroidContainerType.SUPPORT_FRAGMENT_ACTIVITY, AndroidContainerType.VIEW, AndroidContainerType.DIALOG -> {
AndroidContainerType.ACTIVITY, AndroidContainerType.ANDROIDX_SUPPORT_FRAGMENT_ACTIVITY, AndroidContainerType.SUPPORT_FRAGMENT_ACTIVITY, AndroidContainerType.VIEW, AndroidContainerType.DIALOG -> {
receiver.put(Type.getType("L${containerType.internalClassName};"), v)
getResourceId(v)
v.invokevirtual(containerType.internalClassName, "findViewById", "(I)Landroid/view/View;", false)
}
AndroidContainerType.FRAGMENT, AndroidContainerType.SUPPORT_FRAGMENT -> {
AndroidContainerType.FRAGMENT, AndroidContainerType.ANDROIDX_SUPPORT_FRAGMENT, AndroidContainerType.SUPPORT_FRAGMENT -> {
receiver.put(Type.getType("L${containerType.internalClassName};"), v)
v.invokevirtual(containerType.internalClassName, "getView", "()Landroid/view/View;", false)
getResourceId(v)
@@ -99,6 +99,16 @@ class ResourcePropertyStackValue(
getResourceId(v)
v.invokevirtual("android/support/v4/app/FragmentManager", "findFragmentById", "(I)Landroid/support/v4/app/Fragment;", false)
}
AndroidContainerType.ANDROIDX_SUPPORT_FRAGMENT -> {
v.invokevirtual(containerType.internalClassName, "getFragmentManager", "()Landroidx/fragment/app/FragmentManager;", false)
getResourceId(v)
v.invokevirtual("androidx/fragment/app/FragmentManager", "findFragmentById", "(I)Landroidx/fragment/app/Fragment;", false)
}
AndroidContainerType.ANDROIDX_SUPPORT_FRAGMENT_ACTIVITY -> {
v.invokevirtual(containerType.internalClassName, "getSupportFragmentManager", "()Landroidx/fragment/app/FragmentManager;", false)
getResourceId(v)
v.invokevirtual("androidx/fragment/app/FragmentManager", "findFragmentById", "(I)Landroidx/fragment/app/Fragment;", false)
}
else -> throw IllegalStateException("Invalid Android class type: $containerType") // Should never occur
}
@@ -42,8 +42,8 @@ class LazySyntheticElementResolveContext(private val module: ModuleDescriptor, s
val activityDescriptor = find(AndroidConst.ACTIVITY_FQNAME) ?: return SyntheticElementResolveContext.ERROR_CONTEXT
val fragmentDescriptor = find(AndroidConst.FRAGMENT_FQNAME)
val dialogDescriptor = find(AndroidConst.DIALOG_FQNAME) ?: return SyntheticElementResolveContext.ERROR_CONTEXT
val supportActivityDescriptor = find(AndroidConst.SUPPORT_FRAGMENT_ACTIVITY_FQNAME)
val supportFragmentDescriptor = find(AndroidConst.SUPPORT_FRAGMENT_FQNAME)
val supportActivityDescriptor = find(AndroidConst.ANDROIDX_SUPPORT_FRAGMENT_ACTIVITY_FQNAME) ?: find(AndroidConst.SUPPORT_FRAGMENT_ACTIVITY_FQNAME)
val supportFragmentDescriptor = find(AndroidConst.ANDROIDX_SUPPORT_FRAGMENT_FQNAME) ?: find(AndroidConst.SUPPORT_FRAGMENT_FQNAME)
val layoutContainerDescriptor = find(LayoutContainer::class.java.canonicalName)
return SyntheticElementResolveContext(
@@ -169,18 +169,36 @@ public class AndroidBytecodeShapeTestGenerated extends AbstractAndroidBytecodeSh
doTest(fileName);
}
@TestMetadata("supportExtensionFunctionsFragmentAndroidx")
public void testSupportExtensionFunctionsFragmentAndroidx() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/bytecodeShape/supportExtensionFunctionsFragmentAndroidx/");
doTest(fileName);
}
@TestMetadata("supportSimpleFragment")
public void testSupportSimpleFragment() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/bytecodeShape/supportSimpleFragment/");
doTest(fileName);
}
@TestMetadata("supportSimpleFragmentAndroidx")
public void testSupportSimpleFragmentAndroidx() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/bytecodeShape/supportSimpleFragmentAndroidx/");
doTest(fileName);
}
@TestMetadata("supportSimpleFragmentProperty")
public void testSupportSimpleFragmentProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/bytecodeShape/supportSimpleFragmentProperty/");
doTest(fileName);
}
@TestMetadata("supportSimpleFragmentPropertyAndroidx")
public void testSupportSimpleFragmentPropertyAndroidx() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/bytecodeShape/supportSimpleFragmentPropertyAndroidx/");
doTest(fileName);
}
@TestMetadata("viewStub")
public void testViewStub() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/bytecodeShape/viewStub/");
@@ -0,0 +1,17 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,26 @@
package androidx.fragment.app
import android.app.Activity
import android.view.View
import android.os.Bundle
import java.io.File
import kotlinx.android.synthetic.main.layout.*
open class Fragment {
open fun getActivity(): Activity = throw Exception("Function getActivity() is not overridden")
open fun getView(): View = throw Exception("Function getView() is not overridden")
}
public class MyFragment : Fragment()
fun MyFragment.b() {
val x = login
val y = this.login
}
// 2 public _\$_findCachedViewById
// 2 public _\$_clearFindViewByIdCache
// 2 INVOKEVIRTUAL androidx/fragment/app/Fragment\.getView
// 2 GETSTATIC test/R\$id\.login
// 2 INVOKEVIRTUAL androidx/fragment/app/MyFragment\._\$_findCachedViewById
// 2 CHECKCAST android/widget/Button
@@ -0,0 +1,17 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,22 @@
package androidx.fragment.app
import android.app.Activity
import android.view.View
import java.io.File
import kotlinx.android.synthetic.main.layout.*
open class Fragment {
open fun getActivity(): Activity = throw Exception("Function getActivity() is not overridden")
open fun getView(): View = throw Exception("Function getView() is not overridden")
}
public class MyFragment : Fragment() {
init {login}
}
// 2 public _\$_findCachedViewById
// 2 public _\$_clearFindViewByIdCache
// 2 INVOKEVIRTUAL androidx/fragment/app/Fragment\.getView
// 1 GETSTATIC test/R\$id\.login
// 1 INVOKEVIRTUAL androidx/fragment/app/MyFragment\._\$_findCachedViewById
// 1 CHECKCAST android/widget/Button
@@ -0,0 +1,10 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/fragm"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
@@ -0,0 +1,31 @@
package androidx.fragment.app
import android.app.Activity
import android.os.Bundle
import java.io.File
import kotlinx.android.synthetic.main.layout.*
open class FragmentManager {
open fun findFragmentById(id: Int): Fragment = throw Exception("Function getFragmentById() is not overriden")
}
open class Fragment {
open fun getFragmentManager(): FragmentManager = throw Exception("Function getFragmentManager() is not overriden")
}
open class FragmentActivity : Activity() {
open fun getSupportFragmentManager(): FragmentManager = throw Exception("Function getSupportFragmentManager() is not overriden")
}
public class MyActivity : FragmentActivity() {
init { fragm }
}
public class MyFragment : Fragment() {
init { fragm }
}
// 1 INVOKEVIRTUAL androidx/fragment/app/FragmentActivity\.getSupportFragmentManager
// 1 INVOKEVIRTUAL androidx/fragment/app/Fragment\.getFragmentManager
// 2 GETSTATIC test/R\$id\.fragm
// 2 INVOKEVIRTUAL androidx/fragment/app/FragmentManager\.findFragmentById