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 files (IDEA-164939)
This commit is contained in:
+6
@@ -22,6 +22,7 @@ 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;
|
||||
@@ -760,6 +761,11 @@ 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) {
|
||||
|
||||
@@ -19,8 +19,6 @@ import com.intellij.lang.java.JavaParserDefinition;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.JavaDocTokenType;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.PsiKeyword;
|
||||
import com.intellij.psi.impl.source.tree.ElementType;
|
||||
import com.intellij.psi.impl.source.tree.JavaDocElementType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -29,9 +27,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author max
|
||||
*/
|
||||
public class JavaHighlightingLexer extends LayeredLexer {
|
||||
private boolean myAtStart = true;
|
||||
private boolean myModuleInfo = false;
|
||||
|
||||
public JavaHighlightingLexer(@NotNull LanguageLevel languageLevel) {
|
||||
super(JavaParserDefinition.createLexer(languageLevel));
|
||||
|
||||
@@ -47,28 +42,4 @@ public class JavaHighlightingLexer extends LayeredLexer {
|
||||
docLexer.registerLayer(htmlLexer, JavaDocTokenType.DOC_COMMENT_DATA);
|
||||
registerSelfStoppingLayer(docLexer, new IElementType[]{JavaDocElementType.DOC_COMMENT}, IElementType.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElementType getTokenType() {
|
||||
IElementType t = super.getTokenType();
|
||||
|
||||
if (myAtStart && !isLayerActive() && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(t)) {
|
||||
myAtStart = false;
|
||||
myModuleInfo = t == JavaTokenType.IDENTIFIER && PsiKeyword.MODULE.equals(getTokenText());
|
||||
}
|
||||
|
||||
if (myModuleInfo && t == JavaTokenType.IDENTIFIER) {
|
||||
switch (getTokenText()) {
|
||||
case PsiKeyword.MODULE: t = JavaTokenType.MODULE_KEYWORD; break;
|
||||
case PsiKeyword.REQUIRES: t = JavaTokenType.REQUIRES_KEYWORD; break;
|
||||
case PsiKeyword.EXPORTS: t = JavaTokenType.EXPORTS_KEYWORD; break;
|
||||
case PsiKeyword.USES: t = JavaTokenType.USES_KEYWORD; break;
|
||||
case PsiKeyword.PROVIDES: t = JavaTokenType.PROVIDES_KEYWORD; break;
|
||||
case PsiKeyword.TO: t = JavaTokenType.TO_KEYWORD; break;
|
||||
case PsiKeyword.WITH: t = JavaTokenType.WITH_KEYWORD; break;
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user