diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.kt index 99cc012be97c5..a84d6d49975dc 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.kt @@ -128,7 +128,7 @@ class AnalyzerWithCompilerReport( psiElement: E, factory: DiagnosticFactory0, val message: String ) : SimpleDiagnostic(psiElement, factory, Severity.ERROR) { - override fun isValid(): Boolean = true + override val isValid: Boolean = true } companion object { diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt index 2d82644bf95c7..f7b8e272c98fc 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt @@ -28,9 +28,9 @@ class DefaultDiagnosticReporter(override val messageCollector: MessageCollector) interface MessageCollectorBasedReporter : DiagnosticMessageReporter { val messageCollector: MessageCollector - override fun report(diagnostic: Diagnostic, file: PsiFile, render: String) = messageCollector.report( + override fun report(diagnostic: Diagnostic, file: PsiFile?, render: String) = messageCollector.report( AnalyzerWithCompilerReport.convertSeverity(diagnostic.severity), render, - MessageUtil.psiFileToMessageLocation(file, file.name, DiagnosticUtils.getLineAndColumnRange(diagnostic)) + MessageUtil.psiFileToMessageLocation(file!!, file.name, DiagnosticUtils.getLineAndColumnRange(diagnostic)) ) } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt.202 b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt.202 index f560fc945f328..73085c2317f04 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt.202 +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DefaultDiagnosticReporter.kt.202 @@ -28,9 +28,9 @@ class DefaultDiagnosticReporter(override val messageCollector: MessageCollector) interface MessageCollectorBasedReporter : DiagnosticMessageReporter { val messageCollector: MessageCollector - override fun report(diagnostic: Diagnostic, file: PsiFile, render: String) = messageCollector.report( + override fun report(diagnostic: Diagnostic, file: PsiFile?, render: String) = messageCollector.report( AnalyzerWithCompilerReport.convertSeverity(diagnostic.severity), render, - MessageUtil.psiFileToMessageLocation(file, file.name, DiagnosticUtils.getLineAndColumn(diagnostic)) + MessageUtil.psiFileToMessageLocation(file!!, file.name, DiagnosticUtils.getLineAndColumn(diagnostic)) ) } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DiagnosticMessageReporter.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DiagnosticMessageReporter.kt index 246781e61873c..4b6be982707ec 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DiagnosticMessageReporter.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/DiagnosticMessageReporter.kt @@ -20,5 +20,5 @@ import com.intellij.psi.PsiFile import org.jetbrains.kotlin.diagnostics.Diagnostic interface DiagnosticMessageReporter { - fun report(diagnostic: Diagnostic, file: PsiFile, render: String) + fun report(diagnostic: Diagnostic, file: PsiFile?, render: String) } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt index a5a872f861a07..2bd41eda42cf2 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt @@ -343,9 +343,7 @@ object KotlinToJVMBytecodeCompiler { firAnalyzerFacade.runResolution() val firDiagnostics = firAnalyzerFacade.runCheckers().values.flatten() AnalyzerWithCompilerReport.reportDiagnostics( - SimpleDiagnostics( - firDiagnostics.map { it.toRegularDiagnostic() } - ), + SimpleDiagnostics(firDiagnostics), environment.messageCollector ) performanceManager?.notifyAnalysisFinished() @@ -429,30 +427,6 @@ object KotlinToJVMBytecodeCompiler { return writeOutputs(environment, projectConfiguration, chunk, outputs, mainClassFqName) } - private fun FirDiagnostic<*>.toRegularDiagnostic(): Diagnostic { - val psiSource = element as FirPsiSourceElement<*> - @Suppress("UNCHECKED_CAST") - when (this) { - is FirSimpleDiagnostic -> - return SimpleDiagnostic( - psiSource.psi, factory.psiDiagnosticFactory as DiagnosticFactory0, severity - ) - is FirDiagnosticWithParameters1<*, *> -> - return DiagnosticWithParameters1( - psiSource.psi, this.a, factory.psiDiagnosticFactory as DiagnosticFactory1, severity - ) - is FirDiagnosticWithParameters2<*, *, *> -> - return DiagnosticWithParameters2( - psiSource.psi, this.a, this.b, factory.psiDiagnosticFactory as DiagnosticFactory2, severity - ) - is FirDiagnosticWithParameters3<*, *, *, *> -> - return DiagnosticWithParameters3( - psiSource.psi, this.a, this.b, this.c, - factory.psiDiagnosticFactory as DiagnosticFactory3, severity - ) - } - } - private fun getBuildFilePaths(buildFile: File?, sourceFilePaths: List): List = if (buildFile == null) sourceFilePaths else sourceFilePaths.map { path -> diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt index 3a32d8fd51e3a..cf74faad14e01 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt @@ -129,7 +129,7 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension { companion object { fun getRendererForDiagnostic(diagnostic: FirDiagnostic<*>): FirDiagnosticRenderer<*> { val factory = diagnostic.factory - return MAP[factory] ?: factory.defaultRenderer + return MAP[factory] ?: factory.firRenderer } // * - The old FE reports these diagnostics with additional parameters diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnostic.kt index 72836096b240c..96cb228f5babc 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnostic.kt @@ -5,7 +5,9 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics +import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.fir.FirLightSourceElement @@ -14,10 +16,16 @@ import org.jetbrains.kotlin.fir.FirSourceElement // ------------------------------ diagnostics ------------------------------ -sealed class FirDiagnostic { +sealed class FirDiagnostic : Diagnostic { abstract val element: E - abstract val severity: Severity - abstract val factory: AbstractFirDiagnosticFactory<*, *> + abstract override val severity: Severity + abstract override val factory: AbstractFirDiagnosticFactory<*, *> + + override val textRanges: List + get() = factory.getTextRanges(this) + + override val isValid: Boolean + get() = true } sealed class FirSimpleDiagnostic : FirDiagnostic() { @@ -44,31 +52,28 @@ sealed class FirDiagnosticWithParameters3 { - fun asPsiBasedDiagnostic(): Diagnostic +interface FirPsiDiagnostic

: Diagnostic { val element: FirPsiSourceElement

+ + override val psiElement: PsiElement + get() = element.psi + + override val psiFile: PsiFile + get() = psiElement.containingFile } data class FirPsiSimpleDiagnostic

( override val element: FirPsiSourceElement

, override val severity: Severity, override val factory: FirDiagnosticFactory0, P> -) : FirSimpleDiagnostic>(), FirPsiDiagnostic

{ - override fun asPsiBasedDiagnostic(): Diagnostic { - return factory.psiDiagnosticFactory.on(element.psi) - } -} +) : FirSimpleDiagnostic>(), FirPsiDiagnostic

data class FirPsiDiagnosticWithParameters1

( override val element: FirPsiSourceElement

, override val a: A, override val severity: Severity, override val factory: FirDiagnosticFactory1, P, A> -) : FirDiagnosticWithParameters1, A>(), FirPsiDiagnostic

{ - override fun asPsiBasedDiagnostic(): Diagnostic { - return factory.psiDiagnosticFactory.on(element.psi, a) - } -} +) : FirDiagnosticWithParameters1, A>(), FirPsiDiagnostic

data class FirPsiDiagnosticWithParameters2

( override val element: FirPsiSourceElement

, @@ -76,11 +81,7 @@ data class FirPsiDiagnosticWithParameters2

( override val b: B, override val severity: Severity, override val factory: FirDiagnosticFactory2, P, A, B> -) : FirDiagnosticWithParameters2, A, B>(), FirPsiDiagnostic

{ - override fun asPsiBasedDiagnostic(): Diagnostic { - return factory.psiDiagnosticFactory.on(element.psi, a, b) - } -} +) : FirDiagnosticWithParameters2, A, B>(), FirPsiDiagnostic

data class FirPsiDiagnosticWithParameters3

( override val element: FirPsiSourceElement

, @@ -89,16 +90,20 @@ data class FirPsiDiagnosticWithParameters3

, P, A, B, C> -) : FirDiagnosticWithParameters3, A, B, C>(), FirPsiDiagnostic

{ - override fun asPsiBasedDiagnostic(): Diagnostic { - return factory.psiDiagnosticFactory.on(element.psi, a, b, c) - } -} +) : FirDiagnosticWithParameters3, A, B, C>(), FirPsiDiagnostic

// ------------------------------ light tree diagnostics ------------------------------ -interface FirLightDiagnostic { +interface FirLightDiagnostic : Diagnostic { val element: FirLightSourceElement + + override val psiElement: PsiElement + get() { + throw UnsupportedOperationException("Light diagnostic does not hold PSI element") + } + + override val psiFile: PsiFile? + get() = null } data class FirLightSimpleDiagnostic( diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactory.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactory.kt index 22eeb6643580f..e8dae007b4512 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactory.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactory.kt @@ -10,39 +10,33 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import org.jetbrains.kotlin.diagnostics.* +import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticRenderer import org.jetbrains.kotlin.fir.FirLightSourceElement import org.jetbrains.kotlin.fir.FirPsiSourceElement import org.jetbrains.kotlin.fir.FirSourceElement sealed class AbstractFirDiagnosticFactory>( - val name: String, - val severity: Severity, + override var name: String?, + override val severity: Severity, val positioningStrategy: LightTreePositioningStrategy, -) { - abstract val psiDiagnosticFactory: DiagnosticFactoryWithPsiElement<*, *> +) : DiagnosticFactory(name, severity) { + abstract val firRenderer: FirDiagnosticRenderer - abstract val defaultRenderer: FirDiagnosticRenderer<*> + override var defaultRenderer: DiagnosticRenderer? + get() = firRenderer + set(_) { + } fun getTextRanges(diagnostic: FirDiagnostic<*>): List = positioningStrategy.markDiagnostic(diagnostic) - - override fun toString(): String { - return name - } } class FirDiagnosticFactory0( name: String, severity: Severity, - override val psiDiagnosticFactory: DiagnosticFactory0

, positioningStrategy: LightTreePositioningStrategy = LightTreePositioningStrategy.DEFAULT, ) : AbstractFirDiagnosticFactory>(name, severity, positioningStrategy) { - companion object { - private val DefaultRenderer = SimpleFirDiagnosticRenderer("") - } - - override val defaultRenderer: FirDiagnosticRenderer<*> - get() = DefaultRenderer + override val firRenderer: FirDiagnosticRenderer> = SimpleFirDiagnosticRenderer("") fun on(element: E): FirSimpleDiagnostic { return when (element) { @@ -58,18 +52,12 @@ class FirDiagnosticFactory0( class FirDiagnosticFactory1( name: String, severity: Severity, - override val psiDiagnosticFactory: DiagnosticFactory1, positioningStrategy: LightTreePositioningStrategy = LightTreePositioningStrategy.DEFAULT, ) : AbstractFirDiagnosticFactory>(name, severity, positioningStrategy) { - companion object { - private val DefaultRenderer = FirDiagnosticWithParameters1Renderer( - "{0}", - FirDiagnosticRenderers.TO_STRING - ) - } - - override val defaultRenderer: FirDiagnosticRenderer<*> - get() = DefaultRenderer + override val firRenderer: FirDiagnosticRenderer> = FirDiagnosticWithParameters1Renderer( + "{0}", + FirDiagnosticRenderers.TO_STRING + ) fun on(element: E, a: A): FirDiagnosticWithParameters1 { return when (element) { @@ -85,19 +73,13 @@ class FirDiagnosticFactory1( class FirDiagnosticFactory2( name: String, severity: Severity, - override val psiDiagnosticFactory: DiagnosticFactory2, positioningStrategy: LightTreePositioningStrategy = LightTreePositioningStrategy.DEFAULT, ) : AbstractFirDiagnosticFactory>(name, severity, positioningStrategy) { - companion object { - private val DefaultRenderer = FirDiagnosticWithParameters2Renderer( - "{0}, {1}", - FirDiagnosticRenderers.TO_STRING, - FirDiagnosticRenderers.TO_STRING - ) - } - - override val defaultRenderer: FirDiagnosticRenderer<*> - get() = DefaultRenderer + override val firRenderer: FirDiagnosticRenderer> = FirDiagnosticWithParameters2Renderer( + "{0}, {1}", + FirDiagnosticRenderers.TO_STRING, + FirDiagnosticRenderers.TO_STRING + ) fun on(element: E, a: A, b: B): FirDiagnosticWithParameters2 { return when (element) { @@ -113,20 +95,14 @@ class FirDiagnosticFactory2( name: String, severity: Severity, - override val psiDiagnosticFactory: DiagnosticFactory3, positioningStrategy: LightTreePositioningStrategy = LightTreePositioningStrategy.DEFAULT, ) : AbstractFirDiagnosticFactory>(name, severity, positioningStrategy) { - companion object { - private val DefaultRenderer = FirDiagnosticWithParameters3Renderer( - "{0}, {1}, {2}", - FirDiagnosticRenderers.TO_STRING, - FirDiagnosticRenderers.TO_STRING, - FirDiagnosticRenderers.TO_STRING - ) - } - - override val defaultRenderer: FirDiagnosticRenderer<*> - get() = DefaultRenderer + override val firRenderer: FirDiagnosticRenderer> = FirDiagnosticWithParameters3Renderer( + "{0}, {1}, {2}", + FirDiagnosticRenderers.TO_STRING, + FirDiagnosticRenderers.TO_STRING, + FirDiagnosticRenderers.TO_STRING + ) fun on(element: E, a: A, b: B, c: C): FirDiagnosticWithParameters3 { return when (element) { @@ -147,7 +123,9 @@ fun FirDiagnosticFactory0.on(elemen return element?.let { on(it) } } -fun FirDiagnosticFactory1.on(element: E?, a: A): FirDiagnosticWithParameters1? { +fun FirDiagnosticFactory1.on( + element: E?, a: A +): FirDiagnosticWithParameters1? { return element?.let { on(it, a) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactoryDsl.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactoryDsl.kt index 9188355e41c66..5b2fdfd39a638 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactoryDsl.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactoryDsl.kt @@ -12,112 +12,88 @@ import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty fun warning0(): DiagnosticFactory0DelegateProvider { - return DiagnosticFactory0DelegateProvider(Severity.WARNING, null) + return DiagnosticFactory0DelegateProvider(Severity.WARNING) } fun warning1(): DiagnosticFactory1DelegateProvider { - return DiagnosticFactory1DelegateProvider(Severity.WARNING, null) + return DiagnosticFactory1DelegateProvider(Severity.WARNING) } fun warning2(): DiagnosticFactory2DelegateProvider { - return DiagnosticFactory2DelegateProvider(Severity.WARNING, null) + return DiagnosticFactory2DelegateProvider(Severity.WARNING) } fun warning3(): DiagnosticFactory3DelegateProvider { - return DiagnosticFactory3DelegateProvider(Severity.WARNING, null) + return DiagnosticFactory3DelegateProvider(Severity.WARNING) } fun error0(): DiagnosticFactory0DelegateProvider { - return DiagnosticFactory0DelegateProvider(Severity.ERROR, null) + return DiagnosticFactory0DelegateProvider(Severity.ERROR) } fun error1(): DiagnosticFactory1DelegateProvider { - return DiagnosticFactory1DelegateProvider(Severity.ERROR, null) + return DiagnosticFactory1DelegateProvider(Severity.ERROR) } fun error2(): DiagnosticFactory2DelegateProvider { - return DiagnosticFactory2DelegateProvider(Severity.ERROR, null) + return DiagnosticFactory2DelegateProvider(Severity.ERROR) } fun error3(): DiagnosticFactory3DelegateProvider { - return DiagnosticFactory3DelegateProvider(Severity.ERROR, null) + return DiagnosticFactory3DelegateProvider(Severity.ERROR) } /** * Note that those functions can be applicable only for factories * that takes `PsiElement` as first type parameter */ -fun existing( - psiDiagnosticFactory: DiagnosticFactory0

-): DiagnosticFactory0DelegateProvider { - return DiagnosticFactory0DelegateProvider(Severity.ERROR, psiDiagnosticFactory) +fun existing0(): DiagnosticFactory0DelegateProvider { + return DiagnosticFactory0DelegateProvider(Severity.ERROR) } -fun existing( - psiDiagnosticFactory: DiagnosticFactory1 -): DiagnosticFactory1DelegateProvider { - return DiagnosticFactory1DelegateProvider(Severity.ERROR, psiDiagnosticFactory) +fun existing1(): DiagnosticFactory1DelegateProvider { + return DiagnosticFactory1DelegateProvider(Severity.ERROR) } -fun existing( - psiDiagnosticFactory: DiagnosticFactory2 -): DiagnosticFactory2DelegateProvider { - return DiagnosticFactory2DelegateProvider(Severity.ERROR, psiDiagnosticFactory) +fun existing2(): DiagnosticFactory2DelegateProvider { + return DiagnosticFactory2DelegateProvider(Severity.ERROR) } -fun existing( - psiDiagnosticFactory: DiagnosticFactory3 -): DiagnosticFactory3DelegateProvider { - return DiagnosticFactory3DelegateProvider(Severity.ERROR, psiDiagnosticFactory) +fun existing3(): DiagnosticFactory3DelegateProvider { + return DiagnosticFactory3DelegateProvider(Severity.ERROR) } // ------------------------------ Providers ------------------------------ class DiagnosticFactory0DelegateProvider( - private val severity: Severity, - private val psiDiagnosticFactory: DiagnosticFactory0

? + private val severity: Severity ) { operator fun provideDelegate(thisRef: Any?, prop: KProperty<*>): ReadOnlyProperty> { - val psiFactory = psiDiagnosticFactory ?: DiagnosticFactory0.create

(severity).apply { - initializeName(prop.name) - } - return DummyDelegate(FirDiagnosticFactory0(prop.name, severity, psiFactory)) + return DummyDelegate(FirDiagnosticFactory0(prop.name, severity)) } } class DiagnosticFactory1DelegateProvider( - private val severity: Severity, - private val psiDiagnosticFactory: DiagnosticFactory1? + private val severity: Severity ) { operator fun provideDelegate(thisRef: Any?, prop: KProperty<*>): ReadOnlyProperty> { - val psiFactory = psiDiagnosticFactory ?: DiagnosticFactory1.create(severity).apply { - initializeName(prop.name) - } - return DummyDelegate(FirDiagnosticFactory1(prop.name, severity, psiFactory)) + return DummyDelegate(FirDiagnosticFactory1(prop.name, severity)) } } class DiagnosticFactory2DelegateProvider( - private val severity: Severity, - private val psiDiagnosticFactory: DiagnosticFactory2? + private val severity: Severity ) { operator fun provideDelegate(thisRef: Any?, prop: KProperty<*>): ReadOnlyProperty> { - val psiFactory = psiDiagnosticFactory ?: DiagnosticFactory2.create(severity).apply { - initializeName(prop.name) - } - return DummyDelegate(FirDiagnosticFactory2(prop.name, severity, psiFactory)) + return DummyDelegate(FirDiagnosticFactory2(prop.name, severity)) } } class DiagnosticFactory3DelegateProvider( - private val severity: Severity, - private val psiDiagnosticFactory: DiagnosticFactory3? + private val severity: Severity ) { operator fun provideDelegate(thisRef: Any?, prop: KProperty<*>): ReadOnlyProperty> { - val psiFactory = psiDiagnosticFactory ?: DiagnosticFactory3.create(severity).apply { - initializeName(prop.name) - } - return DummyDelegate(FirDiagnosticFactory3(prop.name, severity, psiFactory)) + return DummyDelegate(FirDiagnosticFactory3(prop.name, severity)) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactoryToRendererMap.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactoryToRendererMap.kt index 4a845598888bf..362a11fd8f2a7 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactoryToRendererMap.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticFactoryToRendererMap.kt @@ -7,51 +7,47 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticFactoryToRendererMap import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticParameterRenderer -import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticRenderer +import org.jetbrains.kotlin.fir.FirSourceElement class FirDiagnosticFactoryToRendererMap(val name: String) { - private val classicRenderersMap: MutableMap, DiagnosticRenderer<*>> = mutableMapOf() private val renderersMap: MutableMap, FirDiagnosticRenderer<*>> = mutableMapOf() val psiDiagnosticMap: DiagnosticFactoryToRendererMap = DiagnosticFactoryToRendererMap() operator fun get(factory: AbstractFirDiagnosticFactory<*, *>): FirDiagnosticRenderer<*>? = renderersMap[factory] - fun getClassicRenderer(factory: AbstractFirDiagnosticFactory<*, *>): DiagnosticRenderer<*>? = classicRenderersMap[factory] - fun put(factory: FirDiagnosticFactory0<*, *>, message: String) { - put(factory, SimpleFirDiagnosticRenderer(message)) + fun put(factory: FirDiagnosticFactory0, message: String) { + put(factory, SimpleFirDiagnosticRenderer(message)) } - fun put( - factory: FirDiagnosticFactory1<*, *, A>, + fun put( + factory: FirDiagnosticFactory1, message: String, rendererA: DiagnosticParameterRenderer? ) { - put(factory, FirDiagnosticWithParameters1Renderer(message, rendererA)) + put(factory, FirDiagnosticWithParameters1Renderer(message, rendererA)) } - fun put( - factory: FirDiagnosticFactory2<*, *, A, B>, + fun put( + factory: FirDiagnosticFactory2, message: String, rendererA: DiagnosticParameterRenderer?, rendererB: DiagnosticParameterRenderer? ) { - put(factory, FirDiagnosticWithParameters2Renderer(message, rendererA, rendererB)) + put(factory, FirDiagnosticWithParameters2Renderer(message, rendererA, rendererB)) } - fun put( - factory: FirDiagnosticFactory3<*, *, A, B, C>, + fun put( + factory: FirDiagnosticFactory3, message: String, rendererA: DiagnosticParameterRenderer?, rendererB: DiagnosticParameterRenderer?, rendererC: DiagnosticParameterRenderer? ) { - put(factory, FirDiagnosticWithParameters3Renderer(message, rendererA, rendererB, rendererC)) + put(factory, FirDiagnosticWithParameters3Renderer(message, rendererA, rendererB, rendererC)) } private fun put(factory: AbstractFirDiagnosticFactory<*, *>, renderer: FirDiagnosticRenderer<*>) { - val classicRenderer = renderer.toClassicDiagnosticRenderer() renderersMap[factory] = renderer - classicRenderersMap[factory] = classicRenderer - psiDiagnosticMap.put(factory.psiDiagnosticFactory, classicRenderer) + psiDiagnosticMap.put(factory, renderer) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderer.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderer.kt index 50e16067e3fcc..a440598e48658 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderer.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDiagnosticRenderer.kt @@ -6,22 +6,17 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics import org.jetbrains.kotlin.diagnostics.rendering.* +import org.jetbrains.kotlin.fir.FirSourceElement import java.text.MessageFormat -sealed class FirDiagnosticRenderer> { - abstract fun render(diagnostic: D): String - - abstract fun toClassicDiagnosticRenderer(): DiagnosticRenderer<*> +sealed class FirDiagnosticRenderer> : DiagnosticRenderer { + abstract override fun render(diagnostic: D): String } -class SimpleFirDiagnosticRenderer(private val message: String) : FirDiagnosticRenderer>() { - override fun render(diagnostic: FirSimpleDiagnostic<*>): String { +class SimpleFirDiagnosticRenderer(private val message: String) : FirDiagnosticRenderer>() { + override fun render(diagnostic: FirSimpleDiagnostic): String { return message } - - override fun toClassicDiagnosticRenderer(): DiagnosticRenderer<*> { - return SimpleDiagnosticRenderer(message) - } } sealed class AbstractFirDiagnosticWithParametersRenderer>( @@ -36,45 +31,37 @@ sealed class AbstractFirDiagnosticWithParametersRenderer>( abstract fun renderParameters(diagnostic: D): Array } -class FirDiagnosticWithParameters1Renderer( +class FirDiagnosticWithParameters1Renderer( message: String, private val rendererForA: DiagnosticParameterRenderer?, -) : AbstractFirDiagnosticWithParametersRenderer>(message) { - override fun renderParameters(diagnostic: FirDiagnosticWithParameters1<*, A>): Array { +) : AbstractFirDiagnosticWithParametersRenderer>(message) { + override fun renderParameters(diagnostic: FirDiagnosticWithParameters1): Array { val context = RenderingContext.of(diagnostic.a) - return arrayOf(renderParameter(diagnostic.a, rendererForA, context),) - } - - override fun toClassicDiagnosticRenderer(): DiagnosticRenderer<*> { - return DiagnosticWithParameters1Renderer(message, rendererForA) + return arrayOf(renderParameter(diagnostic.a, rendererForA, context)) } } -class FirDiagnosticWithParameters2Renderer( +class FirDiagnosticWithParameters2Renderer( message: String, private val rendererForA: DiagnosticParameterRenderer?, private val rendererForB: DiagnosticParameterRenderer?, -) : AbstractFirDiagnosticWithParametersRenderer>(message) { - override fun renderParameters(diagnostic: FirDiagnosticWithParameters2<*, A, B>): Array { +) : AbstractFirDiagnosticWithParametersRenderer>(message) { + override fun renderParameters(diagnostic: FirDiagnosticWithParameters2): Array { val context = RenderingContext.of(diagnostic.a, diagnostic.b) return arrayOf( renderParameter(diagnostic.a, rendererForA, context), renderParameter(diagnostic.b, rendererForB, context), ) } - - override fun toClassicDiagnosticRenderer(): DiagnosticRenderer<*> { - return DiagnosticWithParameters2Renderer(message, rendererForA, rendererForB) - } } -class FirDiagnosticWithParameters3Renderer( +class FirDiagnosticWithParameters3Renderer( message: String, private val rendererForA: DiagnosticParameterRenderer?, private val rendererForB: DiagnosticParameterRenderer?, private val rendererForC: DiagnosticParameterRenderer?, -) : AbstractFirDiagnosticWithParametersRenderer>(message) { - override fun renderParameters(diagnostic: FirDiagnosticWithParameters3<*, A, B, C>): Array { +) : AbstractFirDiagnosticWithParametersRenderer>(message) { + override fun renderParameters(diagnostic: FirDiagnosticWithParameters3): Array { val context = RenderingContext.of(diagnostic.a, diagnostic.b, diagnostic.c) return arrayOf( renderParameter(diagnostic.a, rendererForA, context), @@ -82,8 +69,4 @@ class FirDiagnosticWithParameters3Renderer( renderParameter(diagnostic.c, rendererForC, context), ) } - - override fun toClassicDiagnosticRenderer(): DiagnosticRenderer<*> { - return DiagnosticWithParameters3Renderer(message, rendererForA, rendererForB, rendererForC) - } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 982c1e4608cf6..fe86388ba59c3 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics import com.intellij.psi.PsiElement import com.intellij.psi.PsiTypeElement import org.jetbrains.kotlin.contracts.description.EventOccurrencesRange -import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.fir.FirEffectiveVisibility import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.declarations.FirClass @@ -67,10 +66,10 @@ object FirErrors { val SEALED_SUPERTYPE_IN_LOCAL_CLASS by error0() // Constructor problems - val CONSTRUCTOR_IN_OBJECT by existing(Errors.CONSTRUCTOR_IN_OBJECT) - val CONSTRUCTOR_IN_INTERFACE by existing(Errors.CONSTRUCTOR_IN_INTERFACE) - val NON_PRIVATE_CONSTRUCTOR_IN_ENUM by existing(Errors.NON_PRIVATE_CONSTRUCTOR_IN_ENUM) - val NON_PRIVATE_CONSTRUCTOR_IN_SEALED by existing(Errors.NON_PRIVATE_CONSTRUCTOR_IN_SEALED) + val CONSTRUCTOR_IN_OBJECT by existing0() + val CONSTRUCTOR_IN_INTERFACE by existing0() + val NON_PRIVATE_CONSTRUCTOR_IN_ENUM by existing0() + val NON_PRIVATE_CONSTRUCTOR_IN_SEALED by existing0() val CYCLIC_CONSTRUCTOR_DELEGATION_CALL by warning0() val PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED by warning0() val SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR by warning0() @@ -80,19 +79,19 @@ object FirErrors { val SEALED_CLASS_CONSTRUCTOR_CALL by error0() // Annotations - val ANNOTATION_ARGUMENT_KCLASS_LITERAL_OF_TYPE_PARAMETER_ERROR by existing(Errors.ANNOTATION_ARGUMENT_KCLASS_LITERAL_OF_TYPE_PARAMETER_ERROR) - val ANNOTATION_ARGUMENT_MUST_BE_CONST by existing(Errors.ANNOTATION_ARGUMENT_MUST_BE_CONST) - val ANNOTATION_ARGUMENT_MUST_BE_ENUM_CONST by existing(Errors.ANNOTATION_ARGUMENT_MUST_BE_ENUM_CONST) - val ANNOTATION_ARGUMENT_MUST_BE_KCLASS_LITERAL by existing(Errors.ANNOTATION_ARGUMENT_MUST_BE_KCLASS_LITERAL) - val ANNOTATION_CLASS_MEMBER by existing(Errors.ANNOTATION_CLASS_MEMBER) - val ANNOTATION_PARAMETER_DEFAULT_VALUE_MUST_BE_CONSTANT by existing(Errors.ANNOTATION_PARAMETER_DEFAULT_VALUE_MUST_BE_CONSTANT) - val INVALID_TYPE_OF_ANNOTATION_MEMBER by existing(Errors.INVALID_TYPE_OF_ANNOTATION_MEMBER) - val LOCAL_ANNOTATION_CLASS_ERROR by existing(Errors.LOCAL_ANNOTATION_CLASS_ERROR) - val MISSING_VAL_ON_ANNOTATION_PARAMETER by existing(Errors.MISSING_VAL_ON_ANNOTATION_PARAMETER) - val NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION by existing(Errors.NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION) + val ANNOTATION_ARGUMENT_KCLASS_LITERAL_OF_TYPE_PARAMETER_ERROR by existing0() + val ANNOTATION_ARGUMENT_MUST_BE_CONST by existing0() + val ANNOTATION_ARGUMENT_MUST_BE_ENUM_CONST by existing0() + val ANNOTATION_ARGUMENT_MUST_BE_KCLASS_LITERAL by existing0() + val ANNOTATION_CLASS_MEMBER by existing0() + val ANNOTATION_PARAMETER_DEFAULT_VALUE_MUST_BE_CONSTANT by existing0() + val INVALID_TYPE_OF_ANNOTATION_MEMBER by existing0() + val LOCAL_ANNOTATION_CLASS_ERROR by existing0() + val MISSING_VAL_ON_ANNOTATION_PARAMETER by existing0() + val NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION by existing0() val NOT_AN_ANNOTATION_CLASS by error1() - val NULLABLE_TYPE_OF_ANNOTATION_MEMBER by existing(Errors.NULLABLE_TYPE_OF_ANNOTATION_MEMBER) - val VAR_ANNOTATION_PARAMETER by existing(Errors.VAR_ANNOTATION_PARAMETER) + val NULLABLE_TYPE_OF_ANNOTATION_MEMBER by existing0() + val VAR_ANNOTATION_PARAMETER by existing0() // Exposed visibility group val EXPOSED_TYPEALIAS_EXPANDED_TYPE by error3() @@ -105,7 +104,7 @@ object FirErrors { val EXPOSED_TYPE_PARAMETER_BOUND by error3() // Modifiers - val INAPPLICABLE_INFIX_MODIFIER by existing(Errors.INAPPLICABLE_INFIX_MODIFIER) + val INAPPLICABLE_INFIX_MODIFIER by existing1() val REPEATED_MODIFIER by error1() val REDUNDANT_MODIFIER by error2() val DEPRECATED_MODIFIER_PAIR by error2() diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt index b4ac9b28b32b2..63a8fd8b6404d 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt @@ -184,7 +184,8 @@ sealed class FirPsiSourceElement(val psi: P) : FirSourceElem override fun getRoot(): LighterASTNode = lighterAST.root - override fun getParent(node: LighterASTNode): LighterASTNode? = node.unwrap().psi.parent?.node?.let { TreeBackedLighterAST.wrap(it) } + override fun getParent(node: LighterASTNode): LighterASTNode? = + node.unwrap().psi.parent?.node?.let { TreeBackedLighterAST.wrap(it) } override fun getChildren(node: LighterASTNode, nodesRef: Ref>): Int { val children = node.unwrap().psi.children @@ -201,7 +202,7 @@ sealed class FirPsiSourceElement(val psi: P) : FirSourceElem override fun getStartOffset(node: LighterASTNode): Int = node.unwrap().startOffset - override fun getEndOffset(node: LighterASTNode): Int = node.unwrap().let { it.startOffset + it.textLength - 1 } + override fun getEndOffset(node: LighterASTNode): Int = node.unwrap().let { it.startOffset + it.textLength } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/ActualDiagnostic.kt b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/ActualDiagnostic.kt index ec5cf4413d2da..aed9a06ca23bb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/ActualDiagnostic.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/ActualDiagnostic.kt @@ -17,10 +17,10 @@ class ActualDiagnostic constructor(val diagnostic: Diagnostic, override val plat TextDiagnostic.InferenceCompatibility.OLD override val name: String - get() = diagnostic.factory.name + get() = diagnostic.factory.name!! val file: PsiFile - get() = diagnostic.psiFile + get() = diagnostic.psiFile!! override fun compareTo(other: AbstractTestDiagnostic): Int { return if (this.diagnostic is DiagnosticWithParameters1<*, *> && other is ActualDiagnostic && other.diagnostic is DiagnosticWithParameters1<*, *>) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/DiagnosticForTests.kt b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/DiagnosticForTests.kt index bb4ace7414344..c01a46c702cc8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/DiagnosticForTests.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/DiagnosticForTests.kt @@ -21,28 +21,16 @@ class SyntaxErrorDiagnostic(errorElement: PsiErrorElement) : AbstractDiagnosticF SyntaxErrorDiagnosticFactory.INSTANCE ) -open class AbstractDiagnosticForTests(private val element: PsiElement, private val factory: DiagnosticFactory<*>) : Diagnostic { - override fun getFactory(): DiagnosticFactory<*> { - return factory - } +open class AbstractDiagnosticForTests(override val psiElement: PsiElement, override val factory: DiagnosticFactory<*>) : Diagnostic { + override val severity: Severity + get() = Severity.ERROR - override fun getSeverity(): Severity { - return Severity.ERROR - } + override val textRanges: List + get() = listOf(psiElement.textRange) - override fun getPsiElement(): PsiElement { - return element - } + override val psiFile: PsiFile + get() = psiElement.containingFile - override fun getTextRanges(): List { - return listOf(element.textRange) - } - - override fun getPsiFile(): PsiFile { - return element.containingFile - } - - override fun isValid(): Boolean { - return true - } + override val isValid: Boolean + get() = true } \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/DebugInfoDiagnosticFactory0.kt b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/DebugInfoDiagnosticFactory0.kt index f38c8ac706d0e..6bb1e03a087a3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/DebugInfoDiagnosticFactory0.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/DebugInfoDiagnosticFactory0.kt @@ -17,10 +17,12 @@ import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory -class DebugInfoDiagnosticFactory0 : DiagnosticFactory0, +class DebugInfoDiagnosticFactory0 private constructor( + private val privateName: String, + severity: Severity = Severity.ERROR +) : DiagnosticFactory0(severity, PositioningStrategies.DEFAULT), DebugInfoDiagnosticFactory { - private val name: String - override val withExplicitDefinitionOnly: Boolean + override val withExplicitDefinitionOnly: Boolean = false override fun createDiagnostic( expression: KtExpression, @@ -32,22 +34,9 @@ class DebugInfoDiagnosticFactory0 : DiagnosticFactory0, return DebugInfoDiagnostic(expression, this) } - private constructor(name: String, severity: Severity = Severity.ERROR) : super(severity, PositioningStrategies.DEFAULT) { - this.name = name - this.withExplicitDefinitionOnly = false - } - - private constructor(name: String, severity: Severity, withExplicitDefinitionOnly: Boolean) : super( - severity, - PositioningStrategies.DEFAULT - ) { - this.name = name - this.withExplicitDefinitionOnly = withExplicitDefinitionOnly - } - - override fun getName(): String { - return "DEBUG_INFO_$name" - } + override var name: String? + get() = "DEBUG_INFO_$privateName" + set(_) {} companion object { val SMARTCAST = DebugInfoDiagnosticFactory0("SMARTCAST", Severity.INFO) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/DebugInfoDiagnosticFactory1.kt b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/DebugInfoDiagnosticFactory1.kt index 64e8e4b62782c..cc043207e38aa 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/DebugInfoDiagnosticFactory1.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/DebugInfoDiagnosticFactory1.kt @@ -19,11 +19,11 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory class DebugInfoDiagnosticFactory1 : DiagnosticFactory1, DebugInfoDiagnosticFactory { - private val name: String + private val privateName: String - override fun getName(): String { - return "DEBUG_INFO_$name" - } + override var name: String? + get() = "DEBUG_INFO_$privateName" + set(_) {} override val withExplicitDefinitionOnly: Boolean @@ -33,8 +33,8 @@ class DebugInfoDiagnosticFactory1 : DiagnosticFactory1, dataFlowValueFactory: DataFlowValueFactory?, languageVersionSettings: LanguageVersionSettings?, moduleDescriptor: ModuleDescriptorImpl? - ) = when (name) { - EXPRESSION_TYPE.name -> { + ) = when (privateName) { + EXPRESSION_TYPE.privateName -> { val (type, dataFlowTypes) = CheckerTestUtil.getTypeInfo( expression, bindingContext, @@ -45,23 +45,23 @@ class DebugInfoDiagnosticFactory1 : DiagnosticFactory1, this.on(expression, Renderers.renderExpressionType(type, dataFlowTypes)) } - CALL.name -> { + CALL.privateName -> { val (fqName, typeCall) = CheckerTestUtil.getCallDebugInfo(expression, bindingContext) this.on(expression, Renderers.renderCallInfo(fqName, typeCall)) } else -> throw NotImplementedError("Creation diagnostic '$name' isn't supported.") } - protected constructor(name: String, severity: Severity) : super(severity, PositioningStrategies.DEFAULT) { - this.name = name + private constructor(name: String, severity: Severity) : super(severity, PositioningStrategies.DEFAULT) { + this.privateName = name this.withExplicitDefinitionOnly = false } - protected constructor(name: String, severity: Severity, withExplicitDefinitionOnly: Boolean) : super( + private constructor(name: String, severity: Severity, withExplicitDefinitionOnly: Boolean) : super( severity, PositioningStrategies.DEFAULT ) { - this.name = name + this.privateName = name this.withExplicitDefinitionOnly = withExplicitDefinitionOnly } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/SyntaxErrorDiagnosticFactory.kt b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/SyntaxErrorDiagnosticFactory.kt index f553b388e5123..e547fd0ba124f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/SyntaxErrorDiagnosticFactory.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/factories/SyntaxErrorDiagnosticFactory.kt @@ -10,9 +10,9 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticFactory import org.jetbrains.kotlin.diagnostics.Severity class SyntaxErrorDiagnosticFactory private constructor() : DiagnosticFactory(Severity.ERROR) { - override fun getName(): String { - return "SYNTAX" - } + override var name: String? + get() = "SYNTAX" + set(_) {} companion object { val INSTANCE = SyntaxErrorDiagnosticFactory() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Diagnostic.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Diagnostic.kt index 0a832d10a7b6b..be763ca2c0ad9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Diagnostic.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Diagnostic.kt @@ -24,6 +24,6 @@ interface Diagnostic { val severity: Severity val psiElement: PsiElement val textRanges: List - val psiFile: PsiFile + val psiFile: PsiFile? val isValid: Boolean } \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticUtils.java index 846690209459f..dabac77cfee7f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticUtils.java @@ -24,7 +24,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt; import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils; @@ -75,6 +74,9 @@ public static PsiDiagnosticUtils.LineAndColumn getLineAndColumn(@NotNull Diagnos List textRanges = diagnostic.getTextRanges(); if (textRanges.isEmpty()) return PsiDiagnosticUtils.LineAndColumn.NONE; TextRange firstRange = firstRange(textRanges); + if (file == null) { + return PsiDiagnosticUtils.LineAndColumn.NONE; + } return getLineAndColumnInPsiFile(file, firstRange); } @@ -90,6 +92,9 @@ public static PsiDiagnosticUtils.LineAndColumnRange getLineAndColumnRange(@NotNu List textRanges = diagnostic.getTextRanges(); if (textRanges.isEmpty()) return PsiDiagnosticUtils.LineAndColumnRange.NONE; TextRange firstRange = firstRange(textRanges); + if (file == null) { + return PsiDiagnosticUtils.LineAndColumnRange.NONE; + } return getLineAndColumnRangeInPsiFile(file, firstRange); } @@ -124,9 +129,13 @@ public static TextRange firstRange(@NotNull List ranges) { public static List sortedDiagnostics(@NotNull Collection diagnostics) { List result = Lists.newArrayList(diagnostics); result.sort((d1, d2) -> { - String path1 = d1.getPsiFile().getViewProvider().getVirtualFile().getPath(); - String path2 = d2.getPsiFile().getViewProvider().getVirtualFile().getPath(); - if (!path1.equals(path2)) return path1.compareTo(path2); + PsiFile file1 = d1.getPsiFile(); + PsiFile file2 = d2.getPsiFile(); + if (file1 != null && file2 != null) { + String path1 = file1.getViewProvider().getVirtualFile().getPath(); + String path2 = file2.getViewProvider().getVirtualFile().getPath(); + if (!path1.equals(path2)) return path1.compareTo(path2); + } TextRange range1 = firstRange(d1.getTextRanges()); TextRange range2 = firstRange(d2.getTextRanges()); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/KotlinSuppressCache.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/KotlinSuppressCache.kt index d870fc079c380..f0b46fcba4ee4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/KotlinSuppressCache.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/KotlinSuppressCache.kt @@ -164,7 +164,7 @@ abstract class KotlinSuppressCache { companion object { private fun getDiagnosticSuppressKey(diagnostic: Diagnostic): String = - diagnostic.factory.name.toLowerCase() + diagnostic.factory.name!!.toLowerCase() private fun isSuppressedByStrings(key: String, strings: Set, severity: Severity): Boolean = severity == Severity.WARNING && "warnings" in strings || key in strings diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/duplicateJvmSignatureUtil.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/duplicateJvmSignatureUtil.kt index 7b99d638eb3f4..f2780c4ef19a9 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/duplicateJvmSignatureUtil.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/duplicateJvmSignatureUtil.kt @@ -24,13 +24,12 @@ import org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration import org.jetbrains.kotlin.asJava.classes.getOutermostClassOrObject import org.jetbrains.kotlin.asJava.classes.safeIsScript import org.jetbrains.kotlin.diagnostics.Diagnostic -import org.jetbrains.kotlin.diagnostics.DiagnosticFactory.cast +import org.jetbrains.kotlin.diagnostics.DiagnosticFactory import org.jetbrains.kotlin.diagnostics.Errors.* import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics import org.jetbrains.kotlin.resolve.jvm.diagnostics.ConflictingJvmDeclarationsData -import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.* import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind.* @@ -90,8 +89,7 @@ fun getJvmSignatureDiagnostics(element: PsiElement, otherDiagnostics: Diagnostic return null } - val result = doGetDiagnostics() - if (result == null) return null + val result = doGetDiagnostics() ?: return null return FilteredJvmDiagnostics(result, otherDiagnostics) } @@ -111,7 +109,7 @@ class FilteredJvmDiagnostics(val jvmDiagnostics: Diagnostics, val otherDiagnosti } override fun forElement(psiElement: PsiElement): Collection { - fun Diagnostic.data() = cast(this, jvmDiagnosticFactories).a + fun Diagnostic.data() = DiagnosticFactory.cast(this, jvmDiagnosticFactories).a val (conflicting, other) = jvmDiagnostics.forElement(psiElement).partition { it.factory in jvmDiagnosticFactories } if (alreadyReported(psiElement)) { // CONFLICTING_OVERLOADS already reported, no need to duplicate it @@ -125,22 +123,19 @@ class FilteredJvmDiagnostics(val jvmDiagnostics: Diagnostics, val otherDiagnosti val diagnostics = it.value if (diagnostics.size <= 1) { filtered.addAll(diagnostics) - } - else { + } else { filtered.addAll( - diagnostics.filter { - me -> - diagnostics.none { - other -> - me != other && ( - // in case of implementation copied from a super trait there will be both diagnostics on the same signature - other.factory == ErrorsJvm.CONFLICTING_JVM_DECLARATIONS && (me.factory == ACCIDENTAL_OVERRIDE || - me.factory == CONFLICTING_INHERITED_JVM_DECLARATIONS) - // there are paris of corresponding signatures that frequently clash simultaneously: multifile class & part, trait and trait-impl - || other.data().higherThan(me.data()) - ) - } + diagnostics.filter { me -> + diagnostics.none { other -> + me != other && ( + // in case of implementation copied from a super trait there will be both diagnostics on the same signature + other.factory == CONFLICTING_JVM_DECLARATIONS && (me.factory == ACCIDENTAL_OVERRIDE || + me.factory == CONFLICTING_INHERITED_JVM_DECLARATIONS) + // there are paris of corresponding signatures that frequently clash simultaneously: multifile class & part, trait and trait-impl + || other.data().higherThan(me.data()) + ) } + } ) } } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirBaseDiagnosticsTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirBaseDiagnosticsTest.kt index df4ee22d13432..ee7f6b0241d8b 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirBaseDiagnosticsTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirBaseDiagnosticsTest.kt @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM import org.jetbrains.kotlin.diagnostics.PsiDiagnosticUtils import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic -import org.jetbrains.kotlin.fir.analysis.diagnostics.FirPsiDiagnostic import org.jetbrains.kotlin.fir.builder.RawFirBuilder import org.jetbrains.kotlin.fir.builder.RawFirBuilderMode import org.jetbrains.kotlin.fir.declarations.FirFile @@ -326,8 +325,7 @@ abstract class AbstractFirBaseDiagnosticsTest : BaseDiagnosticsTest() { private fun Iterable>.toActualDiagnostic(root: PsiElement): List { val result = mutableListOf() mapTo(result) { - val oldDiagnostic = (it as FirPsiDiagnostic<*>).asPsiBasedDiagnostic() - ActualDiagnostic(oldDiagnostic, null, true) + ActualDiagnostic(it, null, true) } for (errorElement in AnalyzingUtils.getSyntaxErrorRanges(root)) { result.add(ActualDiagnostic(SyntaxErrorDiagnostic(errorElement), null, true)) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt index 40ab827bdf2ae..5ee614c711482 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt @@ -40,7 +40,6 @@ import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitorVoid import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid import org.jetbrains.kotlin.name.FqNameUnsafe import org.jetbrains.kotlin.test.KotlinTestUtils -import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.utils.addIfNotNull import java.io.File @@ -63,8 +62,8 @@ import java.io.File */ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() { companion object { - val DUMP_CFG_DIRECTIVE = "DUMP_CFG" - val COMMON_COROUTINES_DIRECTIVE ="COMMON_COROUTINES_TEST" + const val DUMP_CFG_DIRECTIVE = "DUMP_CFG" + const val COMMON_COROUTINES_DIRECTIVE = "COMMON_COROUTINES_TEST" val TestFile.withDumpCfgDirective: Boolean get() = DUMP_CFG_DIRECTIVE in directives @@ -204,7 +203,8 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() { argument: () -> String, ): FirDiagnosticWithParameters1? { val sourceElement = element.source ?: return null - if (diagnosedRangesToDiagnosticNames[sourceElement.startOffset..sourceElement.endOffset]?.contains(this.name) != true) return null + val name = name ?: return null + if (diagnosedRangesToDiagnosticNames[sourceElement.startOffset..sourceElement.endOffset]?.contains(name) != true) return null val argumentText = argument() return when (sourceElement) { @@ -212,21 +212,13 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() { sourceElement, argumentText, severity, - FirDiagnosticFactory1( - name, - severity, - this - ) + FirDiagnosticFactory1(name, severity) ) is FirLightSourceElement -> FirLightDiagnosticWithParameters1( sourceElement, argumentText, severity, - FirDiagnosticFactory1( - name, - severity, - this - ) + FirDiagnosticFactory1(name, severity) ) } } @@ -324,13 +316,13 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() { private val cfgKinds = listOf(EdgeKind.DeadForward, EdgeKind.CfgForward, EdgeKind.DeadBackward, EdgeKind.CfgBackward) private fun checkEdge(from: CFGNode<*>, to: CFGNode<*>) { - KtUsefulTestCase.assertContainsElements(from.followingNodes, to) - KtUsefulTestCase.assertContainsElements(to.previousNodes, from) + assertContainsElements(from.followingNodes, to) + assertContainsElements(to.previousNodes, from) val fromKind = from.outgoingEdges.getValue(to).kind val toKind = to.incomingEdges.getValue(from).kind TestCase.assertEquals(fromKind, toKind) if (from.isDead && to.isDead) { - KtUsefulTestCase.assertContainsElements(cfgKinds, toKind) + assertContainsElements(cfgKinds, toKind) } } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticsWithLightTreeTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticsWithLightTreeTest.kt index 03a40c793f9f1..05169864ad202 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticsWithLightTreeTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticsWithLightTreeTest.kt @@ -57,7 +57,7 @@ abstract class AbstractFirDiagnosticsWithLightTreeTest : AbstractFirDiagnosticsT val expected = existingDiagnostics[startOffset] ?: emptyMap() val actual = actualDiagnostics[startOffset] ?: emptyMap() for (name in expected.keys + actual.keys) { - if (name == "SYNTAX") continue + if (name == null || name == "SYNTAX") continue val expectedCount = expected[name] ?: 0 val actualCount = actual[name] ?: 0 if (expectedCount != actualCount) { diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/validators/DiagnosticTestTypeValidator.kt b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/validators/DiagnosticTestTypeValidator.kt index 390c4492f83ce..405d6ea865b28 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/validators/DiagnosticTestTypeValidator.kt +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/validators/DiagnosticTestTypeValidator.kt @@ -28,7 +28,7 @@ class DiagnosticTestTypeValidator( private fun findTestCases(diagnostic: Diagnostic): TestCasesByNumbers { val ranges = diagnostic.textRanges - val filename = diagnostic.psiFile.name + val filename = diagnostic.psiFile!!.name val foundTestCases = testInfo.cases.byRanges[filename]!!.floorEntry(ranges[0].startOffset) if (foundTestCases != null) @@ -52,7 +52,7 @@ class DiagnosticTestTypeValidator( private fun collectDiagnostics(files: List) { files.forEach { file -> file.actualDiagnostics.forEach { - val diagnosticName = it.diagnostic.factory.name + val diagnosticName = it.diagnostic.factory.name!! diagnosticStats.run { put(diagnosticName, getOrDefault(diagnosticName, 0) + 1) } diagnostics.add(it.diagnostic) } diff --git a/compiler/tests/org/jetbrains/kotlin/resolve/MutableDiagnosticsTest.kt b/compiler/tests/org/jetbrains/kotlin/resolve/MutableDiagnosticsTest.kt index 77c44a487efeb..b2bc719a7f7cd 100644 --- a/compiler/tests/org/jetbrains/kotlin/resolve/MutableDiagnosticsTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/resolve/MutableDiagnosticsTest.kt @@ -30,9 +30,9 @@ import org.jetbrains.kotlin.test.KotlinTestWithEnvironment import org.junit.Assert class MutableDiagnosticsTest : KotlinTestWithEnvironment() { - override fun createEnvironment(): KotlinCoreEnvironment? { + override fun createEnvironment(): KotlinCoreEnvironment { return KotlinCoreEnvironment.createForTests( - testRootDisposable, KotlinTestUtils.newConfiguration(), EnvironmentConfigFiles.JVM_CONFIG_FILES + testRootDisposable, KotlinTestUtils.newConfiguration(), EnvironmentConfigFiles.JVM_CONFIG_FILES ) } @@ -137,19 +137,18 @@ class MutableDiagnosticsTest : KotlinTestWithEnvironment() { private class DummyDiagnosticFactory : DiagnosticFactory("DUMMY", Severity.ERROR) private inner class DummyDiagnostic : Diagnostic { - private val factory = DummyDiagnosticFactory() + override val factory = DummyDiagnosticFactory() private val dummyElement = KtPsiFactory(environment.project).createType("Int") init { - dummyElement.getContainingKtFile().doNotAnalyze = null + dummyElement.containingKtFile.doNotAnalyze = null } - override fun getFactory() = factory - override fun getSeverity() = factory.severity - override fun getPsiElement() = dummyElement - override fun getTextRanges() = unimplemented() - override fun getPsiFile() = unimplemented() - override fun isValid() = unimplemented() + override val severity get() = factory.severity + override val psiElement get() = dummyElement + override val textRanges get() = unimplemented() + override val psiFile get() = unimplemented() + override val isValid get() = unimplemented() private fun unimplemented(): Nothing = throw UnsupportedOperationException() } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/AnnotationPresentationInfo.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/AnnotationPresentationInfo.kt index cfb3997b2c1d9..cd8bd2cb27ad5 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/AnnotationPresentationInfo.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/AnnotationPresentationInfo.kt @@ -45,7 +45,7 @@ class AnnotationPresentationInfo( if (fixes.isEmpty()) { // if there are no quick fixes we need to register an EmptyIntentionAction to enable 'suppress' actions - annotation.newFix(EmptyIntentionAction(diagnostic.factory.name)).registerFix() + annotation.newFix(EmptyIntentionAction(diagnostic.factory.name!!)).registerFix() } } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuppressableWarningProblemGroup.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuppressableWarningProblemGroup.kt index 87b9da94409e8..39da8b8247bce 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuppressableWarningProblemGroup.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuppressableWarningProblemGroup.kt @@ -37,7 +37,7 @@ class KotlinSuppressableWarningProblemGroup( } fun createSuppressWarningActions(element: PsiElement, diagnosticFactory: DiagnosticFactory<*>): List = - createSuppressWarningActions(element, diagnosticFactory.severity, diagnosticFactory.name) + createSuppressWarningActions(element, diagnosticFactory.severity, diagnosticFactory.name!!) fun createSuppressWarningActions(element: PsiElement, severity: Severity, suppressionKey: String): List { diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostics/AbstractFirIdeDiagnosticsCollector.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostics/AbstractFirIdeDiagnosticsCollector.kt index 91f22f6947432..f05922086ee82 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostics/AbstractFirIdeDiagnosticsCollector.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostics/AbstractFirIdeDiagnosticsCollector.kt @@ -42,7 +42,7 @@ internal abstract class AbstractFirIdeDiagnosticsCollector( override fun report(diagnostic: FirDiagnostic<*>?) { if (diagnostic !is FirPsiDiagnostic<*>) return if (diagnostic.element.psi !is KtElement) return - onDiagnostic(diagnostic.asPsiBasedDiagnostic()) + onDiagnostic(diagnostic) } } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.kt index dcfd2cdc5a638..8629747baa1e6 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.kt @@ -261,7 +261,7 @@ class KotlinBytecodeToolWindow(private val myProject: Project, private val toolW answer.append("// ================\n") for (diagnostic in diagnostics) { answer.append("// Error at ") - .append(diagnostic.psiFile.name) + .append(diagnostic.psiFile?.name) .append(join(diagnostic.textRanges, ",")) .append(": ") .append(DefaultErrorMessages.render(diagnostic)) diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/MigrateDiagnosticSuppressionInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/MigrateDiagnosticSuppressionInspection.kt index d2bbd64e584ba..001814d5fb595 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/MigrateDiagnosticSuppressionInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/MigrateDiagnosticSuppressionInspection.kt @@ -46,7 +46,7 @@ class MigrateDiagnosticSuppressionInspection : AbstractKotlinInspection(), Clean } class ReplaceDiagnosticNameFix(private val diagnosticFactory: DiagnosticFactory<*>) : LocalQuickFix { - override fun getName() = KotlinBundle.message("replace.diagnostic.name.fix.text", familyName, diagnosticFactory.name) + override fun getName() = KotlinBundle.message("replace.diagnostic.name.fix.text", familyName, diagnosticFactory.name!!) override fun getFamilyName() = KotlinBundle.message("replace.diagnostic.name.fix.family.name") diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt index 5d7b8c8e32a33..f4820cd98978d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt @@ -128,7 +128,7 @@ class AddFunctionToSupertypeFix private constructor( val descriptors = generateFunctionsToAdd(function) if (descriptors.isEmpty()) return null - val project = diagnostic.psiFile.project + val project = diagnostic.psiFile!!.project val functionData = descriptors.mapNotNull { createFunctionData(it, project) } if (functionData.isEmpty()) return null diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddPropertyToSupertypeFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddPropertyToSupertypeFix.kt index 45aa2d1e5e668..a3458b509251a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddPropertyToSupertypeFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddPropertyToSupertypeFix.kt @@ -102,7 +102,7 @@ class AddPropertyToSupertypeFix private constructor( val descriptors = generatePropertiesToAdd(property) if (descriptors.isEmpty()) return null - val project = diagnostic.psiFile.project + val project = diagnostic.psiFile!!.project val propertyData = descriptors.mapNotNull { createPropertyData(it, property.initializer, project) } if (propertyData.isEmpty()) return null diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeMetaInfo/renderConfigurations/AbstractCodeMetaInfoRenderConfiguration.kt b/idea/tests/org/jetbrains/kotlin/idea/codeMetaInfo/renderConfigurations/AbstractCodeMetaInfoRenderConfiguration.kt index 6fff12d11d69d..4500557b0e0d1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeMetaInfo/renderConfigurations/AbstractCodeMetaInfoRenderConfiguration.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeMetaInfo/renderConfigurations/AbstractCodeMetaInfoRenderConfiguration.kt @@ -82,7 +82,7 @@ open class DiagnosticCodeMetaInfoRenderConfiguration( } fun getTag(codeMetaInfo: DiagnosticCodeMetaInfo): String { - return codeMetaInfo.diagnostic.factory.name + return codeMetaInfo.diagnostic.factory.name!! } } diff --git a/plugins/scripting/scripting-compiler/src/org/jetbrains/kotlin/scripting/compiler/plugin/repl/messages/IdeDiagnosticMessageHolder.kt b/plugins/scripting/scripting-compiler/src/org/jetbrains/kotlin/scripting/compiler/plugin/repl/messages/IdeDiagnosticMessageHolder.kt index 472c178879b83..bd6d3e0a8f340 100644 --- a/plugins/scripting/scripting-compiler/src/org/jetbrains/kotlin/scripting/compiler/plugin/repl/messages/IdeDiagnosticMessageHolder.kt +++ b/plugins/scripting/scripting-compiler/src/org/jetbrains/kotlin/scripting/compiler/plugin/repl/messages/IdeDiagnosticMessageHolder.kt @@ -15,7 +15,7 @@ import javax.xml.parsers.DocumentBuilderFactory class IdeDiagnosticMessageHolder : DiagnosticMessageHolder { private val diagnostics = arrayListOf>() - override fun report(diagnostic: Diagnostic, file: PsiFile, render: String) { + override fun report(diagnostic: Diagnostic, file: PsiFile?, render: String) { diagnostics.add(Pair(diagnostic, render)) }