Android Extensions: Use smart pointers in 'AndroidResource'
This commit is contained in:
+5
-3
@@ -27,6 +27,7 @@ import com.intellij.psi.PsiManager
|
|||||||
import org.jetbrains.kotlin.android.synthetic.AndroidConst
|
import org.jetbrains.kotlin.android.synthetic.AndroidConst
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class AndroidVariantData(val variant: AndroidVariant, val layouts: Map<String, List<PsiFile>>)
|
class AndroidVariantData(val variant: AndroidVariant, val layouts: Map<String, List<PsiFile>>)
|
||||||
@@ -93,10 +94,11 @@ abstract class AndroidLayoutXmlFileManager(val project: Project) {
|
|||||||
protected abstract fun doExtractResources(layoutGroup: AndroidLayoutGroupData, module: ModuleDescriptor): AndroidLayoutGroup
|
protected abstract fun doExtractResources(layoutGroup: AndroidLayoutGroupData, module: ModuleDescriptor): AndroidLayoutGroup
|
||||||
|
|
||||||
protected fun parseAndroidResource(id: ResourceIdentifier, tag: String, sourceElement: PsiElement?): AndroidResource {
|
protected fun parseAndroidResource(id: ResourceIdentifier, tag: String, sourceElement: PsiElement?): AndroidResource {
|
||||||
|
val sourceElementPointer = sourceElement?.createSmartPointer()
|
||||||
return when (tag) {
|
return when (tag) {
|
||||||
"fragment" -> AndroidResource.Fragment(id, sourceElement)
|
"fragment" -> AndroidResource.Fragment(id, sourceElementPointer)
|
||||||
"include" -> AndroidResource.Widget(id, AndroidConst.VIEW_FQNAME, sourceElement)
|
"include" -> AndroidResource.Widget(id, AndroidConst.VIEW_FQNAME, sourceElementPointer)
|
||||||
else -> AndroidResource.Widget(id, tag, sourceElement)
|
else -> AndroidResource.Widget(id, tag, sourceElementPointer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-3
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.android.synthetic.res
|
|||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.SmartPsiElementPointer
|
||||||
import com.intellij.psi.util.CachedValue
|
import com.intellij.psi.util.CachedValue
|
||||||
import com.intellij.psi.util.CachedValueProvider
|
import com.intellij.psi.util.CachedValueProvider
|
||||||
import com.intellij.psi.util.CachedValuesManager
|
import com.intellij.psi.util.CachedValuesManager
|
||||||
@@ -65,14 +66,18 @@ class AndroidLayoutGroup(val name: String, val layouts: List<AndroidLayout>)
|
|||||||
|
|
||||||
class AndroidLayout(val resources: List<AndroidResource>)
|
class AndroidLayout(val resources: List<AndroidResource>)
|
||||||
|
|
||||||
sealed class AndroidResource(val id: ResourceIdentifier, val sourceElement: PsiElement?, val partiallyDefined: Boolean) {
|
sealed class AndroidResource(
|
||||||
|
val id: ResourceIdentifier,
|
||||||
|
val sourceElement: SmartPsiElementPointer<PsiElement>?,
|
||||||
|
val partiallyDefined: Boolean
|
||||||
|
) {
|
||||||
open fun sameClass(other: AndroidResource): Boolean = false
|
open fun sameClass(other: AndroidResource): Boolean = false
|
||||||
open fun partiallyDefined(): AndroidResource = this
|
open fun partiallyDefined(): AndroidResource = this
|
||||||
|
|
||||||
class Widget(
|
class Widget(
|
||||||
id: ResourceIdentifier,
|
id: ResourceIdentifier,
|
||||||
val xmlType: String,
|
val xmlType: String,
|
||||||
sourceElement: PsiElement?,
|
sourceElement: SmartPsiElementPointer<PsiElement>?,
|
||||||
partiallyDefined: Boolean = false
|
partiallyDefined: Boolean = false
|
||||||
) : AndroidResource(id, sourceElement, partiallyDefined) {
|
) : AndroidResource(id, sourceElement, partiallyDefined) {
|
||||||
override fun sameClass(other: AndroidResource) = other is Widget
|
override fun sameClass(other: AndroidResource) = other is Widget
|
||||||
@@ -81,7 +86,7 @@ sealed class AndroidResource(val id: ResourceIdentifier, val sourceElement: PsiE
|
|||||||
|
|
||||||
class Fragment(
|
class Fragment(
|
||||||
id: ResourceIdentifier,
|
id: ResourceIdentifier,
|
||||||
sourceElement: PsiElement?,
|
sourceElement: SmartPsiElementPointer<PsiElement>?,
|
||||||
partiallyDefined: Boolean = false
|
partiallyDefined: Boolean = false
|
||||||
) : AndroidResource(id, sourceElement, partiallyDefined) {
|
) : AndroidResource(id, sourceElement, partiallyDefined) {
|
||||||
override fun sameClass(other: AndroidResource) = other is Fragment
|
override fun sameClass(other: AndroidResource) = other is Fragment
|
||||||
|
|||||||
+2
-2
@@ -59,7 +59,7 @@ internal fun genPropertyForWidget(
|
|||||||
resolvedWidget: ResolvedWidget,
|
resolvedWidget: ResolvedWidget,
|
||||||
context: SyntheticElementResolveContext
|
context: SyntheticElementResolveContext
|
||||||
): PropertyDescriptor {
|
): PropertyDescriptor {
|
||||||
val sourceEl = resolvedWidget.widget.sourceElement?.let(::XmlSourceElement) ?: SourceElement.NO_SOURCE
|
val sourceEl = resolvedWidget.widget.sourceElement?.element?.let(::XmlSourceElement) ?: SourceElement.NO_SOURCE
|
||||||
|
|
||||||
val classDescriptor = resolvedWidget.viewClassDescriptor
|
val classDescriptor = resolvedWidget.viewClassDescriptor
|
||||||
val type = classDescriptor?.let {
|
val type = classDescriptor?.let {
|
||||||
@@ -83,7 +83,7 @@ internal fun genPropertyForFragment(
|
|||||||
type: SimpleType,
|
type: SimpleType,
|
||||||
fragment: AndroidResource.Fragment
|
fragment: AndroidResource.Fragment
|
||||||
): PropertyDescriptor {
|
): PropertyDescriptor {
|
||||||
val sourceElement = fragment.sourceElement?.let(::XmlSourceElement) ?: SourceElement.NO_SOURCE
|
val sourceElement = fragment.sourceElement?.element?.let(::XmlSourceElement) ?: SourceElement.NO_SOURCE
|
||||||
return genProperty(fragment, receiverType, type, packageFragmentDescriptor, sourceElement, null)
|
return genProperty(fragment, receiverType, type, packageFragmentDescriptor, sourceElement, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user