Skip to content

Commit

Permalink
Rewrite toString() method for JcNewArray and JcRawNewArray
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniilStepanov committed Nov 21, 2023
1 parent 187d0af commit 4959daa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
19 changes: 12 additions & 7 deletions jacodb-api/src/main/kotlin/org/jacodb/api/cfg/JcInst.kt
Original file line number Diff line number Diff line change
Expand Up @@ -606,17 +606,22 @@ data class JcNewArrayExpr(
override val operands: List<JcValue>
get() = dimensions

override fun toString(): String {
var curDim = 0
val typeNameWithDimensions = Regex("\\[(.*?)]").replace(type.typeName) {
"[${dimensions.getOrNull(curDim++) ?: ""}]"
}
return "new $typeNameWithDimensions"
}
override fun toString(): String = "new ${arrayTypeToStringWithDimensions(type.typeName, dimensions)}"

override fun <T> accept(visitor: JcExprVisitor<T>): T {
return visitor.visitJcNewArrayExpr(this)
}

companion object {
private val regexToProcessDimensions = Regex("\\[(.*?)]")

private fun arrayTypeToStringWithDimensions(typeName: String, dimensions: List<JcValue>) {
var curDim = 0
regexToProcessDimensions.replace(typeName) {
"[${dimensions.getOrNull(curDim++) ?: ""}]"
}
}
}
}

data class JcInstanceOfExpr(
Expand Down
19 changes: 12 additions & 7 deletions jacodb-api/src/main/kotlin/org/jacodb/api/cfg/JcRawInst.kt
Original file line number Diff line number Diff line change
Expand Up @@ -609,17 +609,22 @@ data class JcRawNewArrayExpr(
override val operands: List<JcRawValue>
get() = dimensions

override fun toString(): String {
var curDim = 0
val typeNameWithDimensions = Regex("\\[(.*?)]").replace("$typeName") {
"[${dimensions.getOrNull(curDim++) ?: ""}]"
}
return "new $typeNameWithDimensions"
}
override fun toString(): String = "new ${arrayTypeToStringWithDimensions(typeName, dimensions)}"

override fun <T> accept(visitor: JcRawExprVisitor<T>): T {
return visitor.visitJcRawNewArrayExpr(this)
}

companion object {
private val regexToProcessDimensions = Regex("\\[(.*?)]")

private fun arrayTypeToStringWithDimensions(typeName: TypeName, dimensions: List<JcRawValue>) {
var curDim = 0
regexToProcessDimensions.replace("$typeName") {
"[${dimensions.getOrNull(curDim++) ?: ""}]"
}
}
}
}

data class JcRawInstanceOfExpr(
Expand Down

0 comments on commit 4959daa

Please sign in to comment.