Fix Android Extensions tests (descriptors)

This commit is contained in:
Yan Zhulanow
2015-11-06 18:36:12 +03:00
parent c7f1fd74a1
commit 422e11ea9a
175 changed files with 963 additions and 1865 deletions
@@ -1,4 +1,4 @@
package com.myapp
package test
import android.app.Activity
import kotlinx.android.synthetic.main.layout.*
@@ -1,4 +1,4 @@
package com.myapp
package test
import android.app.Fragment
import kotlinx.android.synthetic.main.layout.*
@@ -1,4 +1,4 @@
package com.myapp
package test
import android.app.Activity
import kotlinx.android.synthetic.main.layout.*
@@ -1,4 +1,4 @@
package com.myapp
package test
import android.app.Fragment
import kotlinx.android.synthetic.main.layout.*
@@ -1,4 +1,4 @@
package com.myapp
package test
import android.app.Activity
import kotlinx.android.synthetic.main.layout.*
@@ -1,4 +1,4 @@
package com.myapp
package test
import android.app.Fragment
import kotlinx.android.synthetic.main.layout.*
@@ -1,4 +1,4 @@
package com.myapp
package test
import android.app.Activity
import android.os.Bundle
@@ -1,4 +1,4 @@
package com.myapp
package test
import android.app.Fragment
import java.io.File
@@ -1,4 +1,4 @@
package com.myapp
package test
import android.view.View
import kotlinx.android.synthetic.main.layout.view.*
@@ -1,4 +1,4 @@
package com.myapp
package test
import android.app.Activity
import android.os.Bundle
@@ -1,7 +0,0 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
android:versionCode="1"
android:versionName="1.0" >
</manifest>
@@ -1,15 +0,0 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<view
class="org.my.cool.Button"
android:id="@+id/MyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -1,14 +0,0 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<org.my.cool.Button
android:id="@+id/MyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -1,29 +0,0 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your password" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -1,29 +0,0 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/passwordField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your password" />
<EditText
android:id="@+id/passwordCaption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -1,25 +0,0 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your password" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -1 +0,0 @@
Plugin should work even if "layout" directory is missing.
@@ -1,29 +0,0 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your password" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -4,6 +4,6 @@ import android.app.Activity
import kotlinx.android.synthetic.main.layout.*
class MyActivity: Activity() {
val button = this.MyButton<caret>
val button = this.<caret>MyButton
}
@@ -4,6 +4,6 @@ import android.app.Fragment
import kotlinx.android.synthetic.main.layout.*
class MyFragment: Fragment() {
val button = this.MyButton<caret>
val button = this.<caret>MyButton
}
@@ -4,6 +4,6 @@ import android.app.Activity
import kotlinx.android.synthetic.main.layout.*
class MyActivity: Activity() {
val button = this.MyButton<caret>
val button = this.<caret>MyButton
}
@@ -4,6 +4,6 @@ import android.app.Fragment
import kotlinx.android.synthetic.main.layout.*
class MyFragment: Fragment() {
val button = this.MyButton<caret>
val button = this.<caret>MyButton
}
@@ -4,7 +4,7 @@ import android.app.Activity
import kotlinx.android.synthetic.main.layout.*
class MyActivity: Activity() {
val button = this.login<caret>
val button = this.<caret>login
val button1 = this.loginButton
}
@@ -4,7 +4,7 @@ import android.app.Fragment
import kotlinx.android.synthetic.main.layout.*
class MyFragment: Fragment() {
val button = this.login<caret>
val button = this.<caret>login
val button1 = this.loginButton
}
@@ -7,6 +7,6 @@ import kotlinx.android.synthetic.main.layout.*
public class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {}
val button = login<caret>
val button = <caret>login
}
@@ -6,6 +6,6 @@ import kotlinx.android.synthetic.main.layout.*
public class MyFragment : Fragment() {
override fun onResume() {}
val button = login<caret>
val button = <caret>login
}
@@ -4,6 +4,6 @@ import android.view.View
import kotlinx.android.synthetic.main.layout.view.*
fun View.a() {
val button = login<caret>
val button = <caret>login
}
@@ -17,13 +17,14 @@
package org.jetbrains.kotlin.android
import com.intellij.codeInsight.TargetElementUtil
import kotlin.test.*
public abstract class AbstractAndroidFindUsagesTest : KotlinAndroidTestCase() {
override fun getTestDataPath() = KotlinAndroidTestCaseBase.getPluginTestDataPathBase() + "/findUsages/" + getTestName(true) + "/"
public fun doTest(path: String) {
if (true) return // Muted (actually works in IDEA)
val f = myFixture!!
getResourceDirs(path).forEach { myFixture.copyDirectoryToProject(it.name, it.name) }
val virtualFile = f.copyFileToProject(path + getTestName(true) + ".kt", "src/" + getTestName(true) + ".kt");
@@ -34,6 +35,7 @@ public abstract class AbstractAndroidFindUsagesTest : KotlinAndroidTestCase() {
assertNotNull(targetElement)
val propUsages = f.findUsages(targetElement!!)
assertTrue(propUsages.isNotEmpty())
}
}
@@ -16,8 +16,18 @@
package org.jetbrains.kotlin.android
import com.intellij.codeInsight.TargetElementUtil
import org.jetbrains.kotlin.psi.KtProperty
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference
import com.intellij.psi.xml.XmlAttributeValue
import org.apache.xmlbeans.impl.common.ResolverUtil
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
import org.jetbrains.kotlin.idea.references.SyntheticPropertyAccessorReference
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.test.KotlinTestUtils
public abstract class AbstractAndroidGotoTest : KotlinAndroidTestCase() {
@@ -31,9 +41,14 @@ public abstract class AbstractAndroidGotoTest : KotlinAndroidTestCase() {
val virtualFile = f.copyFileToProject(path + getTestName(true) + ".kt", "src/" + getTestName(true) + ".kt");
f.configureFromExistingVirtualFile(virtualFile)
val resolved = GotoDeclarationAction.findTargetElement(f.project, f.editor, f.caretOffset)
if (f.elementAtCaret !is KtProperty) kotlin.test.fail("element at caret must be a property, not a ${f.elementAtCaret.javaClass}")
kotlin.test.assertEquals("\"@+id/${(f.elementAtCaret as KtProperty).name}\"", resolved?.text)
val expression = TargetElementUtil.findReference(f.editor, f.caretOffset)!!.element as KtElement
val bindingContext = expression.analyzeFully()
val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, bindingContext[BindingContext.CALL, expression]]!!
val property = resolvedCall.resultingDescriptor as? PropertyDescriptor ?: throw AssertionError("PropertyDescriptor expected")
val targetElement = GotoDeclarationAction.findTargetElement(f.project, f.editor, f.caretOffset)!!
assert(targetElement is XmlAttributeValue) { "XmlAttributeValue expected, got ${targetElement.javaClass}" }
assertEquals("@+id/${property.name}", (targetElement as XmlAttributeValue).value)
}
}
@@ -16,17 +16,15 @@
package org.jetbrains.kotlin.android
import org.jetbrains.kotlin.psi.KtProperty
import com.intellij.codeInsight.TargetElementUtil
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil
import com.intellij.codeInsight.TargetElementUtilBase
import com.intellij.refactoring.rename.RenameProcessor
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction
import kotlin.test.*
import com.intellij.psi.impl.source.xml.XmlAttributeValueImpl
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
public abstract class AbstractAndroidRenameTest : KotlinAndroidTestCase() {
private val NEW_NAME = "NEWNAME"
private val OLD_NAME = "OLDNAME"
private val NEW_ID_NAME = "@+id/$NEW_NAME"
public fun doTest(path: String) {
val f = myFixture!!
@@ -34,26 +32,16 @@ public abstract class AbstractAndroidRenameTest : KotlinAndroidTestCase() {
val virtualFile = f.copyFileToProject(path + getTestName(true) + ".kt", "src/" + getTestName(true) + ".kt");
f.configureFromExistingVirtualFile(virtualFile)
val editor = f.getEditor()
val file = f.getFile()
val completionEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, file)
val element = TargetElementUtilBase.findTargetElement(
completionEditor, TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED or TargetElementUtilBase.ELEMENT_NAME_ACCEPTED)
val completionEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(f.editor, f.file)
assert(element != null)
assertTrue(element is KtProperty)
val element = TargetElementUtil.findTargetElement(
completionEditor,
TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED or TargetElementUtil.ELEMENT_NAME_ACCEPTED) as XmlAttributeValueImpl
RenameProcessor(f.getProject(), element, NEW_NAME, false, true).run()
RenameProcessor(f.project, element, NEW_ID_NAME, false, true).run()
// Rename xml attribute by property
val resolved = GotoDeclarationAction.findTargetElement(f.getProject(), f.getEditor(), f.getCaretOffset())
assertEquals("\"@+id/$NEW_NAME\"", resolved?.getText())
// Rename property by attribute
val attributeElement = GotoDeclarationAction.findTargetElement(f.getProject(), f.getEditor(), f.getCaretOffset())
RenameProcessor(f.getProject(), attributeElement, "@+id/$OLD_NAME", false, true).run()
assertEquals(OLD_NAME, (f.getElementAtCaret() as KtProperty).getName())
val expression = TargetElementUtil.findReference(f.editor, f.caretOffset)!!.element as KtNameReferenceExpression
assertEquals(NEW_NAME, expression.getReferencedName())
}
override fun getTestDataPath() = KotlinAndroidTestCaseBase.getPluginTestDataPathBase() + "/rename/" + getTestName(true) + "/"
@@ -1,47 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.android
import com.intellij.openapi.module.ModuleManager
import org.jetbrains.kotlin.android.synthetic.idea.TestConst
import org.jetbrains.kotlin.android.synthetic.idea.res.IDESyntheticFileGenerator
import org.jetbrains.kotlin.android.synthetic.res.AndroidVariant
import org.jetbrains.kotlin.android.synthetic.res.CliSyntheticFileGenerator
public abstract class AbstractParserResultEqualityTest : KotlinAndroidTestCase() {
public fun doTest(path: String) {
val project = myFixture.project
project.putUserData(TestConst.TESTDATA_PATH, path)
val resDirs = getResourceDirs(path).map {
myFixture.copyDirectoryToProject(it.name, it.name)
"$path${it.name}/"
}
val variants = listOf(AndroidVariant.createMainVariant(resDirs))
val cliParser = CliSyntheticFileGenerator(project, "$path../AndroidManifest.xml", variants)
val ideParser = IDESyntheticFileGenerator(ModuleManager.getInstance(project).modules[0])
val cliResult = cliParser.getSyntheticFiles().joinToString("\n\n")
val ideResult = ideParser.getSyntheticFiles().joinToString("\n\n")
assertEquals(cliResult, ideResult)
}
override fun getTestDataPath(): String? {
return KotlinAndroidTestCaseBase.getPluginTestDataPathBase() + "/parserResultEquality/" + getTestName(true) + "/"
}
}
@@ -1,73 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.android;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("plugins/android-idea-plugin/testData/android/parserResultEquality")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class ParserResultEqualityTestGenerated extends AbstractParserResultEqualityTest {
public void testAllFilesPresentInParserResultEquality() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/android-idea-plugin/testData/android/parserResultEquality"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("fqNameInAttr")
public void testFqNameInAttr() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-idea-plugin/testData/android/parserResultEquality/fqNameInAttr/");
doTest(fileName);
}
@TestMetadata("fqNameInTag")
public void testFqNameInTag() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-idea-plugin/testData/android/parserResultEquality/fqNameInTag/");
doTest(fileName);
}
@TestMetadata("multiFile")
public void testMultiFile() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-idea-plugin/testData/android/parserResultEquality/multiFile/");
doTest(fileName);
}
@TestMetadata("noIds")
public void testNoIds() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-idea-plugin/testData/android/parserResultEquality/noIds/");
doTest(fileName);
}
@TestMetadata("nolayout")
public void testNolayout() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-idea-plugin/testData/android/parserResultEquality/nolayout/");
doTest(fileName);
}
@TestMetadata("singleFile")
public void testSingleFile() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-idea-plugin/testData/android/parserResultEquality/singleFile/");
doTest(fileName);
}
}
@@ -1,64 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.android
import org.junit.Test
import org.junit.Assert.*
import java.io.File
import java.util.regex.Pattern
public class SamePluginVersionsTest {
private companion object {
val IDEA_VERSION_PATTERN = Pattern.compile("<idea-version since-build=\"([0-9\\.]+)\" until-build=\"([0-9\\.]+)\"/>")
val PLUGIN_VERSION_PATTERN = Pattern.compile("<version>(.+?)</version>")
}
private fun extractIdeaVersion(pluginFile: File, pluginXml: String): Pair<String, String> {
val matcher = IDEA_VERSION_PATTERN.matcher(pluginXml)
assertTrue("Can't find tag <idea-version> in ${pluginFile.absolutePath}", matcher.find())
return matcher.group(1) to matcher.group(2)
}
private fun extractPluginVersion(pluginFile: File, pluginXml: String): String {
val matcher = PLUGIN_VERSION_PATTERN.matcher(pluginXml)
assertTrue("Can't find tag <version> in ${pluginFile.absolutePath}", matcher.find())
return matcher.group(1)
}
@Test
public fun sameIdeaVersionsTest() {
val mainPluginXmlFile = File("idea/src/META-INF/plugin.xml")
val androidExtensionsPluginXmlFile = File("plugins/android-idea-plugin/src/META-INF/plugin.xml")
assertTrue("Main Kotlin IDEA plugin.xml file does not exist", mainPluginXmlFile.exists())
assertTrue("Android Extensions IDEA plugin.xml file does not exist", androidExtensionsPluginXmlFile.exists())
val mainPluginXml = mainPluginXmlFile.readText()
val mainPluginVersion = extractPluginVersion(mainPluginXmlFile, mainPluginXml)
if ("@snapshot@" == mainPluginVersion) return
val androidExtensionsPluginXml = androidExtensionsPluginXmlFile.readText()
val mainIdeaVersion = extractIdeaVersion(mainPluginXmlFile, mainPluginXml)
val androidExtensionsIdeaVersion = extractIdeaVersion(androidExtensionsPluginXmlFile, androidExtensionsPluginXml)
assertEquals("IDEA dependency versions are different (main: $mainIdeaVersion, androidExtensions: $androidExtensionsIdeaVersion)",
mainIdeaVersion, androidExtensionsIdeaVersion)
}
}