Converted SoftKeywordsAnnotator to extra visitor invoked from JetPsiChecker.
This commit is contained in:
@@ -124,7 +124,6 @@
|
|||||||
<liveTemplateMacro implementation="org.jetbrains.jet.plugin.liveTemplates.macro.JetIterableVariableMacro"/>
|
<liveTemplateMacro implementation="org.jetbrains.jet.plugin.liveTemplates.macro.JetIterableVariableMacro"/>
|
||||||
<liveTemplateMacro implementation="org.jetbrains.jet.plugin.liveTemplates.macro.JetSuggestVariableNameMacro"/>
|
<liveTemplateMacro implementation="org.jetbrains.jet.plugin.liveTemplates.macro.JetSuggestVariableNameMacro"/>
|
||||||
|
|
||||||
<annotator language="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.SoftKeywordsAnnotator"/>
|
|
||||||
<annotator language="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.LabelsAnnotator"/>
|
<annotator language="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.LabelsAnnotator"/>
|
||||||
<annotator language="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.JetPsiChecker"/>
|
<annotator language="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.JetPsiChecker"/>
|
||||||
<annotator language="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.DebugInfoAnnotator"/>
|
<annotator language="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.DebugInfoAnnotator"/>
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ public class JetPsiChecker implements Annotator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) {
|
public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) {
|
||||||
|
element.accept(new SoftKeywordsHighlightingVisitor(holder));
|
||||||
|
|
||||||
if (element instanceof JetFile) {
|
if (element instanceof JetFile) {
|
||||||
JetFile file = (JetFile)element;
|
JetFile file = (JetFile)element;
|
||||||
|
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @author max
|
|
||||||
*/
|
|
||||||
package org.jetbrains.jet.plugin.highlighter;
|
|
||||||
|
|
||||||
import com.intellij.lang.ASTNode;
|
|
||||||
import com.intellij.lang.annotation.AnnotationHolder;
|
|
||||||
import com.intellij.lang.annotation.Annotator;
|
|
||||||
import com.intellij.openapi.application.ApplicationManager;
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
|
||||||
|
|
||||||
public class SoftKeywordsAnnotator implements Annotator {
|
|
||||||
public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) {
|
|
||||||
element.accept(new JetVisitorVoid() {
|
|
||||||
@Override
|
|
||||||
public void visitElement(PsiElement element) {
|
|
||||||
if (element instanceof LeafPsiElement) {
|
|
||||||
if (JetTokens.SOFT_KEYWORDS.contains(((LeafPsiElement) element).getElementType())) {
|
|
||||||
holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlightingColors.SOFT_KEYWORD);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) {
|
|
||||||
JetTypeReference typeReference = annotationEntry.getTypeReference();
|
|
||||||
if (typeReference != null) {
|
|
||||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
|
||||||
markAnnotationIdentifiers(typeElement, holder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
|
|
||||||
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
|
||||||
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
|
||||||
holder.createInfoAnnotation(functionLiteral.getOpenBraceNode(), null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET);
|
|
||||||
ASTNode closingBraceNode = functionLiteral.getClosingBraceNode();
|
|
||||||
if (closingBraceNode != null) {
|
|
||||||
holder.createInfoAnnotation(closingBraceNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET);
|
|
||||||
}
|
|
||||||
ASTNode arrowNode = functionLiteral.getArrowNode();
|
|
||||||
if (arrowNode != null) {
|
|
||||||
holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void markAnnotationIdentifiers(JetTypeElement typeElement, @NotNull AnnotationHolder holder) {
|
|
||||||
if (typeElement instanceof JetUserType) {
|
|
||||||
JetUserType userType = (JetUserType) typeElement;
|
|
||||||
if (userType.getQualifier() == null) {
|
|
||||||
JetSimpleNameExpression referenceExpression = userType.getReferenceExpression();
|
|
||||||
if (referenceExpression != null) {
|
|
||||||
holder.createInfoAnnotation(referenceExpression.getNode(), "Annotation").setTextAttributes(JetHighlightingColors.SOFT_KEYWORD);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author max
|
||||||
|
*/
|
||||||
|
package org.jetbrains.jet.plugin.highlighter;
|
||||||
|
|
||||||
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.lang.annotation.AnnotationHolder;
|
||||||
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
|
class SoftKeywordsHighlightingVisitor extends HighlightingVisitor {
|
||||||
|
SoftKeywordsHighlightingVisitor(AnnotationHolder holder) {
|
||||||
|
super(holder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitElement(PsiElement element) {
|
||||||
|
if (element instanceof LeafPsiElement) {
|
||||||
|
if (JetTokens.SOFT_KEYWORDS.contains(((LeafPsiElement) element).getElementType())) {
|
||||||
|
holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlightingColors.SOFT_KEYWORD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) {
|
||||||
|
JetTypeReference typeReference = annotationEntry.getTypeReference();
|
||||||
|
if (typeReference != null) {
|
||||||
|
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||||
|
markAnnotationIdentifiers(typeElement, holder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
|
||||||
|
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
||||||
|
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
||||||
|
holder.createInfoAnnotation(functionLiteral.getOpenBraceNode(), null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET);
|
||||||
|
ASTNode closingBraceNode = functionLiteral.getClosingBraceNode();
|
||||||
|
if (closingBraceNode != null) {
|
||||||
|
holder.createInfoAnnotation(closingBraceNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET);
|
||||||
|
}
|
||||||
|
ASTNode arrowNode = functionLiteral.getArrowNode();
|
||||||
|
if (arrowNode != null) {
|
||||||
|
holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void markAnnotationIdentifiers(JetTypeElement typeElement, @NotNull AnnotationHolder holder) {
|
||||||
|
if (typeElement instanceof JetUserType) {
|
||||||
|
JetUserType userType = (JetUserType) typeElement;
|
||||||
|
if (userType.getQualifier() == null) {
|
||||||
|
JetSimpleNameExpression referenceExpression = userType.getReferenceExpression();
|
||||||
|
if (referenceExpression != null) {
|
||||||
|
holder.createInfoAnnotation(referenceExpression.getNode(), "Annotation").setTextAttributes(JetHighlightingColors.SOFT_KEYWORD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user