Add ability to specify a custom way to create peek call
This commit is contained in:
committed by
Yan Zhulanow
parent
5ab76d1eed
commit
12fe36b77f
+2
-2
@@ -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
|
||||
|
||||
+33
@@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -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
|
||||
|
||||
+2
-1
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -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)
|
||||
}
|
||||
+13
@@ -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)
|
||||
}
|
||||
+3
-3
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
+32
@@ -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<CallArgument>
|
||||
|
||||
init {
|
||||
args = listOf(CallArgumentImpl(KotlinTypes.ANY.genericTypeName, lambda))
|
||||
}
|
||||
|
||||
override fun getArguments(): List<CallArgument> = 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
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user