From 7622e9043878e28a7d6e775318ef41e36b5d2d83 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 23 Nov 2015 20:46:53 +0300 Subject: [PATCH] Filter diagnostics during creating cache --- .../diagnostics/DiagnosticsElementsCache.java | 13 +++++++++---- .../diagnostics/DiagnosticsWithSuppression.java | 2 +- .../kotlin/resolve/diagnostics/SimpleDiagnostics.kt | 5 ++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/DiagnosticsElementsCache.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/DiagnosticsElementsCache.java index ab9f6f21e18..88fcd6875e9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/DiagnosticsElementsCache.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/DiagnosticsElementsCache.java @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.resolve.diagnostics; import com.intellij.openapi.util.AtomicNotNullLazyValue; +import com.intellij.openapi.util.Condition; import com.intellij.psi.PsiElement; import com.intellij.util.containers.ConcurrentMultiMap; import com.intellij.util.containers.MultiMap; @@ -27,17 +28,19 @@ import java.util.Collection; public class DiagnosticsElementsCache { private final Diagnostics diagnostics; + private final Condition filter; private final AtomicNotNullLazyValue> elementToDiagnostic = new AtomicNotNullLazyValue>() { @NotNull @Override protected MultiMap compute() { - return buildElementToDiagnosticCache(diagnostics); + return buildElementToDiagnosticCache(diagnostics, filter); } }; - public DiagnosticsElementsCache(Diagnostics diagnostics) { + public DiagnosticsElementsCache(Diagnostics diagnostics, Condition filter) { this.diagnostics = diagnostics; + this.filter = filter; } @NotNull @@ -45,10 +48,12 @@ public class DiagnosticsElementsCache { return elementToDiagnostic.getValue().get(psiElement); } - private static MultiMap buildElementToDiagnosticCache(Diagnostics diagnostics) { + private static MultiMap buildElementToDiagnosticCache(Diagnostics diagnostics, Condition filter) { MultiMap elementToDiagnostic = new ConcurrentMultiMap(); for (Diagnostic diagnostic : diagnostics) { - elementToDiagnostic.putValue(diagnostic.getPsiElement(), diagnostic); + if (filter.value(diagnostic)) { + elementToDiagnostic.putValue(diagnostic.getPsiElement(), diagnostic); + } } return elementToDiagnostic; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/DiagnosticsWithSuppression.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/DiagnosticsWithSuppression.java index bfab7e70a78..bf5aaa7c24c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/DiagnosticsWithSuppression.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/DiagnosticsWithSuppression.java @@ -76,7 +76,7 @@ public class DiagnosticsWithSuppression implements Diagnostics { 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 diagnostics) { this.context = context; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/SimpleDiagnostics.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/SimpleDiagnostics.kt index c208b7b518d..61742186c11 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/SimpleDiagnostics.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/diagnostics/SimpleDiagnostics.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.resolve.diagnostics +import com.intellij.openapi.util.Condition import com.intellij.psi.PsiElement import org.jetbrains.kotlin.diagnostics.Diagnostic import java.util.ArrayList @@ -23,7 +24,9 @@ import java.util.ArrayList public class SimpleDiagnostics(diagnostics: Collection) : Diagnostics { //copy to prevent external change private val diagnostics = ArrayList(diagnostics) - private val elementsCache = DiagnosticsElementsCache(this) + + @Suppress("UNCHECKED_CAST") + private val elementsCache = DiagnosticsElementsCache(this, Condition.TRUE as Condition?) override fun all() = diagnostics