Exctract common code from psi and fir visualizer classes

This commit is contained in:
Ivan Cilcic
2019-08-28 15:57:00 +03:00
committed by Mikhail Glukhikh
parent d504774527
commit f0c7aadb20
4 changed files with 34 additions and 45 deletions
@@ -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
}