diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/JavaSoftKeywordHighlighting.kt b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/JavaSoftKeywordHighlighting.kt new file mode 100644 index 000000000000..f6185a665ba5 --- /dev/null +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/JavaSoftKeywordHighlighting.kt @@ -0,0 +1,72 @@ +/* + * Copyright 2000-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 com.intellij.codeInsight.daemon.impl + +import com.intellij.codeHighlighting.TextEditorHighlightingPass +import com.intellij.codeHighlighting.TextEditorHighlightingPassFactory +import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar +import com.intellij.lang.java.lexer.JavaLexer +import com.intellij.openapi.components.AbstractProjectComponent +import com.intellij.openapi.editor.Document +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.progress.ProgressIndicator +import com.intellij.openapi.project.Project +import com.intellij.pom.java.LanguageLevel +import com.intellij.psi.JavaRecursiveElementVisitor +import com.intellij.psi.PsiFile +import com.intellij.psi.PsiJavaFile +import com.intellij.psi.PsiKeyword + +class JavaSoftKeywordHighlightingPassFactory(project: Project, registrar: TextEditorHighlightingPassRegistrar) : + AbstractProjectComponent(project), TextEditorHighlightingPassFactory { + + init { + registrar.registerTextEditorHighlightingPass(this, null, null, false, -1) + } + + override fun createHighlightingPass(file: PsiFile, editor: Editor): TextEditorHighlightingPass? = + if (file is PsiJavaFile && file.languageLevel.isAtLeast(LanguageLevel.JDK_1_9)) JavaSoftKeywordHighlightingPass(file, editor.document) + else null +} + +private class JavaSoftKeywordHighlightingPass(private val file: PsiJavaFile, document: Document) : + TextEditorHighlightingPass(file.project, document) { + + private val results = mutableListOf() + + override fun doCollectInformation(progress: ProgressIndicator) { + file.accept(JavaSoftKeywordHighlightingVisitor(results, file.languageLevel)) + } + + override fun doApplyInformationToEditor() { + if (results.isNotEmpty()) { + UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument!!, 0, file.textLength, results, colorsScheme, id) + } + } +} + +private class JavaSoftKeywordHighlightingVisitor(private val results: MutableList, private val level: LanguageLevel) : + JavaRecursiveElementVisitor() { + + override fun visitKeyword(keyword: PsiKeyword) { + if (JavaLexer.isSoftKeyword(keyword.text, level)) { + val info = HighlightInfo.newHighlightInfo(JavaHighlightInfoTypes.JAVA_KEYWORD).range(keyword).create() + if (info != null) { + results += info + } + } + } +} \ No newline at end of file diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index 8feaf9f4e086..1d258b485068 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -22,7 +22,6 @@ import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil.Feature; import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction; import com.intellij.codeInsight.intention.QuickFixFactory; import com.intellij.lang.injection.InjectedLanguageManager; -import com.intellij.lang.java.lexer.JavaLexer; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.colors.TextAttributesScheme; @@ -761,11 +760,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitKeyword(PsiKeyword keyword) { super.visitKeyword(keyword); - - if (JavaLexer.isSoftKeyword(keyword.getText(), myLanguageLevel)) { - myHolder.add(HighlightInfo.newHighlightInfo(JavaHighlightInfoTypes.JAVA_KEYWORD).range(keyword).create()); - } - PsiElement parent = keyword.getParent(); String text = keyword.getText(); if (parent instanceof PsiModifierList) { diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 2190175682b5..af99e8b1d513 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -71,6 +71,11 @@ com.intellij.execution.scratch.JavaScratchCompilationSupport + + + com.intellij.codeInsight.daemon.impl.JavaSoftKeywordHighlightingPassFactory + + com.intellij.codeInsight.hints.ParameterHintsPassFactory