Converted LabelsAnnotator to extra visitor invoked from JetPsiChecker.

This commit is contained in:
Evgeny Gerashchenko
2012-03-29 14:49:07 +04:00
parent f41548a664
commit 0079df05b0
3 changed files with 19 additions and 21 deletions
-1
View File
@@ -124,7 +124,6 @@
<liveTemplateMacro implementation="org.jetbrains.jet.plugin.liveTemplates.macro.JetIterableVariableMacro"/>
<liveTemplateMacro implementation="org.jetbrains.jet.plugin.liveTemplates.macro.JetSuggestVariableNameMacro"/>
<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.DebugInfoAnnotator"/>
@@ -58,7 +58,8 @@ public class JetPsiChecker implements Annotator {
@Override
public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) {
element.accept(new SoftKeywordsHighlightingVisitor(holder));
element.accept(new LabelsHighlightingVisitor(holder));
if (element instanceof JetFile) {
JetFile file = (JetFile)element;
@@ -29,26 +29,24 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
import org.jetbrains.jet.lexer.JetTokens;
public class LabelsAnnotator implements Annotator {
public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) {
// if (ApplicationManager.getApplication().isUnitTestMode()) return;
element.accept(new JetVisitorVoid() {
@Override
public void visitPrefixExpression(JetPrefixExpression expression) {
JetSimpleNameExpression operationSign = expression.getOperationReference();
if (JetTokens.LABELS.contains(operationSign.getReferencedNameElementType())) {
holder.createInfoAnnotation(operationSign, null).setTextAttributes(JetHighlightingColors.LABEL);
}
}
class LabelsHighlightingVisitor extends HighlightingVisitor {
LabelsHighlightingVisitor(AnnotationHolder holder) {
super(holder);
}
@Override
public void visitLabelQualifiedExpression(JetLabelQualifiedExpression expression) {
JetSimpleNameExpression targetLabel = expression.getTargetLabel();
if (targetLabel != null) {
holder.createInfoAnnotation(targetLabel, null).setTextAttributes(JetHighlightingColors.LABEL);
}
}
@Override
public void visitPrefixExpression(JetPrefixExpression expression) {
JetSimpleNameExpression operationSign = expression.getOperationReference();
if (JetTokens.LABELS.contains(operationSign.getReferencedNameElementType())) {
holder.createInfoAnnotation(operationSign, null).setTextAttributes(JetHighlightingColors.LABEL);
}
}
});
@Override
public void visitLabelQualifiedExpression(JetLabelQualifiedExpression expression) {
JetSimpleNameExpression targetLabel = expression.getTargetLabel();
if (targetLabel != null) {
holder.createInfoAnnotation(targetLabel, null).setTextAttributes(JetHighlightingColors.LABEL);
}
}
}