提交 4ad9f486 编写于 作者: D Dmitriy Novozhilov

[CMI] Cleanup code of CodeMetaInfo

上级 23c088af
......@@ -67,7 +67,7 @@ class CodeMetaInfoTestCase(
): List<CodeMetaInfo> {
val tempSourceKtFile = PsiManager.getInstance(project).findFile(file.virtualFile) as KtFile
val resolutionFacade = tempSourceKtFile.getResolutionFacade()
val (bindingContext, moduleDescriptor) = resolutionFacade.analyzeWithAllCompilerChecks(listOf(tempSourceKtFile))
val (bindingContext, moduleDescriptor, _) = resolutionFacade.analyzeWithAllCompilerChecks(listOf(tempSourceKtFile))
val directives = KotlinTestUtils.parseDirectives(file.text)
val diagnosticsFilter = BaseDiagnosticsTest.parseDiagnosticFilterDirective(directives, allowUnderscoreUsage = false)
val diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(
......
......@@ -29,18 +29,18 @@ interface CodeMetaInfo {
class DiagnosticCodeMetaInfo(
override val start: Int,
override val end: Int,
override val renderConfiguration: AbstractCodeMetaInfoRenderConfiguration,
override val renderConfiguration: DiagnosticCodeMetaInfoRenderConfiguration,
val diagnostic: Diagnostic
) : CodeMetaInfo {
override val platforms: MutableList<String> = mutableListOf()
override fun asString() = renderConfiguration.asString(this)
override fun asString(): String = renderConfiguration.asString(this)
override fun getTag() = (renderConfiguration as DiagnosticCodeMetaInfoRenderConfiguration).getTag(this)
override fun getTag(): String = renderConfiguration.getTag(this)
}
class LineMarkerCodeMetaInfo(
override val renderConfiguration: AbstractCodeMetaInfoRenderConfiguration,
override val renderConfiguration: LineMarkerRenderConfiguration,
val lineMarker: LineMarkerInfo<*>
) : CodeMetaInfo {
override val start: Int
......@@ -49,13 +49,13 @@ class LineMarkerCodeMetaInfo(
get() = lineMarker.endOffset
override val platforms: MutableList<String> = mutableListOf()
override fun asString() = renderConfiguration.asString(this)
override fun asString(): String = renderConfiguration.asString(this)
override fun getTag() = (renderConfiguration as LineMarkerRenderConfiguration).getTag()
override fun getTag(): String = renderConfiguration.getTag()
}
class HighlightingCodeMetaInfo(
override val renderConfiguration: AbstractCodeMetaInfoRenderConfiguration,
override val renderConfiguration: HighlightingRenderConfiguration,
val highlightingInfo: HighlightInfo
) : CodeMetaInfo {
override val start: Int
......@@ -64,9 +64,9 @@ class HighlightingCodeMetaInfo(
get() = highlightingInfo.endOffset
override val platforms: MutableList<String> = mutableListOf()
override fun asString() = renderConfiguration.asString(this)
override fun asString(): String = renderConfiguration.asString(this)
override fun getTag() = (renderConfiguration as HighlightingRenderConfiguration).getTag()
override fun getTag(): String = renderConfiguration.getTag()
}
class ParsedCodeMetaInfo(
......@@ -77,14 +77,21 @@ class ParsedCodeMetaInfo(
) : CodeMetaInfo {
override val renderConfiguration = object : AbstractCodeMetaInfoRenderConfiguration(false) {}
override fun asString() = renderConfiguration.asString(this)
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 getTag() = tag
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> {
......
......@@ -17,7 +17,7 @@ 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
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) = ""
......@@ -62,6 +62,8 @@ open class DiagnosticCodeMetaInfoRenderConfiguration(
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}",
......@@ -137,4 +139,4 @@ open class HighlightingRenderConfiguration(
return if (paramsString.isEmpty()) "" else "(\"$paramsString\")"
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册