diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/CallTypeExtractor.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/CallTypeExtractor.kt index bec65f6c87c..821405d5073 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/CallTypeExtractor.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/CallTypeExtractor.kt @@ -3,6 +3,7 @@ package com.intellij.debugger.streams.kotlin.psi import com.intellij.debugger.streams.trace.impl.handler.type.GenericType import org.jetbrains.kotlin.psi.KtCallExpression +import org.jetbrains.kotlin.types.KotlinType /** * @author Vitaliy.Bibaev @@ -13,4 +14,18 @@ interface CallTypeExtractor { data class IntermediateCallTypes(val typeBefore: GenericType, val typeAfter: GenericType) data class TerminatorCallTypes(val typeBefore: GenericType, val resultType: GenericType) + + abstract class Base : CallTypeExtractor { + override fun extractIntermediateCallTypes(call: KtCallExpression): IntermediateCallTypes = + IntermediateCallTypes(extractItemsType(call.receiverType()), extractItemsType(call.resolveType())) + + + override fun extractTerminalCallTypes(call: KtCallExpression): TerminatorCallTypes = + TerminatorCallTypes(extractItemsType(call.receiverType()), getResultType(call.resolveType())) + + + protected abstract fun extractItemsType(type: KotlinType?): GenericType + protected abstract fun getResultType(type: KotlinType): GenericType + + } } \ No newline at end of file diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/collections/KotlinCollectionsTypeExtractor.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/collections/KotlinCollectionsTypeExtractor.kt index 7342f5e5d12..9e2c8ef4369 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/collections/KotlinCollectionsTypeExtractor.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/collections/KotlinCollectionsTypeExtractor.kt @@ -2,25 +2,20 @@ package com.intellij.debugger.streams.kotlin.psi.collections import com.intellij.debugger.streams.kotlin.psi.CallTypeExtractor -import com.intellij.debugger.streams.kotlin.psi.CallTypeExtractor.IntermediateCallTypes -import com.intellij.debugger.streams.kotlin.psi.CallTypeExtractor.TerminatorCallTypes import com.intellij.debugger.streams.kotlin.psi.KotlinPsiUtil -import com.intellij.debugger.streams.kotlin.psi.receiverType -import com.intellij.debugger.streams.kotlin.psi.resolveType import com.intellij.debugger.streams.kotlin.trace.dsl.KotlinTypes import com.intellij.debugger.streams.kotlin.trace.dsl.KotlinTypes.ANY import com.intellij.debugger.streams.kotlin.trace.dsl.KotlinTypes.NULLABLE_ANY import com.intellij.debugger.streams.trace.impl.handler.type.ArrayType import com.intellij.debugger.streams.trace.impl.handler.type.GenericType import com.intellij.openapi.diagnostic.Logger -import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.typeUtil.supertypes /** * @author Vitaliy.Bibaev */ -class KotlinCollectionsTypeExtractor : CallTypeExtractor { +class KotlinCollectionsTypeExtractor : CallTypeExtractor.Base() { private companion object { val LOG = Logger.getInstance(KotlinCollectionsTypeExtractor::class.java) val primitives: Set = setOf(KotlinTypes.BOOLEAN, KotlinTypes.BYTE, KotlinTypes.INT, KotlinTypes.SHORT, @@ -28,19 +23,17 @@ class KotlinCollectionsTypeExtractor : CallTypeExtractor { val primitiveArrays: Set = primitives.map(KotlinTypes::array).toSet() } - override fun extractIntermediateCallTypes(call: KtCallExpression): IntermediateCallTypes = - IntermediateCallTypes(extractItemsType(call.receiverType()), extractItemsType(call.resolveType())) - - - override fun extractTerminalCallTypes(call: KtCallExpression): TerminatorCallTypes = - TerminatorCallTypes(extractItemsType(call.receiverType()), getResultType(call.resolveType())) - - private fun extractItemsType(type: KotlinType?): GenericType { + override fun extractItemsType(type: KotlinType?): GenericType { if (type == null) return NULLABLE_ANY return tryToFindElementType(type) ?: defaultType(type) } + override fun getResultType(type: KotlinType): GenericType { + val typeName = KotlinPsiUtil.getTypeWithoutTypeParameters(type) + return tryToGetPrimitiveByName(typeName) ?: tryToGetPrimitiveArrayByName(typeName) ?: getAny(type) + } + private fun tryToFindElementType(type: KotlinType): GenericType? { val typeName = KotlinPsiUtil.getTypeWithoutTypeParameters(type) if (typeName == "kotlin.collections.Iterable" || typeName == "kotlin.Array") { @@ -65,11 +58,6 @@ class KotlinCollectionsTypeExtractor : CallTypeExtractor { LOG.warn("Could not find type of items for type ${KotlinPsiUtil.getTypeName(type)}") return getAny(type) } - - private fun getResultType(type: KotlinType): GenericType { - val typeName = KotlinPsiUtil.getTypeWithoutTypeParameters(type) - return tryToGetPrimitiveByName(typeName) ?: tryToGetPrimitiveArrayByName(typeName) ?: getAny(type) - } private fun getAny(type: KotlinType): GenericType = if (type.isMarkedNullable) NULLABLE_ANY else ANY diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/java/JavaStreamChainTypeExtractor.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/java/JavaStreamChainTypeExtractor.kt index c1e324142ec..fe764cb908c 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/java/JavaStreamChainTypeExtractor.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/java/JavaStreamChainTypeExtractor.kt @@ -2,33 +2,19 @@ package com.intellij.debugger.streams.kotlin.psi.java import com.intellij.debugger.streams.kotlin.psi.CallTypeExtractor -import com.intellij.debugger.streams.kotlin.psi.CallTypeExtractor.IntermediateCallTypes -import com.intellij.debugger.streams.kotlin.psi.CallTypeExtractor.TerminatorCallTypes import com.intellij.debugger.streams.kotlin.psi.KotlinPsiUtil -import com.intellij.debugger.streams.kotlin.psi.receiverType -import com.intellij.debugger.streams.kotlin.psi.resolveType import com.intellij.debugger.streams.kotlin.trace.dsl.KotlinTypes import com.intellij.debugger.streams.trace.impl.handler.type.ClassTypeImpl import com.intellij.debugger.streams.trace.impl.handler.type.GenericType import com.intellij.psi.CommonClassNames -import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.typeUtil.getImmediateSuperclassNotAny /** * @author Vitaliy.Bibaev */ -class JavaStreamChainTypeExtractor : CallTypeExtractor { - override fun extractIntermediateCallTypes(call: KtCallExpression): IntermediateCallTypes { - val resultType = call.resolveType() - val receiverType = call.receiverType() - return IntermediateCallTypes(extractItemsType(receiverType), extractItemsType(resultType)) - } - - override fun extractTerminalCallTypes(call: KtCallExpression): TerminatorCallTypes = - TerminatorCallTypes(extractItemsType(call.receiverType()), getResultType(call.resolveType())) - - private fun extractItemsType(type: KotlinType?): GenericType { +class JavaStreamChainTypeExtractor : CallTypeExtractor.Base() { + override fun extractItemsType(type: KotlinType?): GenericType { if (type == null) { return KotlinTypes.NULLABLE_ANY } @@ -42,5 +28,5 @@ class JavaStreamChainTypeExtractor : CallTypeExtractor { } } - private fun getResultType(type: KotlinType): GenericType = ClassTypeImpl(KotlinPsiUtil.getTypeName(type)) + override fun getResultType(type: KotlinType): GenericType = ClassTypeImpl(KotlinPsiUtil.getTypeName(type)) } \ No newline at end of file diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/sequence/SequenceTypeExtractor.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/sequence/SequenceTypeExtractor.kt index 7c21f0d6f4e..e8fbf9cc571 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/sequence/SequenceTypeExtractor.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/psi/sequence/SequenceTypeExtractor.kt @@ -2,17 +2,18 @@ package com.intellij.debugger.streams.kotlin.psi.sequence import com.intellij.debugger.streams.kotlin.psi.CallTypeExtractor -import org.jetbrains.kotlin.psi.KtCallExpression +import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import org.jetbrains.kotlin.types.KotlinType /** * @author Vitaliy.Bibaev */ -class SequenceTypeExtractor : CallTypeExtractor { - override fun extractIntermediateCallTypes(call: KtCallExpression): CallTypeExtractor.IntermediateCallTypes { +class SequenceTypeExtractor : CallTypeExtractor.Base() { + override fun extractItemsType(type: KotlinType?): GenericType { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } - override fun extractTerminalCallTypes(call: KtCallExpression): CallTypeExtractor.TerminatorCallTypes { + override fun getResultType(type: KotlinType): GenericType { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } } \ No newline at end of file