Implement jspecify marks processing in the tests properly, by adding specific handler and cleanuper

This commit is contained in:
Victor Petukhov
2021-04-16 14:26:38 +03:00
parent b9536a25d6
commit e93133a28f
39 changed files with 246 additions and 307 deletions
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.codeMetaInfo
import com.intellij.util.containers.Stack
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
import java.io.File
@@ -55,21 +54,24 @@ object CodeMetaInfoRenderer {
checkOpenedAndCloseStringIfNeeded(opened, offset, builder)
val matchedCodeMetaInfos = sortedMetaInfos[offset] ?: emptyList()
if (matchedCodeMetaInfos.isNotEmpty()) {
openStartTag(builder)
val iterator = matchedCodeMetaInfos.listIterator()
var current: CodeMetaInfo? = iterator.next()
if (current != null) builder.append(current.tagPrefix)
while (current != null) {
val next: CodeMetaInfo? = if (iterator.hasNext()) iterator.next() else null
opened.push(current)
builder.append(current.asString())
when {
next == null ->
closeStartTag(builder)
builder.append(current.tagPostfix)
next.end == current.end ->
builder.append(", ")
else ->
closeStartAndOpenNewTag(builder)
else -> {
builder.append(current.tagPostfix)
builder.append(next.tagPrefix)
}
}
current = next
}
@@ -84,16 +86,11 @@ object CodeMetaInfoRenderer {
return metaInfos.sortedWith(metaInfoComparator)
}
private fun closeString(result: StringBuilder) = result.append("<!>")
private fun openStartTag(result: StringBuilder) = result.append("<!")
private fun closeStartTag(result: StringBuilder) = result.append("!>")
private fun closeStartAndOpenNewTag(result: StringBuilder) = result.append("!><!")
private fun checkOpenedAndCloseStringIfNeeded(opened: Stack<CodeMetaInfo>, end: Int, result: StringBuilder) {
var prev: CodeMetaInfo? = null
while (!opened.isEmpty() && end == opened.peek().end) {
if (prev == null || prev.start != opened.peek().start)
closeString(result)
result.append(opened.peek().closingTag)
prev = opened.pop()
}
}
@@ -14,5 +14,9 @@ interface CodeMetaInfo {
val renderConfiguration: AbstractCodeMetaInfoRenderConfiguration
val attributes: MutableList<String>
val tagPrefix: String get() = "<!"
val tagPostfix: String get() = "!>"
val closingTag: String get() = "<!>"
fun asString(): String
}
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codeMetaInfo.model
import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.JspecifyCodeMetaInfoRenderConfiguration
class JspecifyMarkerCodeMetaInfo(
override val start: Int,
override val end: Int,
val offset: Int,
val name: String
) : CodeMetaInfo {
override val tagPrefix = "\n${" ".repeat(offset)}// "
override val tagPostfix = ""
override val closingTag = ""
override val renderConfiguration = JspecifyCodeMetaInfoRenderConfiguration
override val tag = renderConfiguration.getTag(this)
override val attributes: MutableList<String> = mutableListOf()
override fun asString(): String = renderConfiguration.asString(this)
}
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codeMetaInfo.renderConfigurations
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
import org.jetbrains.kotlin.codeMetaInfo.model.JspecifyMarkerCodeMetaInfo
object JspecifyCodeMetaInfoRenderConfiguration : AbstractCodeMetaInfoRenderConfiguration() {
override fun asString(codeMetaInfo: CodeMetaInfo): String {
if (codeMetaInfo !is JspecifyMarkerCodeMetaInfo) return ""
return getTag(codeMetaInfo)
}
fun getTag(codeMetaInfo: JspecifyMarkerCodeMetaInfo): String {
return codeMetaInfo.name
}
}