Escape layout names which are Kotlin keywords

This commit is contained in:
Yan Zhulanow
2015-04-01 21:33:53 +03:00
parent 3aa6edca7b
commit e6fa6e9a5d
7 changed files with 135 additions and 3 deletions
@@ -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
}
@@ -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) {