diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingUtil.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingUtil.kt new file mode 100644 index 00000000000..51e6dbf55a0 --- /dev/null +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingUtil.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2016 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.idea.highlighter + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.idea.util.ProjectRootsUtil +import org.jetbrains.kotlin.psi.KtCodeFragment +import org.jetbrains.kotlin.psi.KtFile + +object KotlinHighlightingUtil { + fun shouldHighlight(psiElement: PsiElement): Boolean { + val ktFile = psiElement.containingFile as? KtFile ?: return false + return ktFile is KtCodeFragment || ktFile.isScript || ProjectRootsUtil.isInProjectOrLibraryContent(ktFile) + } + + fun shouldHighlightErrors(psiElement: PsiElement): Boolean { + val ktFile = psiElement.containingFile as? KtFile ?: return false + return ktFile is KtCodeFragment || ktFile.isScript || ProjectRootsUtil.isInProjectSource(ktFile) + } +} \ No newline at end of file diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinProblemHighlightFilter.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinProblemHighlightFilter.kt index 3671be71da3..775c44ed73f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinProblemHighlightFilter.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinProblemHighlightFilter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -19,12 +19,12 @@ package org.jetbrains.kotlin.idea.highlighter import com.intellij.codeInsight.daemon.ProblemHighlightFilter import com.intellij.psi.PsiFile import org.jetbrains.kotlin.idea.KotlinFileType -import com.intellij.ide.projectView.impl.ProjectRootsUtil class KotlinProblemHighlightFilter : ProblemHighlightFilter() { override fun shouldHighlight(psiFile: PsiFile): Boolean { - return psiFile.fileType != KotlinFileType.INSTANCE || !ProjectRootsUtil.isOutsideSourceRoot(psiFile) - } + if (psiFile.fileType == KotlinFileType.INSTANCE && !KotlinHighlightingUtil.shouldHighlight(psiFile)) return false + return true + } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt index 94def0afba2..2389f52840d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -56,9 +56,9 @@ import java.util.* open class KotlinPsiChecker : Annotator, HighlightRangeExtension { override fun annotate(element: PsiElement, holder: AnnotationHolder) { - if (!(ProjectRootsUtil.isInProjectOrLibraryContent(element) || element.containingFile is KtCodeFragment)) return + val file = element.containingFile as? KtFile ?: return - val file = element.containingFile as KtFile + if (!KotlinHighlightingUtil.shouldHighlight(file)) return val analysisResult = file.analyzeFullyAndGetResult() if (analysisResult.isError()) { @@ -88,7 +88,7 @@ open class KotlinPsiChecker : Annotator, HighlightRangeExtension { if (diagnosticsForElement.isEmpty()) return - if (ProjectRootsUtil.isInProjectSource(element) || element.containingFile is KtCodeFragment) { + if (KotlinHighlightingUtil.shouldHighlightErrors(element)) { ElementAnnotator(element, holder, { param -> shouldSuppressUnusedParameter(param) }).registerDiagnosticsAnnotations(diagnosticsForElement) } }