Exctract common code from psi and fir visualizer classes
This commit is contained in:
committed by
Mikhail Glukhikh
parent
d504774527
commit
f0c7aadb20
+26
-2
@@ -5,6 +5,30 @@
|
||||
|
||||
package org.jetbrains.kotlin.compiler.visualizer
|
||||
|
||||
interface BaseRenderer {
|
||||
fun render(): String
|
||||
import com.intellij.psi.PsiElement
|
||||
|
||||
abstract class BaseRenderer {
|
||||
private val annotations = mutableSetOf<Annotator.AnnotationInfo>()
|
||||
private val unnecessaryData = mapOf(
|
||||
"kotlin/" to ""
|
||||
)
|
||||
|
||||
open fun addAnnotation(annotationText: String, element: PsiElement?, deleteDuplicate: Boolean = true) {
|
||||
if (element == null) return
|
||||
annotations.removeIf { it.range.startOffset == element.textRange.startOffset && deleteDuplicate }
|
||||
|
||||
var textWithOutUnnecessaryData = annotationText
|
||||
for ((key, value) in unnecessaryData) {
|
||||
textWithOutUnnecessaryData = textWithOutUnnecessaryData.replace(key, value)
|
||||
}
|
||||
if (textWithOutUnnecessaryData != element.text && textWithOutUnnecessaryData.isNotEmpty()) {
|
||||
annotations.add(Annotator.AnnotationInfo(textWithOutUnnecessaryData, element.textRange))
|
||||
}
|
||||
}
|
||||
|
||||
protected fun getAnnotations(): Set<Annotator.AnnotationInfo> {
|
||||
return annotations
|
||||
}
|
||||
|
||||
abstract fun render(): String
|
||||
}
|
||||
Reference in New Issue
Block a user