Extract the suppressing logic for debugger.

This commit is contained in:
Zalim Bashorov
2014-10-23 21:41:09 +04:00
parent cd20301283
commit 38d5f2ee2b
3 changed files with 40 additions and 18 deletions
@@ -23,7 +23,6 @@ import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.ModificationTracker;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.containers.ConcurrentWeakValueHashMap;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.FilteringIterator;
@@ -31,14 +30,10 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.diagnostics.Severity;
import org.jetbrains.jet.lang.psi.JetAnnotated;
import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetStubbedPsiUtil;
import org.jetbrains.jet.lang.psi.codeFragmentUtil.CodeFragmentUtilPackage;
import org.jetbrains.jet.lang.resolve.constants.ArrayValue;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.constants.StringValue;
@@ -121,25 +116,12 @@ public class DiagnosticsWithSuppression implements Diagnostics {
if (suppressor.isSuppressed(diagnostic)) return true;
}
if (isSuppressedForDebugger(diagnostic, element)) return true;
JetAnnotated annotated = JetStubbedPsiUtil.getPsiOrStubParent(element, JetAnnotated.class, false);
if (annotated == null) return false;
return isSuppressedByAnnotated(diagnostic, annotated, 0);
}
private static boolean isSuppressedForDebugger(@NotNull Diagnostic diagnostic, @NotNull PsiElement element) {
PsiFile containingFile = element.getContainingFile();
if (containingFile instanceof JetFile && CodeFragmentUtilPackage.getSkipVisibilityCheck((JetFile) containingFile)) {
DiagnosticFactory<?> diagnosticFactory = diagnostic.getFactory();
return diagnosticFactory == Errors.INVISIBLE_MEMBER ||
diagnosticFactory == Errors.INVISIBLE_REFERENCE ||
diagnosticFactory == Errors.INVISIBLE_SETTER;
}
return false;
}
/*
The cache is optimized for the case where no warnings are suppressed (most frequent one)
+1
View File
@@ -818,5 +818,6 @@
<projectConfigurator implementation="org.jetbrains.jet.plugin.configuration.KotlinJsModuleConfigurator"/>
<suppressStringProvider implementation="org.jetbrains.k2js.analyze.SuppressUnusedParameterForJsNative"/>
<diagnosticSuppressor implementation="org.jetbrains.k2js.analyze.SuppressWarningsFromExternalModules"/>
<diagnosticSuppressor implementation="org.jetbrains.jet.plugin.debugger.DiagnosticSuppressorForDebugger"/>
</extensions>
</idea-plugin>
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2014 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.jet.plugin.debugger
import org.jetbrains.jet.lang.resolve.DiagnosticsWithSuppression
import org.jetbrains.jet.lang.diagnostics.Diagnostic
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.diagnostics.Errors
import org.jetbrains.jet.lang.psi.codeFragmentUtil.skipVisibilityCheck
public class DiagnosticSuppressorForDebugger : DiagnosticsWithSuppression.DiagnosticSuppressor {
override fun isSuppressed(diagnostic: Diagnostic): Boolean {
val element = diagnostic.getPsiElement()
val containingFile = element.getContainingFile()
if (containingFile is JetFile && containingFile.skipVisibilityCheck) {
val diagnosticFactory = diagnostic.getFactory()
return diagnosticFactory == Errors.INVISIBLE_MEMBER ||
diagnosticFactory == Errors.INVISIBLE_REFERENCE ||
diagnosticFactory == Errors.INVISIBLE_SETTER
}
return false
}
}