Show only unique diagnostics in psi checker (KT-35578)
MissingDependencyClassChecker.collectDiagnostics now show only unique diagnostics As per-file analyzer trace used in checker delegates to resolve session trace, diagnostics might be duplicated because of race condition: 1. If a non-checker thread performs analyze first, diagnostics for global elements will be stored in the resolve session trace only once. 2 If the checker threads comes to the analyze first, diagnostics will be stored in the local trace, and after that might be duplicated in the resolve session trace by other analyzers. #KT-35578 Fixed
This commit is contained in:
committed by
Nikolay Krasko
parent
75beaa861f
commit
e99dc0f87f
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class AbstractDiagnostic<E extends PsiElement> implements ParametrizedDiagnostic<E> {
|
||||
private final E psiElement;
|
||||
@@ -71,4 +72,19 @@ public abstract class AbstractDiagnostic<E extends PsiElement> implements Parame
|
||||
if (!getFactory().isValid(this)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AbstractDiagnostic<?> that = (AbstractDiagnostic<?>) o;
|
||||
return Objects.equals(psiElement, that.psiElement) &&
|
||||
Objects.equals(factory, that.factory) &&
|
||||
severity == that.severity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(psiElement, factory, severity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.jetbrains.kotlin.diagnostics;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DiagnosticWithParameters1<E extends PsiElement, A> extends AbstractDiagnostic<E> {
|
||||
private final A a;
|
||||
|
||||
@@ -48,4 +50,18 @@ public class DiagnosticWithParameters1<E extends PsiElement, A> extends Abstract
|
||||
public String toString() {
|
||||
return getFactory() + "(a = " + a + ")";
|
||||
}
|
||||
|
||||
@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;
|
||||
DiagnosticWithParameters1<?, ?> that = (DiagnosticWithParameters1<?, ?>) o;
|
||||
return Objects.equals(a, that.a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), a);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.jetbrains.kotlin.diagnostics;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DiagnosticWithParameters2<E extends PsiElement, A, B> extends AbstractDiagnostic<E> {
|
||||
private final A a;
|
||||
private final B b;
|
||||
@@ -56,4 +58,19 @@ public class DiagnosticWithParameters2<E extends PsiElement, A, B> extends Abstr
|
||||
public String toString() {
|
||||
return getFactory() + "(a = " + a + ", b = " + b + ")";
|
||||
}
|
||||
|
||||
@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;
|
||||
DiagnosticWithParameters2<?, ?, ?> that = (DiagnosticWithParameters2<?, ?, ?>) o;
|
||||
return Objects.equals(a, that.a) &&
|
||||
Objects.equals(b, that.b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), a, b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.jetbrains.kotlin.diagnostics;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DiagnosticWithParameters3<E extends PsiElement, A, B, C> extends AbstractDiagnostic<E> {
|
||||
private final A a;
|
||||
private final B b;
|
||||
@@ -64,4 +66,20 @@ public class DiagnosticWithParameters3<E extends PsiElement, A, B, C> extends Ab
|
||||
public String toString() {
|
||||
return getFactory() + "(a = " + a + ", b = " + b + ", c = " + c + ")";
|
||||
}
|
||||
|
||||
@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;
|
||||
DiagnosticWithParameters3<?, ?, ?, ?> that = (DiagnosticWithParameters3<?, ?, ?, ?>) o;
|
||||
return Objects.equals(a, that.a) &&
|
||||
Objects.equals(b, that.b) &&
|
||||
Objects.equals(c, that.c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), a, b, c);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user