Add ability to use arrays variables in dsl

This commit is contained in:
Vitaliy.Bibaev
2017-09-06 19:30:18 +03:00
parent abfc002207
commit 61cebec550
7 changed files with 74 additions and 1 deletions
@@ -0,0 +1,31 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.streams.trace.dsl
import com.intellij.debugger.streams.trace.dsl.impl.TextExpression
/**
* @author Vitaliy.Bibaev
*/
interface ArrayVariable : Variable {
val elementType: String
operator fun get(index: Expression): Expression
operator fun get(index: Int): Expression = get(TextExpression(index.toString()))
operator fun set(index: Expression, value: Expression): Expression
operator fun set(index: Int, value: Expression): Expression = set(TextExpression(index.toString()), value)
}
@@ -26,6 +26,8 @@ interface DslFactory {
fun variable(type: String, name: String): Variable
fun array(elementType: String, name: String): ArrayVariable
fun map(keyType: GenericType, valueType: GenericType, name: String): MapVariable
fun linkedMap(keyType: GenericType, valueType: GenericType, name: String): MapVariable
@@ -55,4 +55,6 @@ interface StatementFactory {
fun createAssignmentStatement(variable: Variable, expression: Expression): AssignmentStatement
fun createMapVariable(keyType: GenericType, valueType: GenericType, name: String, linked: Boolean): MapVariable
fun createArrayVariable(elementType: String, name: String): ArrayVariable
}
@@ -34,6 +34,8 @@ class DslImpl(override val statementFactory: StatementFactory) : Dsl {
return fragment.toCode(0)
}
override fun array(elementType: String, name: String): ArrayVariable = statementFactory.createArrayVariable(elementType, name)
override fun map(keyType: GenericType, valueType: GenericType, name: String): MapVariable =
statementFactory.createMapVariable(keyType, valueType, name, false)
@@ -0,0 +1,30 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.streams.trace.dsl.impl.java
import com.intellij.debugger.streams.trace.dsl.ArrayVariable
import com.intellij.debugger.streams.trace.dsl.Expression
import com.intellij.debugger.streams.trace.dsl.impl.TextExpression
import com.intellij.debugger.streams.trace.dsl.impl.VariableImpl
/**
* @author Vitaliy.Bibaev
*/
class JavaArrayVariable(override val elementType: String, name: String) : VariableImpl("$elementType[]", 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()}")
}
@@ -69,4 +69,6 @@ class JavaStatementFactory : StatementFactory {
override fun createMapVariable(keyType: GenericType, valueType: GenericType, name: String, linked: Boolean): MapVariable =
JavaMapVariable(keyType, valueType, name, linked)
}
override fun createArrayVariable(elementType: String, name: String): ArrayVariable = JavaArrayVariable(elementType, name)
}
@@ -89,4 +89,8 @@ class KotlinStatementFactory : StatementFactory {
override fun createMapVariable(keyType: GenericType, valueType: GenericType, name: String, linked: Boolean): MapVariable {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun createArrayVariable(elementType: String, name: String): ArrayVariable {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}