[FIR] Fix max parameters count in diagnostics from 3 to 4

This commit is contained in:
Ivan Kochurkin
2021-05-20 16:37:39 +03:00
committed by TeamCityServer
parent 7f591bcfd4
commit 6de97e17fe
6 changed files with 202 additions and 0 deletions
@@ -54,6 +54,18 @@ fun <P : PsiElement, A : Any, B : Any, C : Any> DiagnosticReporter.reportOn(
source?.let { report(factory.on(it, a, b, c), context) }
}
fun <P : PsiElement, A : Any, B : Any, C : Any, D : Any> DiagnosticReporter.reportOn(
source: FirSourceElement?,
factory: FirDiagnosticFactory4<P, A, B, C, D>,
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 <P : PsiElement, A : Any, B : Any, C : Any> DiagnosticReporter.reportOnWithS
}
}
fun <P : PsiElement, A : Any, B : Any, C : Any, D : Any> DiagnosticReporter.reportOnWithSuppression(
element: FirElement,
factory: FirDiagnosticFactory4<P, A, B, C, D>,
a: A,
b: B,
c: C,
d: D,
context: CheckerContext
) {
withSuppressedDiagnostics(element, context) {
reportOn(element.source, factory, a, b, c, d, it)
}
}
@@ -144,6 +144,7 @@ class FirDiagnosticFactory4<P : PsiElement, A, B, C, D>(
}
}
}
private fun incorrectElement(element: FirSourceElement): Nothing {
throw IllegalArgumentException("Unknown element type: ${element::class}")
}
@@ -174,3 +175,13 @@ fun <P : PsiElement, A, B, C> FirDiagnosticFactory3<P, A, B, C>.on(
): FirDiagnosticWithParameters3<*, A, B, C>? {
return element?.let { on(it, a, b, c) }
}
fun <P : PsiElement, A, B, C, D> FirDiagnosticFactory4<P, A, B, C, D>.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) }
}
@@ -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<E extends PsiElement, A, B, C, D> extends DiagnosticFactoryWithPsiElement<E, DiagnosticWithParameters4<E, A, B, C, D>> {
protected DiagnosticFactory4(Severity severity, PositioningStrategy<? super E> positioningStrategy) {
super(severity, positioningStrategy);
}
@NotNull
public static <T extends PsiElement, A, B, C, D> DiagnosticFactory4<T, A, B, C, D> create(Severity severity) {
return create(severity, PositioningStrategies.DEFAULT);
}
@NotNull
public static <T extends PsiElement, A, B, C, D> DiagnosticFactory4<T, A, B, C, D> create(Severity severity, PositioningStrategy<? super T> positioningStrategy) {
return new DiagnosticFactory4<>(severity, positioningStrategy);
}
@NotNull
public ParametrizedDiagnostic<E> 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());
}
}
@@ -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<E extends PsiElement, A, B, C, D> extends AbstractDiagnostic<E> {
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<E, A, B, C, D> 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<E, A, B, C, D> getFactory() {
return (DiagnosticFactory4<E, A, B, C, D>) 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);
}
}
@@ -79,6 +79,16 @@ public final class DiagnosticFactoryToRendererMap {
map.put(factory, new DiagnosticWithParameters3Renderer<A, B, C>(message, rendererA, rendererB, rendererC));
}
public <E extends PsiElement, A, B, C, D> void put(@NotNull DiagnosticFactory4<E, A, B, C, D> factory,
@NotNull String message,
@Nullable DiagnosticParameterRenderer<? super A> rendererA,
@Nullable DiagnosticParameterRenderer<? super B> rendererB,
@Nullable DiagnosticParameterRenderer<? super C> rendererC,
@Nullable DiagnosticParameterRenderer<? super D> rendererD) {
checkMutability();
map.put(factory, new DiagnosticWithParameters4Renderer<A, B, C, D>(message, rendererA, rendererB, rendererC, rendererD));
}
public void put(@NotNull DiagnosticFactory<?> factory, @NotNull DiagnosticRenderer<?> renderer) {
checkMutability();
map.put(factory, renderer);
@@ -75,6 +75,25 @@ class DiagnosticWithParameters3Renderer<A, B, C>(
}
}
class DiagnosticWithParameters4Renderer<A : Any, B : Any, C : Any, D : Any>(
message: String,
private val rendererForA: DiagnosticParameterRenderer<A>?,
private val rendererForB: DiagnosticParameterRenderer<B>?,
private val rendererForC: DiagnosticParameterRenderer<C>?,
private val rendererForD: DiagnosticParameterRenderer<D>?,
) : AbstractDiagnosticWithParametersRenderer<DiagnosticWithParameters4<*, A, B, C, D>>(message) {
override fun renderParameters(diagnostic: DiagnosticWithParameters4<*, A, B, C, D>): Array<out Any> {
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<A>(
message: String,
private val renderer: MultiRenderer<A>