mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactor python: replace utility helpers with kotlin equivalents in PyTypingTypeProvider
(cherry picked from commit a1d8d52a6bd5bdbcecd8698b7bed96260b11b3f0) GitOrigin-RevId: c52d3c037743383fa9e5faabec3733695a78544d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
cc77134fc9
commit
c733d1898f
+10
-17
@@ -22,9 +22,7 @@ import com.intellij.psi.util.CachedValuesManager
|
||||
import com.intellij.psi.util.PsiModificationTracker
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.util.QualifiedName
|
||||
import com.intellij.util.ArrayUtil
|
||||
import com.intellij.util.Function
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.containers.Stack
|
||||
import com.jetbrains.python.PyCustomType
|
||||
import com.jetbrains.python.PyNames
|
||||
@@ -1536,8 +1534,7 @@ class PyTypingTypeProvider : PyTypeProviderWithCustomContext<Context?>() {
|
||||
val containingClass = typeHintContext as? PyClass ?: PsiTreeUtil.getStubOrPsiParentOfType(typeHintContext, PyClass::class.java)
|
||||
if (containingClass == null) return null
|
||||
|
||||
val scopeClassType = PyUtil.`as`(containingClass.getType(context.typeContext), PyClassType::class.java)
|
||||
if (scopeClassType == null) return null
|
||||
val scopeClassType = containingClass.getType(context.typeContext) as? PyClassType ?: return null
|
||||
|
||||
return Ref(PySelfType(scopeClassType).toInstance())
|
||||
}
|
||||
@@ -2258,7 +2255,7 @@ class PyTypingTypeProvider : PyTypeProviderWithCustomContext<Context?>() {
|
||||
Ref()
|
||||
}
|
||||
|
||||
val declarationElement = PyUtil.`as`(element, PyQualifiedNameOwner::class.java)
|
||||
val declarationElement = element as? PyQualifiedNameOwner
|
||||
|
||||
when (element.kind) {
|
||||
PyAstTypeParameter.Kind.TypeVar -> {
|
||||
@@ -2758,7 +2755,7 @@ class PyTypingTypeProvider : PyTypeProviderWithCustomContext<Context?>() {
|
||||
context: TypeEvalContext,
|
||||
): MutableList<PsiElement?> {
|
||||
val qualifiedName = expression.asQualifiedName()
|
||||
val pyFile = PyUtil.`as`(FileContextUtil.getContextFile(expression), PyFile::class.java)
|
||||
val pyFile = FileContextUtil.getContextFile(expression) as? PyFile
|
||||
|
||||
val anchor = expression.containingFile.context
|
||||
val scopeOwner: ScopeOwner?
|
||||
@@ -2875,19 +2872,15 @@ class PyTypingTypeProvider : PyTypeProviderWithCustomContext<Context?>() {
|
||||
|
||||
@JvmStatic
|
||||
fun coroutineOrGeneratorElementType(coroutineOrGeneratorType: PyType?): Ref<PyType?>? {
|
||||
val genericType = PyUtil.`as`(coroutineOrGeneratorType, PyCollectionType::class.java)
|
||||
val classType = PyUtil.`as`(coroutineOrGeneratorType, PyClassType::class.java)
|
||||
if (coroutineOrGeneratorType !is PyCollectionType) return null
|
||||
val qName = coroutineOrGeneratorType.classQName
|
||||
|
||||
if (genericType != null && classType != null) {
|
||||
val qName = classType.classQName
|
||||
if (AWAITABLE == qName) {
|
||||
return Ref(coroutineOrGeneratorType.elementTypes.getOrNull(0))
|
||||
}
|
||||
|
||||
if (AWAITABLE == qName) {
|
||||
return Ref(ContainerUtil.getOrElse<PyType?>(genericType.elementTypes, 0, null))
|
||||
}
|
||||
|
||||
if (ArrayUtil.contains(qName, COROUTINE, GENERATOR)) {
|
||||
return Ref(ContainerUtil.getOrElse<PyType?>(genericType.elementTypes, 2, null))
|
||||
}
|
||||
if (qName in arrayOf(COROUTINE, PyNames.TYPES_COROUTINE_TYPE, GENERATOR)) {
|
||||
return Ref(coroutineOrGeneratorType.elementTypes.getOrNull(2))
|
||||
}
|
||||
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user