Cleanup Android Extensions code
This commit is contained in:
+4
-4
@@ -33,16 +33,16 @@ import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
public class AndroidGotoDeclarationHandler : GotoDeclarationHandler {
|
||||
|
||||
override fun getGotoDeclarationTargets(sourceElement: PsiElement?, offset: Int, editor: Editor?): Array<PsiElement>? {
|
||||
if (sourceElement is LeafPsiElement && sourceElement.getParent() is KtSimpleNameExpression) {
|
||||
val resolved = KtSimpleNameReference(sourceElement.getParent() as KtSimpleNameExpression).resolve()
|
||||
if (sourceElement is LeafPsiElement && sourceElement.parent is KtSimpleNameExpression) {
|
||||
val resolved = KtSimpleNameReference(sourceElement.parent as KtSimpleNameExpression).resolve()
|
||||
val property = resolved as? KtProperty ?: return null
|
||||
|
||||
val moduleInfo = sourceElement.getModuleInfo()
|
||||
if (moduleInfo !is ModuleSourceInfo) return null
|
||||
|
||||
val parser = ModuleServiceManager.getService(moduleInfo.module, javaClass<SyntheticFileGenerator>())!!
|
||||
val parser = ModuleServiceManager.getService(moduleInfo.module, SyntheticFileGenerator::class.java)!!
|
||||
val psiElements = parser.layoutXmlFileManager.propertyToXmlAttributes(property)
|
||||
val valueElements = psiElements.map { (it as? XmlAttribute)?.getValueElement() as? PsiElement }.filterNotNull()
|
||||
val valueElements = psiElements.map { (it as? XmlAttribute)?.valueElement as? PsiElement }.filterNotNull()
|
||||
if (valueElements.isNotEmpty()) return valueElements.toTypedArray()
|
||||
}
|
||||
return null
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ public class AndroidPsiTreeChangePreprocessor : PsiTreeChangePreprocessor, Simpl
|
||||
val module = projectFileIndex.getModuleForFile(xmlFile.virtualFile)
|
||||
|
||||
if (module != null) {
|
||||
val resourceManager = AndroidLayoutXmlFileManager.getInstance(module)
|
||||
val resourceManager = AndroidLayoutXmlFileManager.getInstance(module) ?: return false
|
||||
val resDirectories = resourceManager.getModuleResDirectories()
|
||||
val baseDirectory = xmlFile.parent?.parent?.virtualFile
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class IDEAndroidExternalDeclarationsProvider(private val project: Project
|
||||
if (moduleInfo !is ModuleSourceInfo) return listOf()
|
||||
|
||||
val module = moduleInfo.module
|
||||
val parser = ModuleServiceManager.getService(module, javaClass<SyntheticFileGenerator>()) as? IDESyntheticFileGenerator
|
||||
val parser = ModuleServiceManager.getService(module, SyntheticFileGenerator::class.java) as? IDESyntheticFileGenerator
|
||||
val syntheticFiles = parser?.getSyntheticFiles()
|
||||
syntheticFiles?.forEach { it.moduleInfo = moduleInfo }
|
||||
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class IDEAndroidLayoutXmlFileManager(val module: Module) : AndroidLayoutX
|
||||
override val androidModuleInfo: AndroidModuleInfo? by lazy { module.androidFacet?.toAndroidModuleInfo() }
|
||||
|
||||
override fun propertyToXmlAttributes(property: KtProperty): List<PsiElement> {
|
||||
val fqPath = property.getFqName()?.pathSegments() ?: return listOf()
|
||||
val fqPath = property.fqName?.pathSegments() ?: return listOf()
|
||||
if (fqPath.size() <= AndroidConst.SYNTHETIC_PACKAGE_PATH_LENGTH) return listOf()
|
||||
|
||||
val layoutPackageName = fqPath[AndroidConst.SYNTHETIC_PACKAGE_PATH_LENGTH].asString()
|
||||
|
||||
+1
-1
@@ -61,6 +61,6 @@ public abstract class AbstractAndroidCompletionTest : KotlinAndroidTestCase() {
|
||||
settings.AUTOCOMPLETE_ON_CODE_COMPLETION = codeCompletionOldValue
|
||||
settings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = smartTypeCompletionOldValue
|
||||
|
||||
super<KotlinAndroidTestCase>.tearDown()
|
||||
super.tearDown()
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.android
|
||||
|
||||
import com.intellij.codeInsight.TargetElementUtilBase
|
||||
import com.intellij.codeInsight.TargetElementUtil
|
||||
import kotlin.test.*
|
||||
|
||||
public abstract class AbstractAndroidFindUsagesTest : KotlinAndroidTestCase() {
|
||||
@@ -29,8 +29,8 @@ public abstract class AbstractAndroidFindUsagesTest : KotlinAndroidTestCase() {
|
||||
val virtualFile = f.copyFileToProject(path + getTestName(true) + ".kt", "src/" + getTestName(true) + ".kt");
|
||||
f.configureFromExistingVirtualFile(virtualFile)
|
||||
|
||||
val targetElement = TargetElementUtilBase.findTargetElement(
|
||||
f.getEditor(), TargetElementUtilBase.ELEMENT_NAME_ACCEPTED or TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED)
|
||||
val targetElement = TargetElementUtil.findTargetElement(
|
||||
f.editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED or TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED)
|
||||
assertNotNull(targetElement)
|
||||
|
||||
val propUsages = f.findUsages(targetElement!!)
|
||||
|
||||
+3
-3
@@ -31,9 +31,9 @@ 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.getProject(), f.getEditor(), f.getCaretOffset())
|
||||
if (f.getElementAtCaret() !is KtProperty) kotlin.test.fail("element at caret must be a property, not a ${f.getElementAtCaret().javaClass}")
|
||||
kotlin.test.assertEquals("\"@+id/${(f.getElementAtCaret() as KtProperty).getName()}\"", resolved?.getText())
|
||||
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)
|
||||
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -30,13 +30,13 @@ public class SamePluginVersionsTest {
|
||||
|
||||
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.getAbsolutePath()}", matcher.find())
|
||||
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.getAbsolutePath()}", matcher.find())
|
||||
assertTrue("Can't find tag <version> in ${pluginFile.absolutePath}", matcher.find())
|
||||
return matcher.group(1)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user