[CMI] Extract core of CodeMetaInfo to :compiler:tests-common

This commit is contained in:
Dmitriy Novozhilov
2020-11-03 12:55:44 +03:00
parent 4ad9f48642
commit 25c011ca40
15 changed files with 364 additions and 291 deletions
@@ -34,14 +34,18 @@ import org.jetbrains.kotlin.checkers.diagnostics.SyntaxErrorDiagnostic
import org.jetbrains.kotlin.checkers.diagnostics.factories.DebugInfoDiagnosticFactory0
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil
import org.jetbrains.kotlin.checkers.utils.DiagnosticsRenderingConfiguration
import org.jetbrains.kotlin.codeMetaInfo.CodeMetaInfoParser
import org.jetbrains.kotlin.codeMetaInfo.CodeMetaInfoRenderer
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
import org.jetbrains.kotlin.codeMetaInfo.model.DiagnosticCodeMetaInfo
import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.AbstractCodeMetaInfoRenderConfiguration
import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.DiagnosticCodeMetaInfoRenderConfiguration
import org.jetbrains.kotlin.daemon.common.OSKind
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.diagnostics.AbstractDiagnostic
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.codeMetaInfo.models.*
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.AbstractCodeMetaInfoRenderConfiguration
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.DiagnosticCodeMetaInfoRenderConfiguration
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.HighlightingRenderConfiguration
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.LineMarkerRenderConfiguration
import org.jetbrains.kotlin.idea.multiplatform.setupMppProjectFromTextFile
@@ -193,17 +197,14 @@ class CodeMetaInfoTestCase(
assert(
diagnostics.any { diagnosticCodeMetaInfo ->
diagnosticCodeMetaInfo.start == highlightingCodeMetaInfo.start &&
when (diagnosticCodeMetaInfo.diagnostic) {
when (val diagnostic = diagnosticCodeMetaInfo.diagnostic) {
is SyntaxErrorDiagnostic -> {
val diagnostic: SyntaxErrorDiagnostic = diagnosticCodeMetaInfo.diagnostic
(highlightingCodeMetaInfo as HighlightingCodeMetaInfo).highlightingInfo.description in (diagnostic.psiElement as PsiErrorElementImpl).errorDescription
}
is AbstractDiagnostic<*> -> {
val diagnostic: AbstractDiagnostic<*> = diagnosticCodeMetaInfo.diagnostic
diagnostic.factory.toString() in (highlightingCodeMetaInfo as HighlightingCodeMetaInfo).highlightingInfo.description
}
is DebugInfoDiagnostic -> {
val diagnostic: DebugInfoDiagnostic = diagnosticCodeMetaInfo.diagnostic
diagnostic.factory == DebugInfoDiagnosticFactory0.MISSING_UNRESOLVED &&
"[DEBUG] Reference is not resolved to anything, but is not marked unresolved" in (highlightingCodeMetaInfo as HighlightingCodeMetaInfo).highlightingInfo.description
}
@@ -279,4 +280,4 @@ abstract class AbstractCodeMetaInfoTest : AbstractMultiModuleTest() {
}
return testSourcePath.toFile()
}
}
}
@@ -1,65 +0,0 @@
/*
* 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.idea.codeMetaInfo
import com.intellij.util.containers.Stack
import org.jetbrains.kotlin.idea.codeMetaInfo.models.ParsedCodeMetaInfo
import org.junit.Assert
object CodeMetaInfoParser {
private val openingRegex = "(<!([^>]+?)!>)".toRegex()
private val closingRegex = "(<!>)".toRegex()
private val descriptionRegex = "\\(\".*?\"\\)".toRegex()
private val platformRegex = "\\{(.+)}".toRegex()
fun getCodeMetaInfoFromText(renderedText: String): List<ParsedCodeMetaInfo> {
var text = renderedText
val openingMatchResults = Stack<MatchResult>()
val closingMatchResults = Stack<MatchResult>()
val result = mutableListOf<ParsedCodeMetaInfo>()
while (true) {
var openingStartOffset = Int.MAX_VALUE
var closingStartOffset = Int.MAX_VALUE
val opening = openingRegex.find(text)
val closing = closingRegex.find(text)
if (opening == null && closing == null) break
if (opening != null)
openingStartOffset = opening.range.first
if (closing != null)
closingStartOffset = closing.range.first
text = if (openingStartOffset < closingStartOffset) {
openingMatchResults.push(opening)
text.removeRange(openingStartOffset, opening!!.range.last + 1)
} else {
closingMatchResults.push(closing)
text.removeRange(closingStartOffset, closing!!.range.last + 1)
}
}
if (openingMatchResults.size != closingMatchResults.size) {
Assert.fail("Opening and closing tags counts are not equals")
}
while (!openingMatchResults.isEmpty()) {
val openingMatchResult = openingMatchResults.pop()
val closingMatchResult = closingMatchResults.pop()
val metaInfoWithoutParams = openingMatchResult.groups[2]!!.value.replace(descriptionRegex, "")
metaInfoWithoutParams.split(",").forEach {
val tag = platformRegex.replace(it, "").trim()
val platforms =
if (platformRegex.containsMatchIn(it)) platformRegex.find(it)!!.destructured.component1().split(";") else listOf()
result.add(
ParsedCodeMetaInfo(
openingMatchResult.range.first, closingMatchResult.range.first, platforms.toMutableList(), tag,
)
)
}
}
return result
}
}
@@ -1,80 +0,0 @@
/*
* 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.idea.codeMetaInfo
import com.intellij.util.containers.Stack
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil
import org.jetbrains.kotlin.idea.codeMetaInfo.models.CodeMetaInfo
import java.io.File
object CodeMetaInfoRenderer {
fun renderTagsToText(
codeMetaInfos: List<CodeMetaInfo>,
originalText: String
): StringBuffer {
val result = StringBuffer()
if (codeMetaInfos.isEmpty()) {
result.append(originalText)
return result
}
val sortedMetaInfos = getSortedCodeMetaInfos(codeMetaInfos)
val opened = Stack<CodeMetaInfo>()
for ((i, c) in originalText.withIndex()) {
checkOpenedAndCloseStringIfNeeded(opened, i, result)
val matchedCodeMetaInfos = sortedMetaInfos.filter { it.start == i }
if (matchedCodeMetaInfos.isNotEmpty()) {
openStartTag(result)
val iterator = matchedCodeMetaInfos.listIterator()
var current: CodeMetaInfo? = iterator.next()
while (current != null) {
val next: CodeMetaInfo? = if (iterator.hasNext()) iterator.next() else null
opened.push(current)
result.append(current.asString())
when {
next == null ->
closeStartTag(result)
next.end == current.end ->
result.append(", ")
else ->
closeStartAndOpenNewTag(result)
}
current = next
}
}
result.append(c)
}
checkOpenedAndCloseStringIfNeeded(opened, originalText.length, result)
return result
}
private fun getSortedCodeMetaInfos(metaInfos: Collection<CodeMetaInfo>): List<CodeMetaInfo> {
return metaInfos.sortedWith(compareBy<CodeMetaInfo> { it.start }.then(compareByDescending { it.end }))
}
private fun closeString(result: StringBuffer) = result.append("<!>")
private fun openStartTag(result: StringBuffer) = result.append("<!")
private fun closeStartTag(result: StringBuffer) = result.append("!>")
private fun closeStartAndOpenNewTag(result: StringBuffer) = result.append("!><!")
private fun checkOpenedAndCloseStringIfNeeded(opened: Stack<CodeMetaInfo>, end: Int, result: StringBuffer) {
var prev: CodeMetaInfo? = null
while (!opened.isEmpty() && end == opened.peek().end) {
if (prev == null || prev.start != opened.peek().start)
closeString(result)
prev = opened.pop()
}
}
}
fun clearFileFromDiagnosticMarkup(file: File) {
val text = file.readText()
val cleanText = clearTextFromDiagnosticMarkup(text)
file.writeText(cleanText)
}
fun clearTextFromDiagnosticMarkup(text: String): String = CheckerTestUtil.rangeStartOrEndPattern.matcher(text).replaceAll("")
@@ -1,125 +0,0 @@
/*
* 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.idea.codeMetaInfo.models
import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.impl.HighlightInfo
import org.jetbrains.kotlin.checkers.diagnostics.ActualDiagnostic
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.AbstractCodeMetaInfoRenderConfiguration
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.DiagnosticCodeMetaInfoRenderConfiguration
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.HighlightingRenderConfiguration
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.LineMarkerRenderConfiguration
import org.jetbrains.kotlin.idea.editor.fixers.end
import org.jetbrains.kotlin.idea.editor.fixers.start
interface CodeMetaInfo {
val start: Int
val end: Int
val renderConfiguration: AbstractCodeMetaInfoRenderConfiguration
val platforms: MutableList<String>
fun asString(): String
fun getTag(): String
}
class DiagnosticCodeMetaInfo(
override val start: Int,
override val end: Int,
override val renderConfiguration: DiagnosticCodeMetaInfoRenderConfiguration,
val diagnostic: Diagnostic
) : CodeMetaInfo {
override val platforms: MutableList<String> = mutableListOf()
override fun asString(): String = renderConfiguration.asString(this)
override fun getTag(): String = renderConfiguration.getTag(this)
}
class LineMarkerCodeMetaInfo(
override val renderConfiguration: LineMarkerRenderConfiguration,
val lineMarker: LineMarkerInfo<*>
) : CodeMetaInfo {
override val start: Int
get() = lineMarker.startOffset
override val end: Int
get() = lineMarker.endOffset
override val platforms: MutableList<String> = mutableListOf()
override fun asString(): String = renderConfiguration.asString(this)
override fun getTag(): String = renderConfiguration.getTag()
}
class HighlightingCodeMetaInfo(
override val renderConfiguration: HighlightingRenderConfiguration,
val highlightingInfo: HighlightInfo
) : CodeMetaInfo {
override val start: Int
get() = highlightingInfo.startOffset
override val end: Int
get() = highlightingInfo.endOffset
override val platforms: MutableList<String> = mutableListOf()
override fun asString(): String = renderConfiguration.asString(this)
override fun getTag(): String = renderConfiguration.getTag()
}
class ParsedCodeMetaInfo(
override val start: Int,
override val end: Int,
override val platforms: MutableList<String>,
private val tag: String
) : CodeMetaInfo {
override val renderConfiguration = object : AbstractCodeMetaInfoRenderConfiguration(false) {}
override fun asString(): String = renderConfiguration.asString(this)
override fun getTag(): String = tag
override fun equals(other: Any?): Boolean {
if (other == null || other !is CodeMetaInfo) return false
return this.tag == other.getTag() && this.start == other.start && this.end == other.end
}
override fun hashCode(): Int {
var result = start
result = 31 * result + end
result = 31 * result + tag.hashCode()
return result
}
}
fun createCodeMetaInfo(obj: Any, renderConfiguration: AbstractCodeMetaInfoRenderConfiguration): List<CodeMetaInfo> {
fun errorMessage() = "Unexpected render configuration for object $obj"
return when (obj) {
is Diagnostic -> {
require(renderConfiguration is DiagnosticCodeMetaInfoRenderConfiguration, ::errorMessage)
obj.textRanges.map { DiagnosticCodeMetaInfo(it.start, it.end, renderConfiguration, obj) }
}
is ActualDiagnostic -> {
require(renderConfiguration is DiagnosticCodeMetaInfoRenderConfiguration, ::errorMessage)
obj.diagnostic.textRanges.map { DiagnosticCodeMetaInfo(it.start, it.end, renderConfiguration, obj.diagnostic) }
}
is HighlightInfo -> {
require(renderConfiguration is HighlightingRenderConfiguration, ::errorMessage)
listOf(HighlightingCodeMetaInfo(renderConfiguration, obj))
}
is LineMarkerInfo<*> -> {
require(renderConfiguration is LineMarkerRenderConfiguration, ::errorMessage)
listOf(LineMarkerCodeMetaInfo(renderConfiguration, obj))
}
else -> throw IllegalArgumentException("Unknown type for creating CodeMetaInfo object $obj")
}
}
fun getCodeMetaInfo(
objects: List<Any>,
renderConfiguration: AbstractCodeMetaInfoRenderConfiguration
): List<CodeMetaInfo> {
return objects.flatMap { createCodeMetaInfo(it, renderConfiguration) }
}
@@ -0,0 +1,49 @@
/*
* 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.idea.codeMetaInfo.models
import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.impl.HighlightInfo
import org.jetbrains.kotlin.checkers.diagnostics.ActualDiagnostic
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
import org.jetbrains.kotlin.codeMetaInfo.model.DiagnosticCodeMetaInfo
import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.AbstractCodeMetaInfoRenderConfiguration
import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.DiagnosticCodeMetaInfoRenderConfiguration
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.HighlightingRenderConfiguration
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.LineMarkerRenderConfiguration
import org.jetbrains.kotlin.idea.editor.fixers.end
import org.jetbrains.kotlin.idea.editor.fixers.start
fun createCodeMetaInfo(obj: Any, renderConfiguration: AbstractCodeMetaInfoRenderConfiguration): List<CodeMetaInfo> {
fun errorMessage() = "Unexpected render configuration for object $obj"
return when (obj) {
is Diagnostic -> {
require(renderConfiguration is DiagnosticCodeMetaInfoRenderConfiguration, ::errorMessage)
obj.textRanges.map { DiagnosticCodeMetaInfo(it.start, it.end, renderConfiguration, obj) }
}
is ActualDiagnostic -> {
require(renderConfiguration is DiagnosticCodeMetaInfoRenderConfiguration, ::errorMessage)
obj.diagnostic.textRanges.map { DiagnosticCodeMetaInfo(it.start, it.end, renderConfiguration, obj.diagnostic) }
}
is HighlightInfo -> {
require(renderConfiguration is HighlightingRenderConfiguration, ::errorMessage)
listOf(HighlightingCodeMetaInfo(renderConfiguration, obj))
}
is LineMarkerInfo<*> -> {
require(renderConfiguration is LineMarkerRenderConfiguration, ::errorMessage)
listOf(LineMarkerCodeMetaInfo(renderConfiguration, obj))
}
else -> throw IllegalArgumentException("Unknown type for creating CodeMetaInfo object $obj")
}
}
fun getCodeMetaInfo(
objects: List<Any>,
renderConfiguration: AbstractCodeMetaInfoRenderConfiguration
): List<CodeMetaInfo> {
return objects.flatMap { createCodeMetaInfo(it, renderConfiguration) }
}
@@ -0,0 +1,25 @@
/*
* 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.idea.codeMetaInfo.models
import com.intellij.codeInsight.daemon.impl.HighlightInfo
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.HighlightingRenderConfiguration
class HighlightingCodeMetaInfo(
override val renderConfiguration: HighlightingRenderConfiguration,
val highlightingInfo: HighlightInfo
) : CodeMetaInfo {
override val start: Int
get() = highlightingInfo.startOffset
override val end: Int
get() = highlightingInfo.endOffset
override val platforms: MutableList<String> = mutableListOf()
override fun asString(): String = renderConfiguration.asString(this)
override fun getTag(): String = renderConfiguration.getTag()
}
@@ -0,0 +1,25 @@
/*
* 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.idea.codeMetaInfo.models
import com.intellij.codeInsight.daemon.LineMarkerInfo
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
import org.jetbrains.kotlin.idea.codeMetaInfo.renderConfigurations.LineMarkerRenderConfiguration
class LineMarkerCodeMetaInfo(
override val renderConfiguration: LineMarkerRenderConfiguration,
val lineMarker: LineMarkerInfo<*>
) : CodeMetaInfo {
override val start: Int
get() = lineMarker.startOffset
override val end: Int
get() = lineMarker.endOffset
override val platforms: MutableList<String> = mutableListOf()
override fun asString(): String = renderConfiguration.asString(this)
override fun getTag(): String = renderConfiguration.getTag()
}
@@ -1,142 +0,0 @@
/*
* 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.idea.codeMetaInfo.renderConfigurations
import com.intellij.openapi.util.text.StringUtil
import com.intellij.util.containers.ContainerUtil
import org.jetbrains.kotlin.checkers.diagnostics.factories.DebugInfoDiagnosticFactory1
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.rendering.*
import org.jetbrains.kotlin.idea.codeMetaInfo.models.DiagnosticCodeMetaInfo
import org.jetbrains.kotlin.idea.codeMetaInfo.models.HighlightingCodeMetaInfo
import org.jetbrains.kotlin.idea.codeMetaInfo.models.CodeMetaInfo
import org.jetbrains.kotlin.idea.codeMetaInfo.models.LineMarkerCodeMetaInfo
abstract class AbstractCodeMetaInfoRenderConfiguration(var renderParams: Boolean = true) {
private val clickOrPressRegex = "Click or press (.*)to navigate".toRegex() // We have different hotkeys on different platforms
open fun asString(codeMetaInfo: CodeMetaInfo) = codeMetaInfo.getTag() + getPlatformsString(codeMetaInfo)
open fun getAdditionalParams(codeMetaInfo: CodeMetaInfo) = ""
protected fun sanitizeLineMarkerTooltip(originalText: String?): String {
if (originalText == null) return "null"
val noHtmlTags = StringUtil.removeHtmlTags(originalText)
.replace(" ", "")
.replace(clickOrPressRegex, "")
.trim()
return sanitizeLineBreaks(noHtmlTags)
}
protected fun sanitizeLineBreaks(originalText: String): String {
var sanitizedText = originalText
sanitizedText = StringUtil.replace(sanitizedText, "\r\n", " ")
sanitizedText = StringUtil.replace(sanitizedText, "\n", " ")
sanitizedText = StringUtil.replace(sanitizedText, "\r", " ")
return sanitizedText
}
protected fun getPlatformsString(codeMetaInfo: CodeMetaInfo): String {
if (codeMetaInfo.platforms.isEmpty()) return ""
return "{${codeMetaInfo.platforms.joinToString(";")}}"
}
}
open class DiagnosticCodeMetaInfoRenderConfiguration(
val withNewInference: Boolean = true,
val renderSeverity: Boolean = false
) : AbstractCodeMetaInfoRenderConfiguration() {
private val crossPlatformLineBreak = """\r?\n""".toRegex()
override fun asString(codeMetaInfo: CodeMetaInfo): String {
if (codeMetaInfo !is DiagnosticCodeMetaInfo) return ""
return (getTag(codeMetaInfo)
+ getPlatformsString(codeMetaInfo)
+ getParamsString(codeMetaInfo))
.replace(crossPlatformLineBreak, "")
}
private fun getParamsString(codeMetaInfo: DiagnosticCodeMetaInfo): String {
if (!renderParams) return ""
val params = mutableListOf<String>()
@Suppress("UNCHECKED_CAST")
val renderer = when (codeMetaInfo.diagnostic.factory) {
is DebugInfoDiagnosticFactory1 -> DiagnosticWithParameters1Renderer(
"{0}",
Renderers.TO_STRING
) as DiagnosticRenderer<Diagnostic>
else -> DefaultErrorMessages.getRendererForDiagnostic(codeMetaInfo.diagnostic)
}
if (renderer is AbstractDiagnosticWithParametersRenderer) {
val renderParameters = renderer.renderParameters(codeMetaInfo.diagnostic)
params.addAll(ContainerUtil.map(renderParameters) { it.toString() })
}
if (renderSeverity)
params.add("severity='${codeMetaInfo.diagnostic.severity}'")
params.add(getAdditionalParams(codeMetaInfo))
return "(\"${params.filter { it.isNotEmpty() }.joinToString("; ")}\")"
}
fun getTag(codeMetaInfo: DiagnosticCodeMetaInfo): String {
return codeMetaInfo.diagnostic.factory.name!!
}
}
open class LineMarkerRenderConfiguration(var renderDescription: Boolean = true) : AbstractCodeMetaInfoRenderConfiguration() {
override fun asString(codeMetaInfo: CodeMetaInfo): String {
if (codeMetaInfo !is LineMarkerCodeMetaInfo) return ""
return getTag() + getParamsString(codeMetaInfo)
}
fun getTag() = "LINE_MARKER"
private fun getParamsString(lineMarkerCodeMetaInfo: LineMarkerCodeMetaInfo): String {
if (!renderParams) return ""
val params = mutableListOf<String>()
if (renderDescription)
params.add("descr='${sanitizeLineMarkerTooltip(lineMarkerCodeMetaInfo.lineMarker.lineMarkerTooltip)}'")
params.add(getAdditionalParams(lineMarkerCodeMetaInfo))
val paramsString = params.filter { it.isNotEmpty() }.joinToString("; ")
return if (paramsString.isEmpty()) "" else "(\"$paramsString\")"
}
}
open class HighlightingRenderConfiguration(
val renderDescription: Boolean = true,
val renderTextAttributesKey: Boolean = true,
val renderSeverity: Boolean = true
) : AbstractCodeMetaInfoRenderConfiguration() {
override fun asString(codeMetaInfo: CodeMetaInfo): String {
if (codeMetaInfo !is HighlightingCodeMetaInfo) return ""
return getTag() + getParamsString(codeMetaInfo)
}
fun getTag() = "HIGHLIGHTING"
private fun getParamsString(highlightingCodeMetaInfo: HighlightingCodeMetaInfo): String {
if (!renderParams) return ""
val params = mutableListOf<String>()
if (renderSeverity)
params.add("severity='${highlightingCodeMetaInfo.highlightingInfo.severity}'")
if (renderDescription)
params.add("descr='${sanitizeLineBreaks(highlightingCodeMetaInfo.highlightingInfo.description)}'")
if (renderTextAttributesKey)
params.add("textAttributesKey='${highlightingCodeMetaInfo.highlightingInfo.forcedTextAttributesKey}'")
params.add(getAdditionalParams(highlightingCodeMetaInfo))
val paramsString = params.filter { it.isNotEmpty() }.joinToString("; ")
return if (paramsString.isEmpty()) "" else "(\"$paramsString\")"
}
}
@@ -0,0 +1,41 @@
/*
* 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.idea.codeMetaInfo.renderConfigurations
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.AbstractCodeMetaInfoRenderConfiguration
import org.jetbrains.kotlin.idea.codeMetaInfo.models.HighlightingCodeMetaInfo
open class HighlightingRenderConfiguration(
val renderDescription: Boolean = true,
val renderTextAttributesKey: Boolean = true,
val renderSeverity: Boolean = true
) : AbstractCodeMetaInfoRenderConfiguration() {
override fun asString(codeMetaInfo: CodeMetaInfo): String {
if (codeMetaInfo !is HighlightingCodeMetaInfo) return ""
return getTag() + getParamsString(codeMetaInfo)
}
fun getTag() = "HIGHLIGHTING"
private fun getParamsString(highlightingCodeMetaInfo: HighlightingCodeMetaInfo): String {
if (!renderParams) return ""
val params = mutableListOf<String>()
if (renderSeverity)
params.add("severity='${highlightingCodeMetaInfo.highlightingInfo.severity}'")
if (renderDescription)
params.add("descr='${sanitizeLineBreaks(highlightingCodeMetaInfo.highlightingInfo.description)}'")
if (renderTextAttributesKey)
params.add("textAttributesKey='${highlightingCodeMetaInfo.highlightingInfo.forcedTextAttributesKey}'")
params.add(getAdditionalParams(highlightingCodeMetaInfo))
val paramsString = params.filter { it.isNotEmpty() }.joinToString("; ")
return if (paramsString.isEmpty()) "" else "(\"$paramsString\")"
}
}
@@ -0,0 +1,32 @@
/*
* 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.idea.codeMetaInfo.renderConfigurations
import org.jetbrains.kotlin.codeMetaInfo.model.CodeMetaInfo
import org.jetbrains.kotlin.codeMetaInfo.renderConfigurations.AbstractCodeMetaInfoRenderConfiguration
import org.jetbrains.kotlin.idea.codeMetaInfo.models.LineMarkerCodeMetaInfo
open class LineMarkerRenderConfiguration(var renderDescription: Boolean = true) : AbstractCodeMetaInfoRenderConfiguration() {
override fun asString(codeMetaInfo: CodeMetaInfo): String {
if (codeMetaInfo !is LineMarkerCodeMetaInfo) return ""
return getTag() + getParamsString(codeMetaInfo)
}
fun getTag() = "LINE_MARKER"
private fun getParamsString(lineMarkerCodeMetaInfo: LineMarkerCodeMetaInfo): String {
if (!renderParams) return ""
val params = mutableListOf<String>()
if (renderDescription)
params.add("descr='${sanitizeLineMarkerTooltip(lineMarkerCodeMetaInfo.lineMarker.lineMarkerTooltip)}'")
params.add(getAdditionalParams(lineMarkerCodeMetaInfo))
val paramsString = params.filter { it.isNotEmpty() }.joinToString("; ")
return if (paramsString.isEmpty()) "" else "(\"$paramsString\")"
}
}