diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/ArrayVariable.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/ArrayVariable.kt index e43601e0108d..fceb26696000 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/ArrayVariable.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/ArrayVariable.kt @@ -16,14 +16,14 @@ package com.intellij.debugger.streams.trace.dsl import com.intellij.debugger.streams.trace.dsl.impl.TextExpression -import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.ArrayType /** * @author Vitaliy.Bibaev */ interface ArrayVariable : Variable { - val elementType: GenericType + override val type: ArrayType operator fun get(index: Expression): Expression operator fun get(index: Int): Expression = get(TextExpression(index.toString())) diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/ListVariable.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/ListVariable.kt index 24b6ec65a77d..68327340fcc4 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/ListVariable.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/ListVariable.kt @@ -16,13 +16,13 @@ package com.intellij.debugger.streams.trace.dsl import com.intellij.debugger.streams.trace.dsl.impl.TextExpression -import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.ListType /** * @author Vitaliy.Bibaev */ interface ListVariable : Variable { - val elementType: GenericType + override val type: ListType fun get(index: Expression): Expression fun get(index: Int): Expression = get(TextExpression(index.toString())) diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/MapVariable.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/MapVariable.kt index 3ed6f089cb61..40fca67d2f30 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/MapVariable.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/MapVariable.kt @@ -15,14 +15,13 @@ */ package com.intellij.debugger.streams.trace.dsl -import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.MapType /** * @author Vitaliy.Bibaev */ interface MapVariable : Variable { - val keyType: GenericType - val valueType: GenericType + override val type: MapType fun get(key: Expression): Expression fun set(key: Expression, newValue: Expression): Expression diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/Types.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/Types.kt index 3ca867be2231..3387071c5712 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/Types.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/Types.kt @@ -15,7 +15,10 @@ */ package com.intellij.debugger.streams.trace.dsl +import com.intellij.debugger.streams.trace.impl.handler.type.ArrayType import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.ListType +import com.intellij.debugger.streams.trace.impl.handler.type.MapType /** * @author Vitaliy.Bibaev @@ -34,6 +37,8 @@ interface Types { val listOfAny: GenericType get() = list(anyType) - fun list(elementsType: GenericType): GenericType - fun map(keyType: GenericType, valueType: GenericType): GenericType + fun array(elementType: GenericType): ArrayType + fun list(elementsType: GenericType): ListType + fun map(keyType: GenericType, valueType: GenericType): MapType + fun linkedMap(keyType: GenericType, valueType: GenericType): MapType } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/Variable.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/Variable.kt index f19e58bd9923..8b5cfea6beaa 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/Variable.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/Variable.kt @@ -15,11 +15,13 @@ */ package com.intellij.debugger.streams.trace.dsl +import com.intellij.debugger.streams.trace.impl.handler.type.GenericType + /** * @author Vitaliy.Bibaev */ interface Variable : Expression { - val type: String + val type: GenericType val name: String override fun toCode(indent: Int): String = name.withIndent(indent) diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/VariableImpl.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/VariableImpl.kt index 9ef3cf2431d2..dddaef7db404 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/VariableImpl.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/VariableImpl.kt @@ -17,11 +17,12 @@ package com.intellij.debugger.streams.trace.dsl.impl import com.intellij.debugger.streams.trace.dsl.Expression import com.intellij.debugger.streams.trace.dsl.Variable +import com.intellij.debugger.streams.trace.impl.handler.type.GenericType /** * @author Vitaliy.Bibaev */ -open class VariableImpl(override val type: String, override val name: String) : Variable { +open class VariableImpl(override val type: GenericType, override val name: String) : Variable { override fun call(callName: String, vararg args: Expression): Expression = TextExpression("$name.$callName(${args.joinToString(", ") { it.toCode() }})") diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/common/MapVariableBase.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/common/MapVariableBase.kt index 5a8c96e725c1..d1e299278f4f 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/common/MapVariableBase.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/common/MapVariableBase.kt @@ -20,21 +20,21 @@ import com.intellij.debugger.streams.trace.dsl.Dsl import com.intellij.debugger.streams.trace.dsl.MapVariable 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.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.MapType /** * @author Vitaliy.Bibaev */ -abstract class MapVariableBase(override val keyType: GenericType, override val valueType: GenericType, - override val type: String, override val name: String) +abstract class MapVariableBase(override val type: MapType, override val name: String) : VariableImpl(type, name), MapVariable { + override fun convertToArray(dsl: Dsl, arrayName: String): CodeBlock { val resultArray = dsl.array(dsl.types.anyType, arrayName) val size = dsl.variable(dsl.types.integerType, "size") - val keys = dsl.array(keyType, "keys") - val values = dsl.array(valueType, "values") + val keys = dsl.array(type.keyType, "keys") + val values = dsl.array(type.valueType, "values") val i = dsl.variable(dsl.types.integerType, "i") - val key = dsl.variable(keyType, "key") + val key = dsl.variable(type.keyType, "key") return dsl.block { declare(resultArray, true) scope { diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaArrayVariable.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaArrayVariable.kt index 9b8132d5e5a6..1667b9f75289 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaArrayVariable.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaArrayVariable.kt @@ -20,17 +20,17 @@ import com.intellij.debugger.streams.trace.dsl.Expression import com.intellij.debugger.streams.trace.dsl.VariableDeclaration 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.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.ArrayType /** * @author Vitaliy.Bibaev */ -class JavaArrayVariable(override val elementType: GenericType, name: String) - : VariableImpl("${elementType.variableTypeName}[]", name), ArrayVariable { +class JavaArrayVariable(override val type: ArrayType, name: String) + : VariableImpl(type, name), ArrayVariable { override fun get(index: Expression): Expression = TextExpression("$name[${index.toCode()}]") override fun set(index: Expression, value: Expression): Expression = TextExpression("$name[${index.toCode()}] = ${value.toCode()}") override fun defaultDeclaration(size: Expression): VariableDeclaration = - JavaVariableDeclaration(this, false, TextExpression("new ${elementType.variableTypeName}[${size.toCode()}]")) + JavaVariableDeclaration(this, false, TextExpression("new ${type.elementType.variableTypeName}[${size.toCode()}]")) } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaForEachLoop.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaForEachLoop.kt index 6d72f3279304..259c6a59ff37 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaForEachLoop.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaForEachLoop.kt @@ -15,7 +15,10 @@ */ package com.intellij.debugger.streams.trace.dsl.impl.java -import com.intellij.debugger.streams.trace.dsl.* +import com.intellij.debugger.streams.trace.dsl.Convertable +import com.intellij.debugger.streams.trace.dsl.Expression +import com.intellij.debugger.streams.trace.dsl.ForLoopBody +import com.intellij.debugger.streams.trace.dsl.Variable /** * @author Vitaliy.Bibaev @@ -24,7 +27,7 @@ class JavaForEachLoop(private val iterateVariable: Variable, private val collection: Expression, private val loopBody: ForLoopBody) : Convertable { override fun toCode(indent: Int): String = - "for (${iterateVariable.type} ${iterateVariable.name} : ${collection.toCode(0)}) {\n".withIndent(indent) + + "for (${iterateVariable.type.variableTypeName} ${iterateVariable.name} : ${collection.toCode(0)}) {\n".withIndent(indent) + loopBody.toCode(indent + 1) + "}".withIndent(indent) } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaListVariable.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaListVariable.kt index d9b1c9a1cf40..a60b26feabd2 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaListVariable.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaListVariable.kt @@ -20,13 +20,14 @@ import com.intellij.debugger.streams.trace.dsl.ListVariable import com.intellij.debugger.streams.trace.dsl.VariableDeclaration 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.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.ListType /** * @author Vitaliy.Bibaev */ -class JavaListVariable(override val elementType: GenericType, name: String) - : VariableImpl("java.util.List<${elementType.genericTypeName}>", name), ListVariable { +class JavaListVariable(override val type: ListType, name: String) + : VariableImpl(type, name), ListVariable { + override fun get(index: Expression): Expression = call("get", index) override fun set(index: Expression, newValue: Expression): Expression = call("set", index, newValue) override fun add(element: Expression): Expression = call("add", element) @@ -36,5 +37,5 @@ class JavaListVariable(override val elementType: GenericType, name: String) override fun size(): Expression = call("size") override fun defaultDeclaration(): VariableDeclaration = - JavaVariableDeclaration(this, false, TextExpression("new java.util.ArrayList<${elementType.genericTypeName}>()")) + JavaVariableDeclaration(this, false, TextExpression(type.defaultValue)) } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaMapVariable.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaMapVariable.kt index 3b286fbf53d5..e29f600b4de3 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaMapVariable.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaMapVariable.kt @@ -20,32 +20,25 @@ import com.intellij.debugger.streams.trace.dsl.Lambda import com.intellij.debugger.streams.trace.dsl.VariableDeclaration import com.intellij.debugger.streams.trace.dsl.impl.TextExpression import com.intellij.debugger.streams.trace.dsl.impl.common.MapVariableBase -import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.MapType /** * @author Vitaliy.Bibaev */ -class JavaMapVariable(keyType: GenericType, - valueType: GenericType, - name: String, - private val linked: Boolean) - : MapVariableBase(keyType, valueType, "${getMapType(linked)}<${keyType.genericTypeName}, ${valueType.genericTypeName}>", name) { - companion object { - fun getMapType(linked: Boolean): String = "java.util.${if (linked) "Linked" else ""}HashMap" - } - +class JavaMapVariable(type: MapType, name: String) + : MapVariableBase(type, name) { override fun get(key: Expression): Expression = call("get", key) override operator fun set(key: Expression, newValue: Expression): Expression = call("put", key, newValue) override fun contains(key: Expression): Expression = call("contains", key) - override fun defaultDeclaration(isMutable: Boolean): VariableDeclaration = - JavaVariableDeclaration(this, false, TextExpression("new ${getMapType(linked)}<>()")) - override fun keys(): Expression = call("keySet") override fun size(): Expression = call("size") override fun computeIfAbsent(key: Expression, supplier: Lambda): Expression = call("computeIfAbsent", key, supplier) + + override fun defaultDeclaration(isMutable: Boolean): VariableDeclaration = + JavaVariableDeclaration(this, false, TextExpression(type.defaultValue)) } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaStatementFactory.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaStatementFactory.kt index b4413f80a5f9..f53813c2f199 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaStatementFactory.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaStatementFactory.kt @@ -56,7 +56,7 @@ class JavaStatementFactory : StatementFactory { return JavaLambda(argName, lambdaBody as JavaLambdaBody) } - override fun createVariable(type: GenericType, name: String): Variable = VariableImpl(type.variableTypeName, name) + override fun createVariable(type: GenericType, name: String): Variable = VariableImpl(type, name) override fun and(left: Expression, right: Expression): Expression = TextExpression("${left.toCode()} $$ ${right.toCode()}") @@ -71,10 +71,10 @@ class JavaStatementFactory : StatementFactory { JavaAssignmentStatement(variable, expression) override fun createMapVariable(keyType: GenericType, valueType: GenericType, name: String, linked: Boolean): MapVariable = - JavaMapVariable(keyType, valueType, name, linked) + JavaMapVariable(types.map(keyType, valueType), name) override fun createArrayVariable(elementType: GenericType, name: String): ArrayVariable = - JavaArrayVariable(elementType, name) + JavaArrayVariable(types.array(elementType), name) override fun createScope(codeBlock: CodeBlock): Convertable = object : Convertable { override fun toCode(indent: Int): String = "{\n".withIndent(indent) + @@ -102,7 +102,7 @@ class JavaStatementFactory : StatementFactory { override fun createNewListExpression(elementType: GenericType, vararg args: Expression): Expression { if (args.isEmpty()) { - return TextExpression("new java.util.ArrayList<${elementType.genericTypeName}>()") + return TextExpression(types.list(elementType).defaultValue) } return TextExpression("java.util.Arrays.asList(${args.joinToString(separator = ", ") { it.toCode() }})") @@ -110,7 +110,7 @@ class JavaStatementFactory : StatementFactory { override fun createPeekCall(elementsType: GenericType, lambda: String): IntermediateStreamCall = PeekCall(lambda, elementsType) - override fun createListVariable(elementType: GenericType, name: String): ListVariable = JavaListVariable(elementType, name) + override fun createListVariable(elementType: GenericType, name: String): ListVariable = JavaListVariable(types.list(elementType), name) override fun not(expression: Expression): Expression = TextExpression("!${expression.toCode()}") } diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaTypes.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaTypes.kt index 442f43a4daba..60a192250ddb 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaTypes.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaTypes.kt @@ -16,9 +16,7 @@ package com.intellij.debugger.streams.trace.dsl.impl.java import com.intellij.debugger.streams.trace.dsl.Types -import com.intellij.debugger.streams.trace.impl.handler.type.ClassTypeImpl -import com.intellij.debugger.streams.trace.impl.handler.type.GenericType -import com.intellij.debugger.streams.trace.impl.handler.type.GenericTypeImpl +import com.intellij.debugger.streams.trace.impl.handler.type.* import com.intellij.psi.CommonClassNames /** @@ -53,8 +51,16 @@ class JavaTypes() : Types { override val stringType: GenericType = STRING override val longType: GenericType = LONG - override fun list(elementsType: GenericType): GenericType = ClassTypeImpl("java.util.List<${elementsType.genericTypeName}>") + override fun array(elementType: GenericType): ArrayType = + ArrayTypeImpl(elementType, { "$it[]" }, "new ${elementType.variableTypeName}[] {}") + + override fun map(keyType: GenericType, valueType: GenericType): MapType = + MapTypeImpl(keyType, valueType, { keys, values -> "java.util.Map<$keys, $values>" }, "new java.util.HashMap<>()") + + override fun linkedMap(keyType: GenericType, valueType: GenericType): MapType = + MapTypeImpl(keyType, valueType, { keys, values -> "java.util.Map<$keys, $values>" }, "new java.util.LinkedHashMap<>()") + + override fun list(elementsType: GenericType): ListType = + ListTypeImpl(elementsType, { "java.util.List<$it>" }, "new java.util.ArrayList<>()") - override fun map(keyType: GenericType, valueType: GenericType): GenericType = - ClassTypeImpl("java.util.Map<${keyType.genericTypeName}, ${valueType.genericTypeName}>") } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaVariableDeclaration.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaVariableDeclaration.kt index de5546840beb..d470fb75c9eb 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaVariableDeclaration.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/java/JavaVariableDeclaration.kt @@ -29,6 +29,6 @@ class JavaVariableDeclaration(override val variable: Variable, val modifier = if (!isMutable) "final " else "" val initCode = init.toCode() val right = if (initCode.trim().isEmpty()) "" else " = $initCode" - return "$modifier${variable.type} ${variable.name}$right".withIndent(indent) + return "$modifier${variable.type.variableTypeName} ${variable.name}$right".withIndent(indent) } } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinArrayVariable.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinArrayVariable.kt index 09ec903c87ab..6704be10f173 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinArrayVariable.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinArrayVariable.kt @@ -20,17 +20,17 @@ import com.intellij.debugger.streams.trace.dsl.Expression import com.intellij.debugger.streams.trace.dsl.VariableDeclaration 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.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.ArrayType /** * @author Vitaliy.Bibaev */ -class KotlinArrayVariable(override val elementType: GenericType, override val name: String) - : VariableImpl("kotlin.Array<${elementType.genericTypeName}>", name), ArrayVariable { - override fun get(index: Expression): Expression = TextExpression("$name[${index.toCode()}]") +class KotlinArrayVariable(override val type: ArrayType, override val name: String) + : VariableImpl(type, name), ArrayVariable { + override fun get(index: Expression): Expression = TextExpression("$name[${index.toCode()}]!!") override fun set(index: Expression, value: Expression): Expression = TextExpression("$name[${index.toCode()}] = ${value.toCode()}") override fun defaultDeclaration(size: Expression): VariableDeclaration = - KotlinVariableDeclaration(this, false, "kotlin.arrayOfNulls<${elementType.variableTypeName}>(${size.toCode()})") + KotlinVariableDeclaration(this, false, type.defaultValue) } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinListVariable.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinListVariable.kt index 15e10d5e0aa7..2ddf5ef55c8d 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinListVariable.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinListVariable.kt @@ -19,13 +19,13 @@ import com.intellij.debugger.streams.trace.dsl.Expression import com.intellij.debugger.streams.trace.dsl.ListVariable import com.intellij.debugger.streams.trace.dsl.VariableDeclaration import com.intellij.debugger.streams.trace.dsl.impl.VariableImpl -import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.ListType /** * @author Vitaliy.Bibaev */ -class KotlinListVariable(override val elementType: GenericType, name: String) - : VariableImpl("kotlin.collections.MutableList<${elementType.genericTypeName}>", name), ListVariable { +class KotlinListVariable(override val type: ListType, name: String) + : VariableImpl(type, name), ListVariable { override fun get(index: Expression): Expression = call("get", index) override fun set(index: Expression, newValue: Expression): Expression = call("set", index, newValue) override fun add(element: Expression): Expression = call("add", element) @@ -35,5 +35,5 @@ class KotlinListVariable(override val elementType: GenericType, name: String) override fun size(): Expression = property("size") override fun defaultDeclaration(): VariableDeclaration = - KotlinVariableDeclaration(this, false, "mutableListOf<${elementType.genericTypeName}>()") + KotlinVariableDeclaration(this, false, type.defaultValue) } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinMapVariable.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinMapVariable.kt index 58a9a3063a6d..885ff0f864a2 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinMapVariable.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinMapVariable.kt @@ -17,24 +17,15 @@ package com.intellij.debugger.streams.trace.dsl.impl.kotlin import com.intellij.debugger.streams.trace.dsl.Expression import com.intellij.debugger.streams.trace.dsl.Lambda -import com.intellij.debugger.streams.trace.dsl.Statement import com.intellij.debugger.streams.trace.dsl.VariableDeclaration import com.intellij.debugger.streams.trace.dsl.impl.TextExpression import com.intellij.debugger.streams.trace.dsl.impl.common.MapVariableBase -import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.MapType /** * @author Vitaliy.Bibaev */ -class KotlinMapVariable(keyType: GenericType, - valueType: GenericType, - name: String, - linked: Boolean) - : MapVariableBase(keyType, valueType, "${getType(linked)}<${keyType.genericTypeName}, ${valueType.genericTypeName}>", name) { - companion object { - fun getType(linked: Boolean): String = "kotlin.collections.${if (linked) "Linked" else ""}HashMap" - } - +class KotlinMapVariable(type: MapType, name: String) : MapVariableBase(type, name) { override fun get(key: Expression): Expression = TextExpression("${toCode()}[${key.toCode()}]") override fun set(key: Expression, newValue: Expression): Expression = @@ -50,5 +41,5 @@ class KotlinMapVariable(keyType: GenericType, TextExpression("${toCode()}.getOrPut(${key.toCode()}, ${supplier.toCode()}") override fun defaultDeclaration(isMutable: Boolean): VariableDeclaration = - KotlinVariableDeclaration(this, false, "mutableMapOf()") + KotlinVariableDeclaration(this, false, type.defaultValue) } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinStatementFactory.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinStatementFactory.kt index e43a91e93cfb..239c7b25ad5e 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinStatementFactory.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinStatementFactory.kt @@ -30,7 +30,7 @@ class KotlinStatementFactory : StatementFactory { override fun createNewListExpression(elementType: GenericType, vararg args: Expression): Expression = TextExpression("kotlin.collections.mutableListOf<${elementType.genericTypeName}>(${StatementFactory.commaSeparate(*args)})") - override fun createListVariable(elementType: GenericType, name: String): ListVariable = KotlinListVariable(elementType, name) + override fun createListVariable(elementType: GenericType, name: String): ListVariable = KotlinListVariable(types.list(elementType), name) override fun not(expression: Expression): Expression = TextExpression("!${expression.toCode()}") @@ -59,7 +59,7 @@ class KotlinStatementFactory : StatementFactory { override fun createLambda(argName: String, lambdaBody: LambdaBody): Lambda = KotlinLambda(argName, lambdaBody) - override fun createVariable(type: GenericType, name: String): Variable = VariableImpl(type.variableTypeName, name) + override fun createVariable(type: GenericType, name: String): Variable = VariableImpl(type, name) override fun and(left: Expression, right: Expression): Expression = TextExpression("${left.toCode()} && ${right.toCode()}") @@ -74,9 +74,10 @@ class KotlinStatementFactory : StatementFactory { KotlinAssignmentStatement(variable, expression) override fun createMapVariable(keyType: GenericType, valueType: GenericType, name: String, linked: Boolean): MapVariable = - KotlinMapVariable(keyType, valueType, name, linked) + KotlinMapVariable(if (linked) types.linkedMap(keyType, valueType) else types.map(keyType, valueType), name) - override fun createArrayVariable(elementType: GenericType, name: String): ArrayVariable = KotlinArrayVariable(elementType, name) + override fun createArrayVariable(elementType: GenericType, name: String): ArrayVariable = + KotlinArrayVariable(types.array(elementType), name) override fun createScope(codeBlock: CodeBlock): Convertable = object : Convertable { diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinTryBlock.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinTryBlock.kt index d3ab39c27e67..54a165fa479d 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinTryBlock.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinTryBlock.kt @@ -27,7 +27,7 @@ class KotlinTryBlock(private val block: CodeBlock, statementFactory: StatementFa val descriptor = myCatchDescriptor ?: error("catch block must be specified") return "try {\n".withIndent(indent) + block.toCode(indent + 1) + - "} catch(${descriptor.variable.name} : ${descriptor.variable.type}) {\n" + + "} catch(${descriptor.variable.name} : ${descriptor.variable.type.variableTypeName}) {\n" + descriptor.block.toCode(indent + 1) + "}".withIndent(indent) } diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinTypes.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinTypes.kt index 13fa36d87b17..181e85d2c0f0 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinTypes.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinTypes.kt @@ -16,8 +16,7 @@ package com.intellij.debugger.streams.trace.dsl.impl.kotlin import com.intellij.debugger.streams.trace.dsl.Types -import com.intellij.debugger.streams.trace.impl.handler.type.ClassTypeImpl -import com.intellij.debugger.streams.trace.impl.handler.type.GenericType +import com.intellij.debugger.streams.trace.impl.handler.type.* /** * @author Vitaliy.Bibaev @@ -34,12 +33,20 @@ class KotlinTypes private constructor() : Types by KotlinTypes { override val timeVariableType: GenericType = ClassTypeImpl("java.util.concurrent.atomic.AtomicInteger", "new java.util.concurrent.atomic.AtomicInteger()") - override fun list(elementsType: GenericType): GenericType = - ClassTypeImpl("kotlin.collections.List<${elementsType.genericTypeName}>", - "kotlin.collections.ArrayList<${elementsType.genericTypeName}>()") + override fun list(elementsType: GenericType): ListType = + ListTypeImpl(elementsType, { "kotlin.collections.MutableList<$it>" }, "kotlin.collections.mutableListOf()") - override fun map(keyType: GenericType, valueType: GenericType): GenericType = - ClassTypeImpl("kotlin.collections.Map<${keyType.genericTypeName}, ${valueType.genericTypeName}>", - "kotlin.collections.HashMap<${keyType.genericTypeName}, ${valueType.genericTypeName}>()") + override fun array(elementType: GenericType): ArrayType = + ArrayTypeImpl(elementType, { "kotlin.Array<$it?>" }, "kotlin.arrayOfNulls(1)") + + override fun map(keyType: GenericType, valueType: GenericType): MapType = + MapTypeImpl(keyType, valueType, + { keys, values -> "kotlin.collections.MutableMap<$keys, $values>" }, + "kotlin.collections.mutableMapOf()") + + override fun linkedMap(keyType: GenericType, valueType: GenericType): MapType = + MapTypeImpl(keyType, valueType, + { keys, values -> "kotlin.collections.MutableMap<$keys, $values>" }, + "kotlin.collections.linkedMapOf()") } } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinVariableDeclaration.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinVariableDeclaration.kt index 1b94d5880a14..e9b67ff20156 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinVariableDeclaration.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/dsl/impl/kotlin/KotlinVariableDeclaration.kt @@ -27,6 +27,6 @@ class KotlinVariableDeclaration(override val variable: Variable, override fun toCode(indent: Int): String { val prefix = if (isMutable) "var" else "var" val suffix = if (init.trim().isEmpty()) "" else " = $init" - return "$prefix ${variable.name}: ${variable.type}$suffix".withIndent(indent) + return "$prefix ${variable.name}: ${variable.type.variableTypeName}$suffix".withIndent(indent) } } \ No newline at end of file diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/impl/handler/unified/DistinctTraceHandler.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/impl/handler/unified/DistinctTraceHandler.kt index 28628103ca3c..1771bc4a6281 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/impl/handler/unified/DistinctTraceHandler.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/impl/handler/unified/DistinctTraceHandler.kt @@ -38,11 +38,11 @@ class DistinctTraceHandler(num: Int, private val myCall: IntermediateStreamCall, val mapping = linkedMap(types.integerType, types.integerType, "mapping") declare(mapping.defaultDeclaration()) val eqClasses = map(myCall.typeBefore, nestedMapType, "eqClasses") - declare(eqClasses, false) + declare(eqClasses, TextExpression(eqClasses.type.defaultValue), false) forEachLoop(variable(types.integerType, "beforeTime"), before.keys()) { val beforeValue = declare(variable(myCall.typeBefore, "beforeValue"), before.get(loopVariable), false) +eqClasses.computeIfAbsent(beforeValue, lambda("key") { - +nestedMapType.defaultValue + +TextExpression(nestedMapType.defaultValue) }) } @@ -52,7 +52,7 @@ class DistinctTraceHandler(num: Int, private val myCall: IntermediateStreamCall, val classes = map(types.integerType, myCall.typeBefore, "classes") declare(classes, eqClasses.get(afterValue), false) forEachLoop(variable(types.integerType, "classElementTime"), classes.keys()) { - mapping.set(loopVariable, afterTime) + +mapping.set(loopVariable, afterTime) } } diff --git a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/impl/handler/unified/MatchHandler.kt b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/impl/handler/unified/MatchHandler.kt index 6606ce569adc..3a8f91695761 100644 --- a/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/impl/handler/unified/MatchHandler.kt +++ b/plugins/stream-debugger/src/main/java/com/intellij/debugger/streams/trace/impl/handler/unified/MatchHandler.kt @@ -82,7 +82,7 @@ class MatchHandler(private val call: TerminatorStreamCall, dsl: Dsl) : HandlerBa override fun additionalCallsBefore(): List { val result = ArrayList(myBeforePeekInserter.additionalCallsBefore()) val filterPredicate = (if (call.name == "allMatch") myPredicateVariable.call("negate") else myPredicateVariable).toCode() - val filterArg = CallArgumentImpl(myPredicateVariable.type, filterPredicate) + val filterArg = CallArgumentImpl(myPredicateVariable.type.variableTypeName, filterPredicate) result += IntermediateStreamCallImpl("filter", listOf(filterArg), call.typeBefore, call.typeBefore, TextRange.EMPTY_RANGE, call.packageName) return result