diff --git a/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidConst.kt b/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidConst.kt index 1cfa552c0f9..160c87fdf2a 100644 --- a/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidConst.kt +++ b/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidConst.kt @@ -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 } \ No newline at end of file diff --git a/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidXmlHandler.kt b/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidXmlHandler.kt index 8e6ab406e4b..c514f7716fb 100644 --- a/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidXmlHandler.kt +++ b/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidXmlHandler.kt @@ -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) diff --git a/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout.kt b/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout.kt index 0d8202b99df..f0a0fe45c1c 100644 --- a/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout.kt +++ b/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout.kt @@ -12,12 +12,6 @@ val Activity.includeTag: ft val Fragment.includeTag: ft get() = getView().findViewById(0) : View -val Activity.mergeTag: ft - get() = findViewById(0) : View - -val Fragment.mergeTag: ft - get() = getView().findViewById(0) : View - val Activity.fragmentTag: ft get() = findViewById(0) : View diff --git a/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout1.kt b/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout1.kt index bfa76cfeabb..f9efcc0df30 100644 --- a/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout1.kt +++ b/plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/layout1.kt @@ -9,9 +9,6 @@ import kotlin.internal.flexible.ft val View.includeTag: ft get() = findViewById(0) : View -val View.mergeTag: ft - get() = findViewById(0) : View - val View.fragmentTag: ft get() = findViewById(0) : View diff --git a/plugins/android-compiler-plugin/testData/codegen/android/FakeAppwidgetPackage.kt b/plugins/android-compiler-plugin/testData/codegen/android/FakeAppwidgetPackage.kt new file mode 100644 index 00000000000..b150584134e --- /dev/null +++ b/plugins/android-compiler-plugin/testData/codegen/android/FakeAppwidgetPackage.kt @@ -0,0 +1 @@ +package android.appwidget \ No newline at end of file diff --git a/plugins/android-compiler-plugin/testData/codegen/android/FakeInputMethodServicePackage.kt b/plugins/android-compiler-plugin/testData/codegen/android/FakeInputMethodServicePackage.kt new file mode 100644 index 00000000000..74b092db14e --- /dev/null +++ b/plugins/android-compiler-plugin/testData/codegen/android/FakeInputMethodServicePackage.kt @@ -0,0 +1 @@ +package android.inputmethodservice \ No newline at end of file diff --git a/plugins/android-compiler-plugin/testData/codegen/android/FakeOpenglPackage.kt b/plugins/android-compiler-plugin/testData/codegen/android/FakeOpenglPackage.kt new file mode 100644 index 00000000000..2f38c0654d1 --- /dev/null +++ b/plugins/android-compiler-plugin/testData/codegen/android/FakeOpenglPackage.kt @@ -0,0 +1 @@ +package android.opengl \ No newline at end of file diff --git a/plugins/android-compiler-plugin/testData/codegen/android/FakeWebkitPackage.kt b/plugins/android-compiler-plugin/testData/codegen/android/FakeWebkitPackage.kt new file mode 100644 index 00000000000..c25921a9b0e --- /dev/null +++ b/plugins/android-compiler-plugin/testData/codegen/android/FakeWebkitPackage.kt @@ -0,0 +1 @@ +package android.webkit \ No newline at end of file diff --git a/plugins/android-idea-plugin/src/org/jetbrains/kotlin/plugin/android/AndroidXmlVisitor.kt b/plugins/android-idea-plugin/src/org/jetbrains/kotlin/plugin/android/AndroidXmlVisitor.kt index e262e0bcca6..78c0a401f1c 100644 --- a/plugins/android-idea-plugin/src/org/jetbrains/kotlin/plugin/android/AndroidXmlVisitor.kt +++ b/plugins/android-idea-plugin/src/org/jetbrains/kotlin/plugin/android/AndroidXmlVisitor.kt @@ -35,14 +35,17 @@ class AndroidXmlVisitor(val elementCallback: (String, String, XmlAttribute) -> U } override fun visitXmlTag(tag: XmlTag?) { + val localName = tag?.getLocalName() ?: "" + if (isWidgetTypeIgnored(localName)) return + val idAttribute = tag?.getAttribute(AndroidConst.ID_ATTRIBUTE) if (idAttribute != null) { val idAttributeValue = idAttribute.getValue() if (idAttributeValue != null) { val classAttributeValue = tag?.getAttribute(AndroidConst.CLASS_ATTRIBUTE_NO_NAMESPACE)?.getValue() - val xmlType = classAttributeValue ?: tag?.getLocalName() - val widgetType = xmlType?.let { getRealWidgetType(it) } - if (widgetType != null && isResourceDeclarationOrUsage(idAttributeValue)) { + val xmlType = classAttributeValue ?: localName + val widgetType = xmlType.let { getRealWidgetType(it) } + if (isResourceDeclarationOrUsage(idAttributeValue)) { val name = idToName(idAttributeValue) if (name != null) elementCallback(name, widgetType, idAttribute) }