Escape layout names which are Kotlin keywords
This commit is contained in:
+2
-2
@@ -49,7 +49,7 @@ public fun idToName(id: String): String? {
|
||||
if (isResourceIdDeclaration(id)) id.replace(AndroidConst.ID_DECLARATION_PREFIX, "")
|
||||
else if (isResourceIdUsage(id)) id.replace(AndroidConst.ID_USAGE_PREFIX, "")
|
||||
else null
|
||||
return if (unescaped != null) escapeWidgetId(unescaped) else null
|
||||
return if (unescaped != null) escapeAndroidIdentifier(unescaped) else null
|
||||
}
|
||||
|
||||
public fun isResourceIdDeclaration(str: String?): Boolean = str?.startsWith(AndroidConst.ID_DECLARATION_PREFIX) ?: false
|
||||
@@ -67,6 +67,6 @@ public fun getRealWidgetType(xmlType: String): String = when (xmlType) {
|
||||
else -> xmlType
|
||||
}
|
||||
|
||||
public fun escapeWidgetId(id: String): String {
|
||||
fun escapeAndroidIdentifier(id: String): String {
|
||||
return if (id in AndroidConst.ESCAPED_IDENTIFIERS) "`$id`" else id
|
||||
}
|
||||
+1
-1
@@ -136,7 +136,7 @@ public abstract class AndroidUIXmlProcessor(protected val project: Project) {
|
||||
}
|
||||
|
||||
private fun PsiFile.genSyntheticPackageName(): String {
|
||||
return AndroidConst.SYNTHETIC_PACKAGE + "." + getName().substringBefore('.')
|
||||
return AndroidConst.SYNTHETIC_PACKAGE + "." + escapeAndroidIdentifier(getName().substringBefore('.'))
|
||||
}
|
||||
|
||||
private fun KotlinStringWriter.writeSyntheticProperty(receiver: String, widget: AndroidWidget, stubCall: String) {
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.myapp"
|
||||
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>
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package kotlinx.android.synthetic.`get`
|
||||
|
||||
import android.app.*
|
||||
import android.view.*
|
||||
import android.widget.*
|
||||
import android.webkit.*
|
||||
import android.inputmethodservice.*
|
||||
import android.opengl.*
|
||||
import android.appwidget.*
|
||||
import android.support.v4.app.*
|
||||
import android.support.v4.view.*
|
||||
import android.support.v4.widget.*
|
||||
import kotlin.internal.flexible.ft
|
||||
|
||||
val android.app.Activity.item_detail_container: ft<FrameLayout, FrameLayout?>
|
||||
get() = findViewById(0) as? FrameLayout
|
||||
|
||||
val android.app.Fragment.item_detail_container: ft<FrameLayout, FrameLayout?>
|
||||
get() = getView().findViewById(0) as? FrameLayout
|
||||
|
||||
val android.app.Activity.textView1: ft<TextView, TextView?>
|
||||
get() = findViewById(0) as? TextView
|
||||
|
||||
val android.app.Fragment.textView1: ft<TextView, TextView?>
|
||||
get() = getView().findViewById(0) as? TextView
|
||||
|
||||
val android.app.Activity.password: ft<EditText, EditText?>
|
||||
get() = findViewById(0) as? EditText
|
||||
|
||||
val android.app.Fragment.password: ft<EditText, EditText?>
|
||||
get() = getView().findViewById(0) as? EditText
|
||||
|
||||
val android.app.Activity.login: ft<Button, Button?>
|
||||
get() = findViewById(0) as? Button
|
||||
|
||||
val android.app.Fragment.login: ft<Button, Button?>
|
||||
get() = getView().findViewById(0) as? Button
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package kotlinx.android.synthetic.`get`.view
|
||||
|
||||
import android.app.*
|
||||
import android.view.*
|
||||
import android.widget.*
|
||||
import android.webkit.*
|
||||
import android.inputmethodservice.*
|
||||
import android.opengl.*
|
||||
import android.appwidget.*
|
||||
import android.support.v4.app.*
|
||||
import android.support.v4.view.*
|
||||
import android.support.v4.widget.*
|
||||
import kotlin.internal.flexible.ft
|
||||
|
||||
val android.view.View.item_detail_container: ft<FrameLayout, FrameLayout?>
|
||||
get() = findViewById(0) as? FrameLayout
|
||||
|
||||
val android.view.View.textView1: ft<TextView, TextView?>
|
||||
get() = findViewById(0) as? TextView
|
||||
|
||||
val android.view.View.password: ft<EditText, EditText?>
|
||||
get() = findViewById(0) as? EditText
|
||||
|
||||
val android.view.View.login: ft<Button, Button?>
|
||||
get() = findViewById(0) as? Button
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<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" >
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Enter your password" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="textPassword" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Sign in" />
|
||||
|
||||
</FrameLayout>
|
||||
+6
@@ -42,6 +42,12 @@ public class AndroidXml2KConversionTestGenerated extends AbstractAndroidXml2KCon
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/android-compiler-plugin/testData/android/converter/simple"), Pattern.compile("^([^\\.]+)$"), false);
|
||||
}
|
||||
|
||||
@TestMetadata("escapedLayoutName")
|
||||
public void testEscapedLayoutName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("plugins/android-compiler-plugin/testData/android/converter/simple/escapedLayoutName/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("fqNameInAttr")
|
||||
public void testFqNameInAttr() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("plugins/android-compiler-plugin/testData/android/converter/simple/fqNameInAttr/");
|
||||
|
||||
Reference in New Issue
Block a user