From 12fe36b77f1e7233f6bff79a8aa2266b3c81528c Mon Sep 17 00:00:00 2001 From: "Vitaliy.Bibaev" Date: Fri, 27 Oct 2017 15:58:16 +0300 Subject: [PATCH] Add ability to specify a custom way to create peek call --- .../lib/JavaStandardLibrarySupportProvider.kt | 4 +-- .../lib/KotlinCollectionLibrarySupport.kt | 33 +++++++++++++++++++ .../lib/KotlinCollectionSupportProvider.kt | 3 +- .../lib/StreamExLibrarySupportProvider.kt | 3 +- .../kotlin/trace/dsl/JavaPeekCallFactory.kt | 13 ++++++++ .../dsl/KotlinCollectionsPeekCallFactory.kt | 13 ++++++++ .../trace/dsl/KotlinStatementFactory.kt | 6 ++-- .../kotlin/trace/dsl/PeekCallFactory.kt | 11 +++++++ .../kotlin/trace/impl/handler/OnEachCall.kt | 32 ++++++++++++++++++ .../streams/kotlin/dsl/KotlinDslTest.kt | 3 +- 10 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/JavaPeekCallFactory.kt create mode 100644 idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/KotlinCollectionsPeekCallFactory.kt create mode 100644 idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/PeekCallFactory.kt create mode 100644 idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/impl/handler/OnEachCall.kt diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/JavaStandardLibrarySupportProvider.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/JavaStandardLibrarySupportProvider.kt index ae3800404ff..e9a15728656 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/JavaStandardLibrarySupportProvider.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/JavaStandardLibrarySupportProvider.kt @@ -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.lib import com.intellij.debugger.streams.kotlin.psi.impl.KotlinJavaStreamChainBuilder import com.intellij.debugger.streams.kotlin.psi.impl.PackageBasedCallChecker +import com.intellij.debugger.streams.kotlin.trace.dsl.JavaPeekCallFactory import com.intellij.debugger.streams.kotlin.trace.dsl.KotlinStatementFactory import com.intellij.debugger.streams.kotlin.trace.impl.KotlinTraceExpressionBuilder import com.intellij.debugger.streams.lib.LibrarySupport @@ -21,7 +21,7 @@ class JavaStandardLibrarySupportProvider : LibrarySupportProvider { private companion object { val builder = KotlinJavaStreamChainBuilder(PackageBasedCallChecker("java.util.stream")) val support = StandardLibrarySupport() - val dsl = DslImpl(KotlinStatementFactory()) + val dsl = DslImpl(KotlinStatementFactory(JavaPeekCallFactory())) } override fun getLanguageId(): String = LibraryUtil.KOTLIN_LANGUAGE_ID diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/KotlinCollectionLibrarySupport.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/KotlinCollectionLibrarySupport.kt index 0b461b7f036..9086236196f 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/KotlinCollectionLibrarySupport.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/KotlinCollectionLibrarySupport.kt @@ -1,11 +1,44 @@ package com.intellij.debugger.streams.kotlin.lib +import com.intellij.debugger.streams.lib.IntermediateOperation +import com.intellij.debugger.streams.lib.TerminalOperation import com.intellij.debugger.streams.lib.impl.LibrarySupportBase +import com.intellij.debugger.streams.resolve.ValuesOrderResolver +import com.intellij.debugger.streams.trace.CallTraceInterpreter +import com.intellij.debugger.streams.trace.IntermediateCallHandler +import com.intellij.debugger.streams.trace.TerminatorCallHandler +import com.intellij.debugger.streams.trace.dsl.Dsl +import com.intellij.debugger.streams.wrapper.IntermediateStreamCall +import com.intellij.debugger.streams.wrapper.TerminatorStreamCall /** * @author Vitaliy.Bibaev */ class KotlinCollectionLibrarySupport : LibrarySupportBase() { init { + addIntermediateOperationsSupport() + addTerminationOperationsSupport() + } + + private fun addOperation(operation: CollectionOperation) { + addIntermediateOperationsSupport(operation) + addTerminationOperationsSupport(operation) + } + + private class CollectionOperation : IntermediateOperation, TerminalOperation { + override val name: String + get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. + override val traceInterpreter: CallTraceInterpreter + get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. + override val valuesOrderResolver: ValuesOrderResolver + get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. + + override fun getTraceHandler(callOrder: Int, call: IntermediateStreamCall, dsl: Dsl): IntermediateCallHandler { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun getTraceHandler(call: TerminatorStreamCall, resultExpression: String, dsl: Dsl): TerminatorCallHandler { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } } } \ No newline at end of file diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/KotlinCollectionSupportProvider.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/KotlinCollectionSupportProvider.kt index 32b126fb051..088383ff137 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/KotlinCollectionSupportProvider.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/KotlinCollectionSupportProvider.kt @@ -2,6 +2,7 @@ package com.intellij.debugger.streams.kotlin.lib import com.intellij.debugger.streams.kotlin.psi.impl.KotlinCollectionChainBuilder +import com.intellij.debugger.streams.kotlin.trace.dsl.KotlinCollectionsPeekCallFactory import com.intellij.debugger.streams.kotlin.trace.dsl.KotlinStatementFactory import com.intellij.debugger.streams.kotlin.trace.impl.KotlinTraceExpressionBuilder import com.intellij.debugger.streams.lib.LibrarySupport @@ -18,7 +19,7 @@ class KotlinCollectionSupportProvider : LibrarySupportProvider { private companion object { val builder: StreamChainBuilder = KotlinCollectionChainBuilder() val support: LibrarySupport = KotlinCollectionLibrarySupport() - val dsl = DslImpl(KotlinStatementFactory()) + val dsl = DslImpl(KotlinStatementFactory(KotlinCollectionsPeekCallFactory())) } override fun getLanguageId(): String = LibraryUtil.KOTLIN_LANGUAGE_ID diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/StreamExLibrarySupportProvider.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/StreamExLibrarySupportProvider.kt index 8f2d4819cde..d672aa24923 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/StreamExLibrarySupportProvider.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/StreamExLibrarySupportProvider.kt @@ -3,6 +3,7 @@ package com.intellij.debugger.streams.kotlin.lib import com.intellij.debugger.streams.kotlin.psi.impl.KotlinJavaStreamChainBuilder import com.intellij.debugger.streams.kotlin.psi.impl.PackageBasedCallChecker +import com.intellij.debugger.streams.kotlin.trace.dsl.JavaPeekCallFactory import com.intellij.debugger.streams.kotlin.trace.dsl.KotlinStatementFactory import com.intellij.debugger.streams.kotlin.trace.impl.KotlinTraceExpressionBuilder import com.intellij.debugger.streams.lib.LibrarySupport @@ -20,7 +21,7 @@ class StreamExLibrarySupportProvider : LibrarySupportProvider { private companion object { val streamChainBuilder = KotlinJavaStreamChainBuilder(PackageBasedCallChecker("one.util.streamex")) val support = StreamExLibrarySupport() - val dsl = DslImpl(KotlinStatementFactory()) + val dsl = DslImpl(KotlinStatementFactory(JavaPeekCallFactory())) val expressionBuilder = KotlinTraceExpressionBuilder(dsl, support.createHandlerFactory(dsl)) } diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/JavaPeekCallFactory.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/JavaPeekCallFactory.kt new file mode 100644 index 00000000000..5c883b3d39f --- /dev/null +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/JavaPeekCallFactory.kt @@ -0,0 +1,13 @@ +package com.intellij.debugger.streams.kotlin.trace.dsl + +import com.intellij.debugger.streams.trace.impl.handler.PeekCall +import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.wrapper.IntermediateStreamCall + +/** + * @author Vitaliy.Bibaev + */ +class JavaPeekCallFactory : PeekCallFactory { + override fun createPeekCall(elementsType: GenericType, lambda: String): IntermediateStreamCall = + PeekCall(lambda, elementsType) +} \ No newline at end of file diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/KotlinCollectionsPeekCallFactory.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/KotlinCollectionsPeekCallFactory.kt new file mode 100644 index 00000000000..69ae04ee31a --- /dev/null +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/KotlinCollectionsPeekCallFactory.kt @@ -0,0 +1,13 @@ +package com.intellij.debugger.streams.kotlin.trace.dsl + +import com.intellij.debugger.streams.kotlin.trace.impl.handler.OnEachCall +import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.wrapper.IntermediateStreamCall + +/** + * @author Vitaliy.Bibaev + */ +class KotlinCollectionsPeekCallFactory : PeekCallFactory { + override fun createPeekCall(elementsType: GenericType, lambda: String): IntermediateStreamCall = + OnEachCall(elementsType, lambda) +} \ No newline at end of file diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/KotlinStatementFactory.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/KotlinStatementFactory.kt index e55d5cca009..ffdb3ac2d9e 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/KotlinStatementFactory.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/KotlinStatementFactory.kt @@ -5,14 +5,13 @@ import com.intellij.debugger.streams.trace.dsl.* import com.intellij.debugger.streams.trace.dsl.impl.AssignmentStatement import com.intellij.debugger.streams.trace.dsl.impl.TextExpression import com.intellij.debugger.streams.trace.dsl.impl.VariableImpl -import com.intellij.debugger.streams.trace.impl.handler.PeekCall import com.intellij.debugger.streams.trace.impl.handler.type.GenericType import com.intellij.debugger.streams.wrapper.IntermediateStreamCall /** * @author Vitaliy.Bibaev */ -class KotlinStatementFactory : StatementFactory { +class KotlinStatementFactory(private val peekCallFactory: PeekCallFactory) : StatementFactory { override fun createNewListExpression(elementType: GenericType, vararg args: Expression): Expression = TextExpression("kotlin.collections.mutableListOf<${elementType.genericTypeName}>(${StatementFactory.commaSeparate(*args)})") @@ -95,5 +94,6 @@ class KotlinStatementFactory : StatementFactory { override fun createNewSizedArray(elementType: GenericType, size: Expression): Expression = TextExpression("arrayOfNulls<${elementType.genericTypeName}>(${size.toCode()})") - override fun createPeekCall(elementsType: GenericType, lambda: String): IntermediateStreamCall = PeekCall(lambda, elementsType) + override fun createPeekCall(elementsType: GenericType, lambda: String): IntermediateStreamCall = + peekCallFactory.createPeekCall(elementsType, lambda) } diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/PeekCallFactory.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/PeekCallFactory.kt new file mode 100644 index 00000000000..e6144dc4ff6 --- /dev/null +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/dsl/PeekCallFactory.kt @@ -0,0 +1,11 @@ +package com.intellij.debugger.streams.kotlin.trace.dsl + +import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.wrapper.IntermediateStreamCall + +/** + * @author Vitaliy.Bibaev + */ +interface PeekCallFactory { + fun createPeekCall(elementsType: GenericType, lambda: String): IntermediateStreamCall +} \ No newline at end of file diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/impl/handler/OnEachCall.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/impl/handler/OnEachCall.kt new file mode 100644 index 00000000000..b0bf153bd29 --- /dev/null +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/trace/impl/handler/OnEachCall.kt @@ -0,0 +1,32 @@ +package com.intellij.debugger.streams.kotlin.trace.impl.handler + +import com.intellij.debugger.streams.kotlin.trace.dsl.KotlinTypes +import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.wrapper.CallArgument +import com.intellij.debugger.streams.wrapper.IntermediateStreamCall +import com.intellij.debugger.streams.wrapper.StreamCallType +import com.intellij.debugger.streams.wrapper.impl.CallArgumentImpl +import com.intellij.openapi.util.TextRange + +/** + * @author Vitaliy.Bibaev + */ +class OnEachCall(private val elementsType: GenericType, lambda: String) : IntermediateStreamCall { + private val args: List + + init { + args = listOf(CallArgumentImpl(KotlinTypes.ANY.genericTypeName, lambda)) + } + + override fun getArguments(): List = args + + override fun getName(): String = "onEach" + + override fun getType(): StreamCallType = StreamCallType.INTERMEDIATE + + override fun getTextRange(): TextRange = TextRange.EMPTY_RANGE + + override fun getTypeBefore(): GenericType = elementsType + + override fun getTypeAfter(): GenericType = elementsType +} \ No newline at end of file diff --git a/idea/tests/com/intellij/debugger/streams/kotlin/dsl/KotlinDslTest.kt b/idea/tests/com/intellij/debugger/streams/kotlin/dsl/KotlinDslTest.kt index 0c129999724..209d724ac9d 100644 --- a/idea/tests/com/intellij/debugger/streams/kotlin/dsl/KotlinDslTest.kt +++ b/idea/tests/com/intellij/debugger/streams/kotlin/dsl/KotlinDslTest.kt @@ -1,6 +1,7 @@ // 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.dsl +import com.intellij.debugger.streams.kotlin.trace.dsl.KotlinCollectionsPeekCallFactory import com.intellij.debugger.streams.kotlin.trace.dsl.KotlinStatementFactory import com.intellij.debugger.streams.test.DslTestCase import com.intellij.debugger.streams.trace.dsl.impl.DslImpl @@ -8,7 +9,7 @@ import com.intellij.debugger.streams.trace.dsl.impl.DslImpl /** * @author Vitaliy.Bibaev */ -class KotlinDslTest : DslTestCase(DslImpl(KotlinStatementFactory())) { +class KotlinDslTest : DslTestCase(DslImpl(KotlinStatementFactory(KotlinCollectionsPeekCallFactory()))) { override fun getTestDataPath(): String { return "testData/dsl" }