diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/DiagnosticReporter.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/DiagnosticReporter.kt index c64a5f5767d..0a5bd2ff499 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/DiagnosticReporter.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/DiagnosticReporter.kt @@ -54,6 +54,18 @@ fun

DiagnosticReporter.reportOn( source?.let { report(factory.on(it, a, b, c), context) } } +fun

DiagnosticReporter.reportOn( + source: FirSourceElement?, + factory: FirDiagnosticFactory4, + a: A, + b: B, + c: C, + d: D, + context: CheckerContext +) { + source?.let { report(factory.on(it, a, b, c, d), context) } +} + inline fun withSuppressedDiagnostics( element: FirElement, context: CheckerContext, @@ -120,3 +132,17 @@ fun

DiagnosticReporter.reportOnWithS } } +fun

DiagnosticReporter.reportOnWithSuppression( + element: FirElement, + factory: FirDiagnosticFactory4, + a: A, + b: B, + c: C, + d: D, + context: CheckerContext +) { + withSuppressedDiagnostics(element, context) { + reportOn(element.source, factory, a, b, c, d, it) + } +} + 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 27eace6946e..09bf47a9735 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 @@ -144,6 +144,7 @@ class FirDiagnosticFactory4

( } } } + private fun incorrectElement(element: FirSourceElement): Nothing { throw IllegalArgumentException("Unknown element type: ${element::class}") } @@ -174,3 +175,13 @@ fun

FirDiagnosticFactory3.on( ): FirDiagnosticWithParameters3<*, A, B, C>? { return element?.let { on(it, a, b, c) } } + +fun

FirDiagnosticFactory4.on( + element: FirSourceElement?, + a: A, + b: B, + c: C, + d: D +): FirDiagnosticWithParameters4<*, A, B, C, D>? { + return element?.let { on(it, a, b, c, d) } +} \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticFactory4.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticFactory4.java new file mode 100644 index 00000000000..139dbe58cd8 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticFactory4.java @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.diagnostics; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; + +public class DiagnosticFactory4 extends DiagnosticFactoryWithPsiElement> { + + protected DiagnosticFactory4(Severity severity, PositioningStrategy positioningStrategy) { + super(severity, positioningStrategy); + } + + @NotNull + public static DiagnosticFactory4 create(Severity severity) { + return create(severity, PositioningStrategies.DEFAULT); + } + + @NotNull + public static DiagnosticFactory4 create(Severity severity, PositioningStrategy positioningStrategy) { + return new DiagnosticFactory4<>(severity, positioningStrategy); + } + + @NotNull + public ParametrizedDiagnostic on(@NotNull E element, @NotNull A a, @NotNull B b, @NotNull C c, @NotNull D d) { + return new DiagnosticWithParameters4<>(element, a, b, c, d,this, getSeverity()); + } +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticWithParameters4.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticWithParameters4.java new file mode 100644 index 00000000000..94e12775690 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/DiagnosticWithParameters4.java @@ -0,0 +1,94 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.diagnostics; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + +public class DiagnosticWithParameters4 extends AbstractDiagnostic { + private final A a; + private final B b; + private final C c; + private final D d; + + public DiagnosticWithParameters4( + @NotNull E psiElement, + @NotNull A a, + @NotNull B b, + @NotNull C c, + @NotNull D d, + @NotNull DiagnosticFactory4 factory, + @NotNull Severity severity + ) { + super(psiElement, factory, severity); + this.a = a; + this.b = b; + this.c = c; + this.d = d; + } + + @NotNull + @Override + @SuppressWarnings("unchecked") + public DiagnosticFactory4 getFactory() { + return (DiagnosticFactory4) super.getFactory(); + } + + @NotNull + public A getA() { + return a; + } + + @NotNull + public B getB() { + return b; + } + + @NotNull + public C getC() { + return c; + } + + @NotNull + public D getD() { + return d; + } + + @Override + public String toString() { + return getFactory() + "(a = " + a + ", b = " + b + ", c = " + c + ", d = " + d + ")"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + DiagnosticWithParameters4 that = (DiagnosticWithParameters4) o; + return Objects.equals(a, that.a) && + Objects.equals(b, that.b) && + Objects.equals(c, that.c) && + Objects.equals(d, that.d); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), a, b, c, d); + } +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DiagnosticFactoryToRendererMap.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DiagnosticFactoryToRendererMap.java index e74dca1ed96..cd054f58042 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DiagnosticFactoryToRendererMap.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DiagnosticFactoryToRendererMap.java @@ -79,6 +79,16 @@ public final class DiagnosticFactoryToRendererMap { map.put(factory, new DiagnosticWithParameters3Renderer(message, rendererA, rendererB, rendererC)); } + public void put(@NotNull DiagnosticFactory4 factory, + @NotNull String message, + @Nullable DiagnosticParameterRenderer rendererA, + @Nullable DiagnosticParameterRenderer rendererB, + @Nullable DiagnosticParameterRenderer rendererC, + @Nullable DiagnosticParameterRenderer rendererD) { + checkMutability(); + map.put(factory, new DiagnosticWithParameters4Renderer(message, rendererA, rendererB, rendererC, rendererD)); + } + public void put(@NotNull DiagnosticFactory factory, @NotNull DiagnosticRenderer renderer) { checkMutability(); map.put(factory, renderer); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/diagnosticsWithParameterRenderers.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/diagnosticsWithParameterRenderers.kt index adc9d920afa..63478703e93 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/diagnosticsWithParameterRenderers.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/diagnosticsWithParameterRenderers.kt @@ -75,6 +75,25 @@ class DiagnosticWithParameters3Renderer( } } +class DiagnosticWithParameters4Renderer( + message: String, + private val rendererForA: DiagnosticParameterRenderer?, + private val rendererForB: DiagnosticParameterRenderer?, + private val rendererForC: DiagnosticParameterRenderer?, + private val rendererForD: DiagnosticParameterRenderer?, +) : AbstractDiagnosticWithParametersRenderer>(message) { + + override fun renderParameters(diagnostic: DiagnosticWithParameters4<*, A, B, C, D>): Array { + val context = RenderingContext.of(diagnostic.a, diagnostic.b, diagnostic.c, diagnostic.d) + return arrayOf( + renderParameter(diagnostic.a, rendererForA, context), + renderParameter(diagnostic.b, rendererForB, context), + renderParameter(diagnostic.c, rendererForC, context), + renderParameter(diagnostic.d, rendererForD, context), + ) + } +} + class DiagnosticWithParametersMultiRenderer( message: String, private val renderer: MultiRenderer