mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] fixes soft keyword highlighting in source and .class files (IDEA-164939)
This commit is contained in:
+72
@@ -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<HighlightInfo>()
|
||||
|
||||
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<HighlightInfo>, 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-6
@@ -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) {
|
||||
|
||||
@@ -71,6 +71,11 @@
|
||||
<component>
|
||||
<implementation-class>com.intellij.execution.scratch.JavaScratchCompilationSupport</implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<implementation-class>com.intellij.codeInsight.daemon.impl.JavaSoftKeywordHighlightingPassFactory</implementation-class>
|
||||
<skipForDefaultProject/>
|
||||
</component>
|
||||
<component>
|
||||
<implementation-class>com.intellij.codeInsight.hints.ParameterHintsPassFactory</implementation-class>
|
||||
<skipForDefaultProject/>
|
||||
|
||||
Reference in New Issue
Block a user