Android Extensions: Correctly handle namespaces in layout xml

#KT-19451 Fixed Target versions 1.1.5
This commit is contained in:
Vyacheslav Gerasimov
2017-08-16 15:38:41 +03:00
parent 1dfa05fe49
commit cb3a8d87d0
5 changed files with 38 additions and 3 deletions
@@ -28,9 +28,8 @@ object AndroidConst {
list
}
val ANDROID_NAMESPACE: String = "android"
val ANDROID_NAMESPACE: String = "http://schemas.android.com/apk/res/android"
val ID_ATTRIBUTE_NO_NAMESPACE: String = "id"
val ID_ATTRIBUTE: String = "$ANDROID_NAMESPACE:$ID_ATTRIBUTE_NO_NAMESPACE"
val CLASS_ATTRIBUTE_NO_NAMESPACE: String = "class"
val IDENTIFIER_REGEX = "^@(\\+)?(([A-Za-z0-9_\\.]+)\\:)?id\\/([A-Za-z0-9_]+)$".toRegex()
@@ -43,7 +43,7 @@ class AndroidXmlVisitor(val elementCallback: (ResourceIdentifier, String, XmlAtt
return
}
val idAttribute = tag?.getAttribute(AndroidConst.ID_ATTRIBUTE)
val idAttribute = tag?.getAttribute(AndroidConst.ID_ATTRIBUTE_NO_NAMESPACE, AndroidConst.ANDROID_NAMESPACE)
if (idAttribute != null) {
val idAttributeValue = idAttribute.value
if (idAttributeValue != null) {
@@ -52,6 +52,7 @@ class AndroidXmlVisitor(val elementCallback: (ResourceIdentifier, String, XmlAtt
if (name != null) elementCallback(name, xmlType, idAttribute)
}
}
tag?.acceptChildren(this)
}
}
@@ -0,0 +1,12 @@
package com.myapp
import android.app.Activity
import android.os.Bundle
import java.io.File
import kotlinx.android.synthetic.main.layout.*
public class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {}
val button = login<caret>
}
@@ -0,0 +1,17 @@
<FrameLayout xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
a:id="@+id/item_detail_container"
a:layout_width="match_parent"
a:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<Button
a:id="@+id/login"
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:text="Sign in" />
</FrameLayout>
@@ -36,6 +36,12 @@ public class AndroidGotoTestGenerated extends AbstractAndroidGotoTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/android-extensions/android-extensions-idea/testData/android/goto"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, false);
}
@TestMetadata("customNamespaceName")
public void testCustomNamespaceName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-idea/testData/android/goto/customNamespaceName/");
doTest(fileName);
}
@TestMetadata("fqNameInAttr")
public void testFqNameInAttr() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-idea/testData/android/goto/fqNameInAttr/");