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

[CMI] Cleanup code of CodeMetaInfo

上级 23c088af
...@@ -67,7 +67,7 @@ class CodeMetaInfoTestCase( ...@@ -67,7 +67,7 @@ class CodeMetaInfoTestCase(
): List<CodeMetaInfo> { ): List<CodeMetaInfo> {
val tempSourceKtFile = PsiManager.getInstance(project).findFile(file.virtualFile) as KtFile val tempSourceKtFile = PsiManager.getInstance(project).findFile(file.virtualFile) as KtFile
val resolutionFacade = tempSourceKtFile.getResolutionFacade() 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 directives = KotlinTestUtils.parseDirectives(file.text)
val diagnosticsFilter = BaseDiagnosticsTest.parseDiagnosticFilterDirective(directives, allowUnderscoreUsage = false) val diagnosticsFilter = BaseDiagnosticsTest.parseDiagnosticFilterDirective(directives, allowUnderscoreUsage = false)
val diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors( val diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(
......
...@@ -29,18 +29,18 @@ interface CodeMetaInfo { ...@@ -29,18 +29,18 @@ interface CodeMetaInfo {
class DiagnosticCodeMetaInfo( class DiagnosticCodeMetaInfo(
override val start: Int, override val start: Int,
override val end: Int, override val end: Int,
override val renderConfiguration: AbstractCodeMetaInfoRenderConfiguration, override val renderConfiguration: DiagnosticCodeMetaInfoRenderConfiguration,
val diagnostic: Diagnostic val diagnostic: Diagnostic
) : CodeMetaInfo { ) : CodeMetaInfo {
override val platforms: MutableList<String> = mutableListOf() 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( class LineMarkerCodeMetaInfo(
override val renderConfiguration: AbstractCodeMetaInfoRenderConfiguration, override val renderConfiguration: LineMarkerRenderConfiguration,
val lineMarker: LineMarkerInfo<*> val lineMarker: LineMarkerInfo<*>
) : CodeMetaInfo { ) : CodeMetaInfo {
override val start: Int override val start: Int
...@@ -49,13 +49,13 @@ class LineMarkerCodeMetaInfo( ...@@ -49,13 +49,13 @@ class LineMarkerCodeMetaInfo(
get() = lineMarker.endOffset get() = lineMarker.endOffset
override val platforms: MutableList<String> = mutableListOf() 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( class HighlightingCodeMetaInfo(
override val renderConfiguration: AbstractCodeMetaInfoRenderConfiguration, override val renderConfiguration: HighlightingRenderConfiguration,
val highlightingInfo: HighlightInfo val highlightingInfo: HighlightInfo
) : CodeMetaInfo { ) : CodeMetaInfo {
override val start: Int override val start: Int
...@@ -64,9 +64,9 @@ class HighlightingCodeMetaInfo( ...@@ -64,9 +64,9 @@ class HighlightingCodeMetaInfo(
get() = highlightingInfo.endOffset get() = highlightingInfo.endOffset
override val platforms: MutableList<String> = mutableListOf() 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( class ParsedCodeMetaInfo(
...@@ -77,14 +77,21 @@ class ParsedCodeMetaInfo( ...@@ -77,14 +77,21 @@ class ParsedCodeMetaInfo(
) : CodeMetaInfo { ) : CodeMetaInfo {
override val renderConfiguration = object : AbstractCodeMetaInfoRenderConfiguration(false) {} 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 { override fun equals(other: Any?): Boolean {
if (other == null || other !is CodeMetaInfo) return false if (other == null || other !is CodeMetaInfo) return false
return this.tag == other.getTag() && this.start == other.start && this.end == other.end 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> { fun createCodeMetaInfo(obj: Any, renderConfiguration: AbstractCodeMetaInfoRenderConfiguration): List<CodeMetaInfo> {
......
...@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.idea.codeMetaInfo.models.LineMarkerCodeMetaInfo ...@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.idea.codeMetaInfo.models.LineMarkerCodeMetaInfo
abstract class AbstractCodeMetaInfoRenderConfiguration(var renderParams: Boolean = true) { 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 asString(codeMetaInfo: CodeMetaInfo) = codeMetaInfo.getTag() + getPlatformsString(codeMetaInfo)
open fun getAdditionalParams(codeMetaInfo: CodeMetaInfo) = "" open fun getAdditionalParams(codeMetaInfo: CodeMetaInfo) = ""
...@@ -62,6 +62,8 @@ open class DiagnosticCodeMetaInfoRenderConfiguration( ...@@ -62,6 +62,8 @@ open class DiagnosticCodeMetaInfoRenderConfiguration(
private fun getParamsString(codeMetaInfo: DiagnosticCodeMetaInfo): String { private fun getParamsString(codeMetaInfo: DiagnosticCodeMetaInfo): String {
if (!renderParams) return "" if (!renderParams) return ""
val params = mutableListOf<String>() val params = mutableListOf<String>()
@Suppress("UNCHECKED_CAST")
val renderer = when (codeMetaInfo.diagnostic.factory) { val renderer = when (codeMetaInfo.diagnostic.factory) {
is DebugInfoDiagnosticFactory1 -> DiagnosticWithParameters1Renderer( is DebugInfoDiagnosticFactory1 -> DiagnosticWithParameters1Renderer(
"{0}", "{0}",
...@@ -137,4 +139,4 @@ open class HighlightingRenderConfiguration( ...@@ -137,4 +139,4 @@ open class HighlightingRenderConfiguration(
return if (paramsString.isEmpty()) "" else "(\"$paramsString\")" 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.
先完成此消息的编辑!
想要评论请 注册