Filter diagnostics during creating cache
This commit is contained in:
+9
-4
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.resolve.diagnostics;
|
package org.jetbrains.kotlin.resolve.diagnostics;
|
||||||
|
|
||||||
import com.intellij.openapi.util.AtomicNotNullLazyValue;
|
import com.intellij.openapi.util.AtomicNotNullLazyValue;
|
||||||
|
import com.intellij.openapi.util.Condition;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.util.containers.ConcurrentMultiMap;
|
import com.intellij.util.containers.ConcurrentMultiMap;
|
||||||
import com.intellij.util.containers.MultiMap;
|
import com.intellij.util.containers.MultiMap;
|
||||||
@@ -27,17 +28,19 @@ import java.util.Collection;
|
|||||||
|
|
||||||
public class DiagnosticsElementsCache {
|
public class DiagnosticsElementsCache {
|
||||||
private final Diagnostics diagnostics;
|
private final Diagnostics diagnostics;
|
||||||
|
private final Condition<Diagnostic> filter;
|
||||||
|
|
||||||
private final AtomicNotNullLazyValue<MultiMap<PsiElement, Diagnostic>> elementToDiagnostic = new AtomicNotNullLazyValue<MultiMap<PsiElement, Diagnostic>>() {
|
private final AtomicNotNullLazyValue<MultiMap<PsiElement, Diagnostic>> elementToDiagnostic = new AtomicNotNullLazyValue<MultiMap<PsiElement, Diagnostic>>() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected MultiMap<PsiElement, Diagnostic> compute() {
|
protected MultiMap<PsiElement, Diagnostic> compute() {
|
||||||
return buildElementToDiagnosticCache(diagnostics);
|
return buildElementToDiagnosticCache(diagnostics, filter);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public DiagnosticsElementsCache(Diagnostics diagnostics) {
|
public DiagnosticsElementsCache(Diagnostics diagnostics, Condition<Diagnostic> filter) {
|
||||||
this.diagnostics = diagnostics;
|
this.diagnostics = diagnostics;
|
||||||
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -45,10 +48,12 @@ public class DiagnosticsElementsCache {
|
|||||||
return elementToDiagnostic.getValue().get(psiElement);
|
return elementToDiagnostic.getValue().get(psiElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MultiMap<PsiElement, Diagnostic> buildElementToDiagnosticCache(Diagnostics diagnostics) {
|
private static MultiMap<PsiElement, Diagnostic> buildElementToDiagnosticCache(Diagnostics diagnostics, Condition<Diagnostic> filter) {
|
||||||
MultiMap<PsiElement, Diagnostic> elementToDiagnostic = new ConcurrentMultiMap<PsiElement, Diagnostic>();
|
MultiMap<PsiElement, Diagnostic> elementToDiagnostic = new ConcurrentMultiMap<PsiElement, Diagnostic>();
|
||||||
for (Diagnostic diagnostic : diagnostics) {
|
for (Diagnostic diagnostic : diagnostics) {
|
||||||
elementToDiagnostic.putValue(diagnostic.getPsiElement(), diagnostic);
|
if (filter.value(diagnostic)) {
|
||||||
|
elementToDiagnostic.putValue(diagnostic.getPsiElement(), diagnostic);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return elementToDiagnostic;
|
return elementToDiagnostic;
|
||||||
|
|||||||
+1
-1
@@ -76,7 +76,7 @@ public class DiagnosticsWithSuppression implements Diagnostics {
|
|||||||
return !isSuppressed(diagnostic);
|
return !isSuppressed(diagnostic);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private final DiagnosticsElementsCache elementsCache = new DiagnosticsElementsCache(this);
|
private final DiagnosticsElementsCache elementsCache = new DiagnosticsElementsCache(this, filter);
|
||||||
|
|
||||||
public DiagnosticsWithSuppression(@NotNull BindingContext context, @NotNull Collection<Diagnostic> diagnostics) {
|
public DiagnosticsWithSuppression(@NotNull BindingContext context, @NotNull Collection<Diagnostic> diagnostics) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.diagnostics
|
package org.jetbrains.kotlin.resolve.diagnostics
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.Condition
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
@@ -23,7 +24,9 @@ import java.util.ArrayList
|
|||||||
public class SimpleDiagnostics(diagnostics: Collection<Diagnostic>) : Diagnostics {
|
public class SimpleDiagnostics(diagnostics: Collection<Diagnostic>) : Diagnostics {
|
||||||
//copy to prevent external change
|
//copy to prevent external change
|
||||||
private val diagnostics = ArrayList(diagnostics)
|
private val diagnostics = ArrayList(diagnostics)
|
||||||
private val elementsCache = DiagnosticsElementsCache(this)
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
private val elementsCache = DiagnosticsElementsCache(this, Condition.TRUE as Condition<Diagnostic>?)
|
||||||
|
|
||||||
override fun all() = diagnostics
|
override fun all() = diagnostics
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user