fix android cross parser tests
- reorganize tests folder structure - fix class attribute ignored in ide xml parser
This commit is contained in:
committed by
Yan Zhulanow
parent
84d326ed47
commit
bc9e1ee2d2
+4
-4
@@ -31,10 +31,10 @@ class AndroidXmlHandler(private val resourceManager: AndroidResourceManager, pri
|
||||
}
|
||||
|
||||
override fun startElement(uri: String, localName: String, qName: String, attributes: Attributes) {
|
||||
val hashMap = attributes.toMap()
|
||||
val s = hashMap[resourceManager.idAttributeNoNamespace]
|
||||
val className = hashMap[resourceManager.classAttributeNoNamespace] ?: localName
|
||||
if (resourceManager.isResourceDeclarationOrUsage(s)) elementCallback(resourceManager.idToName(s), className)
|
||||
val attributesMap = attributes.toMap()
|
||||
val idAttr = attributesMap[resourceManager.idAttributeNoNamespace]
|
||||
val classNameAttr = attributesMap[resourceManager.classAttributeNoNamespace] ?: localName
|
||||
if (resourceManager.isResourceDeclarationOrUsage(idAttr)) elementCallback(resourceManager.idToName(idAttr), classNameAttr)
|
||||
}
|
||||
|
||||
override fun endElement(uri: String?, localName: String, qName: String) {
|
||||
|
||||
@@ -36,7 +36,8 @@ class AndroidXmlVisitor(val resourceManager: AndroidResourceManager, val element
|
||||
override fun visitXmlTag(tag: XmlTag?) {
|
||||
val attribute = tag?.getAttribute(resourceManager.idAttribute)
|
||||
if (attribute != null && attribute.getValue() != null) {
|
||||
elementCallback(resourceManager.idToName(attribute.getValue()), tag!!.getLocalName(), attribute)
|
||||
val classNameAttr = tag?.getAttribute(resourceManager.classAttributeNoNamespace)?.getValue() ?: tag?.getLocalName()
|
||||
elementCallback(resourceManager.idToName(attribute.getValue()), classNameAttr!!, attribute)
|
||||
}
|
||||
tag?.acceptChildren(this)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.myapp"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
|
||||
</manifest>
|
||||
@@ -1,33 +0,0 @@
|
||||
<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>
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.myapp
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
|
||||
val Activity.MyButton: org.my.cool.Button
|
||||
get() = findViewById(0) as org.my.cool.Button
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<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>
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.myapp
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
|
||||
val Activity.MyButton: org.my.cool.Button
|
||||
get() = findViewById(0) as org.my.cool.Button
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<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>
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.myapp
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
|
||||
val Activity.item_detail_container: FrameLayout
|
||||
get() = findViewById(0) as FrameLayout
|
||||
|
||||
val Activity.textView1: TextView
|
||||
get() = findViewById(0) as TextView
|
||||
|
||||
val Activity.password: EditText
|
||||
get() = findViewById(0) as EditText
|
||||
|
||||
val Activity.login: Button
|
||||
get() = findViewById(0) as Button
|
||||
|
||||
val Activity.frameLayout: FrameLayout
|
||||
get() = findViewById(0) as FrameLayout
|
||||
|
||||
val Activity.passwordField: TextView
|
||||
get() = findViewById(0) as TextView
|
||||
|
||||
val Activity.passwordCaption: EditText
|
||||
get() = findViewById(0) as EditText
|
||||
|
||||
val Activity.loginButton: Button
|
||||
get() = findViewById(0) as Button
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<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>
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.myapp
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<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>
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.myapp
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
|
||||
class MyActivity(): Activity() {
|
||||
val textViewWidget = TextView()
|
||||
val editTextWidget = EditText()
|
||||
val buttonWidget = Button()
|
||||
|
||||
override fun findViewById(id: Int): View? {
|
||||
return when (id) {
|
||||
R.id.textView1 -> textViewWidget
|
||||
R.id.password -> editTextWidget
|
||||
R.id.login -> buttonWidget
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun test(): String {
|
||||
return if (password.toString() == "EditText" &&
|
||||
textView1.toString() == "TextView" &&
|
||||
login.toString() == "Button" )
|
||||
"OK" else "NOTOK"
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.myapp
|
||||
|
||||
class R {
|
||||
class id {
|
||||
class object {
|
||||
val item_detail_container = 0
|
||||
val textView1 = 1
|
||||
val password = 2
|
||||
val textView2 = 3
|
||||
val passwordConfirmation = 4
|
||||
val login = 5
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.myapp
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
|
||||
val Activity.item_detail_container: FrameLayout
|
||||
get() = findViewById(0) as FrameLayout
|
||||
|
||||
val Activity.textView1: TextView
|
||||
get() = findViewById(0) as TextView
|
||||
|
||||
val Activity.password: EditText
|
||||
get() = findViewById(0) as EditText
|
||||
|
||||
val Activity.login: Button
|
||||
get() = findViewById(0) as Button
|
||||
|
||||
@@ -36,13 +36,15 @@ import com.intellij.ide.startup.impl.StartupManagerImpl
|
||||
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
|
||||
import org.jetbrains.jet.JetTestCaseBuilder
|
||||
import com.intellij.openapi.startup.StartupManager
|
||||
import com.android.SdkConstants
|
||||
import com.intellij.openapi.application.PathManager
|
||||
|
||||
public abstract class AbstractCrossParserTest : LightCodeInsightFixtureTestCase() {
|
||||
public abstract class AbstractCrossParserTest : KotlinAndroidTestCase() {
|
||||
public fun doTest(path: String) {
|
||||
val project = myFixture.getProject()
|
||||
val project = myFixture!!.getProject()
|
||||
project.putUserData(TestConst.TESTDATA_PATH, path)
|
||||
myFixture.copyDirectoryToProject(getTestName(true), "")
|
||||
val cliParser = CliAndroidUIXmlProcessor(project, path + "/layout", path + "AndroidManifest.xml")
|
||||
myFixture!!.copyDirectoryToProject(getResDir()!!, "res")
|
||||
val cliParser = CliAndroidUIXmlProcessor(project, path + getResDir() + "/layout/", path + "../AndroidManifest.xml")
|
||||
val ideParser = IDEAndroidUIXmlProcessor(project)
|
||||
|
||||
val cliResult = cliParser.parseToPsi(project)!!.getText()
|
||||
@@ -51,10 +53,9 @@ public abstract class AbstractCrossParserTest : LightCodeInsightFixtureTestCase(
|
||||
assertEquals(cliResult, ideResult)
|
||||
}
|
||||
override fun setUp() {
|
||||
System.setProperty(KotlinAndroidTestCaseBase.SDK_PATH_PROPERTY, PathManager.getHomePath() + "/androidSDK/")
|
||||
System.setProperty(KotlinAndroidTestCaseBase.PLATFORM_DIR_PROPERTY, "android-17")
|
||||
super.setUp()
|
||||
myFixture.setTestDataPath(PluginTestCaseBase.getTestDataPathBase() + "/android/crossParser")
|
||||
(StartupManager.getInstance(getProject()) as StartupManagerImpl).runPostStartupActivities()
|
||||
VfsRootAccess.allowRootAccess(JetTestCaseBuilder.getHomeDirectory())
|
||||
}
|
||||
|
||||
private fun getEnvironment(testPath: String): JetCoreEnvironment {
|
||||
@@ -63,7 +64,14 @@ public abstract class AbstractCrossParserTest : LightCodeInsightFixtureTestCase(
|
||||
configuration.put<String>(JVMConfigurationKeys.ANDROID_MANIFEST, testPath + "/AndroidManifest.xml")
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration)
|
||||
}
|
||||
|
||||
override fun getTestDataPath(): String? {
|
||||
return PluginTestCaseBase.getTestDataPathBase() + "/android/crossParser/"
|
||||
return PluginTestCaseBase.getTestDataPathBase() + "/android/crossParser/" + getTestName(true) + "/"
|
||||
}
|
||||
|
||||
override fun createManifest() {
|
||||
myFixture!!.copyFileToProject("idea/testData/android/AndroidManifest.xml", SdkConstants.FN_ANDROID_MANIFEST_XML)
|
||||
}
|
||||
|
||||
override fun requireRecentSdk() = true
|
||||
}
|
||||
@@ -114,7 +114,6 @@ public abstract class KotlinAndroidTestCase extends KotlinAndroidTestCaseBase {
|
||||
createManifest();
|
||||
|
||||
myFacet = addAndroidFacet(myModule, sdkPath, getPlatformDir(), isToAddSdk());
|
||||
myFixture.copyDirectoryToProject(getResDir(), "res");
|
||||
|
||||
myAdditionalModules = new ArrayList<Module>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user