Add util function to extract type name without generic parameters
This commit is contained in:
committed by
Yan Zhulanow
parent
b817fd111e
commit
8900411fb1
@@ -6,7 +6,9 @@ import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
@@ -15,8 +17,14 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
*/
|
||||
|
||||
object KotlinPsiUtil {
|
||||
fun getTypeName(type: KotlinType): String = DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(type)
|
||||
private val WITH_TYPES_RENDERER = DescriptorRenderer.withOptions { modifiers = DescriptorRendererModifier.ALL }
|
||||
|
||||
fun getTypeName(type: KotlinType): String = WITH_TYPES_RENDERER.renderType(type)
|
||||
|
||||
fun getTypeWithoutTypeParameters(type: KotlinType): String {
|
||||
val descriptor = type.constructor.declarationDescriptor ?: return getTypeName(type)
|
||||
return descriptor.fqNameSafe.asString()
|
||||
}
|
||||
}
|
||||
|
||||
fun KtExpression.resolveType(): KotlinType =
|
||||
|
||||
+2
-3
@@ -1,9 +1,9 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.debugger.streams.kotlin.psi.impl
|
||||
|
||||
import com.intellij.debugger.streams.kotlin.psi.KotlinPsiUtil
|
||||
import com.intellij.debugger.streams.kotlin.psi.previousCall
|
||||
import com.intellij.debugger.streams.kotlin.psi.receiverType
|
||||
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
|
||||
/**
|
||||
@@ -18,8 +18,7 @@ class KotlinCollectionChainBuilder
|
||||
|
||||
private fun isCollectionTransformationCall(expression: KtCallExpression): Boolean {
|
||||
val receiverType = expression.receiverType() ?: return false
|
||||
val receiverTypeName = receiverType.getJetTypeFqName(false)
|
||||
return SUPPORTED_RECEIVERS.contains(receiverTypeName)
|
||||
return SUPPORTED_RECEIVERS.contains(KotlinPsiUtil.getTypeWithoutTypeParameters(receiverType))
|
||||
}
|
||||
|
||||
override val existenceChecker: ExistenceChecker = object : ExistenceChecker() {
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.debugger.streams.kotlin.psi.impl
|
||||
|
||||
import com.intellij.debugger.streams.kotlin.psi.KotlinPsiUtil
|
||||
import com.intellij.debugger.streams.kotlin.psi.StreamCallChecker
|
||||
import com.intellij.debugger.streams.kotlin.psi.receiverType
|
||||
import com.intellij.debugger.streams.kotlin.psi.resolveType
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
@@ -33,7 +33,7 @@ class PackageBasedCallChecker(private val supportedPackage: String) : StreamCall
|
||||
}
|
||||
|
||||
private fun isSupportedType(type: KotlinType): Boolean {
|
||||
val typeName = type.getJetTypeFqName(false)
|
||||
val typeName = KotlinPsiUtil.getTypeWithoutTypeParameters(type)
|
||||
return StringUtil.getPackageName(typeName).startsWith(supportedPackage)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user