Ignore some XML tags

This commit is contained in:
Yan Zhulanow
2015-03-25 17:15:09 +03:00
parent 938248bd29
commit 2af538e854
9 changed files with 18 additions and 13 deletions
@@ -33,6 +33,8 @@ public object AndroidConst {
val ID_USAGE_PREFIX = "@id/"
val CLEAR_FUNCTION_NAME = "clearFindViewByIdCache"
val IGNORED_XML_WIDGET_TYPES = setOf("requestFocus", "merge", "tag", "check")
}
public fun nameToIdDeclaration(name: String): String = AndroidConst.ID_DECLARATION_PREFIX + name
@@ -49,7 +51,11 @@ public fun isResourceIdUsage(str: String?): Boolean = str?.startsWith(AndroidCon
public fun isResourceDeclarationOrUsage(id: String?): Boolean = isResourceIdDeclaration(id) || isResourceIdUsage(id)
public fun isWidgetTypeIgnored(xmlType: String): Boolean {
return (xmlType.isEmpty() || xmlType in AndroidConst.IGNORED_XML_WIDGET_TYPES)
}
public fun getRealWidgetType(xmlType: String): String = when (xmlType) {
"fragment", "include", "merge" -> "View"
"fragment", "include" -> "View"
else -> xmlType
}
@@ -31,6 +31,7 @@ class AndroidXmlHandler(private val elementCallback: (String, String) -> Unit) :
}
override fun startElement(uri: String, localName: String, qName: String, attributes: Attributes) {
if (isWidgetTypeIgnored(localName)) return
val attributesMap = attributes.toMap()
val idAttribute = attributesMap[AndroidConst.ID_ATTRIBUTE_NO_NAMESPACE]
val widgetType = getRealWidgetType(attributesMap[AndroidConst.CLASS_ATTRIBUTE_NO_NAMESPACE] ?: localName)