From f41548a6642fc3206bc0bb21c783e8b0767a7899 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 14:45:11 +0400 Subject: [PATCH] Converted SoftKeywordsAnnotator to extra visitor invoked from JetPsiChecker. --- idea/src/META-INF/plugin.xml | 1 - .../jet/plugin/highlighter/JetPsiChecker.java | 2 + .../highlighter/SoftKeywordsAnnotator.java | 81 ------------------- .../SoftKeywordsHighlightingVisitor.java | 80 ++++++++++++++++++ 4 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java create mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index caf29ab9868..77a8b4a1d62 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -124,7 +124,6 @@ - diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 7cbbffdcd22..b4e5790d540 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -57,6 +57,8 @@ public class JetPsiChecker implements Annotator { @Override public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { + element.accept(new SoftKeywordsHighlightingVisitor(holder)); + if (element instanceof JetFile) { JetFile file = (JetFile)element; diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java deleted file mode 100644 index 9b9079d5f1f..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java +++ /dev/null @@ -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); - } - } - } - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java new file mode 100644 index 00000000000..0aa1ea36870 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java @@ -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); + } + } + } + } +}