Search in sources :

Example 1 with DartTernaryExpression

use of com.jetbrains.lang.dart.psi.DartTernaryExpression in project intellij-plugins by JetBrains.

the class DartAnnotator method annotate.

@Override
public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder holder) {
    if (holder.isBatchMode())
        return;
    final AnnotationSession session = holder.getCurrentAnnotationSession();
    if (session.getUserData(DART_SERVER_DATA_HANDLED) != Boolean.TRUE) {
        session.putUserData(DART_SERVER_DATA_HANDLED, Boolean.TRUE);
        final VirtualFile vFile = element.getContainingFile().getVirtualFile();
        final DartAnalysisServerService service = DartAnalysisServerService.getInstance(element.getProject());
        if (canBeAnalyzedByServer(element.getProject(), vFile) && service.serverReadyForRequest(element.getProject())) {
            service.updateFilesContent();
            if (ApplicationManager.getApplication().isUnitTestMode()) {
                service.waitForAnalysisToComplete_TESTS_ONLY(vFile);
            }
            applyServerHighlighting(vFile, holder);
        }
    }
    if (DartTokenTypes.COLON == element.getNode().getElementType() && element.getParent() instanceof DartTernaryExpression) {
        holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.OPERATION_SIGN);
        return;
    }
    if (DartTokenTypesSets.BUILT_IN_IDENTIFIERS.contains(element.getNode().getElementType())) {
        if (element.getNode().getTreeParent().getElementType() != DartTokenTypes.ID) {
            holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.KEYWORD);
            return;
        }
    }
    // sync*, async* and yield*
    if (DartTokenTypes.MUL == element.getNode().getElementType()) {
        final ASTNode previous = element.getNode().getTreePrev();
        if (previous != null && (previous.getElementType() == DartTokenTypes.SYNC || previous.getElementType() == DartTokenTypes.ASYNC || previous.getElementType() == DartTokenTypes.YIELD)) {
            holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.KEYWORD);
        }
    }
    if (element.getNode().getElementType() == DartTokenTypes.REGULAR_STRING_PART) {
        highlightEscapeSequences(element, holder);
        return;
    }
    if (element instanceof DartSymbolLiteralExpression) {
        holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.SYMBOL_LITERAL);
        //noinspection UnnecessaryReturnStatement
        return;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnnotationSession(com.intellij.lang.annotation.AnnotationSession) DartSymbolLiteralExpression(com.jetbrains.lang.dart.psi.DartSymbolLiteralExpression) ASTNode(com.intellij.lang.ASTNode) DartTernaryExpression(com.jetbrains.lang.dart.psi.DartTernaryExpression) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)

Aggregations

ASTNode (com.intellij.lang.ASTNode)1 AnnotationSession (com.intellij.lang.annotation.AnnotationSession)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)1 DartSymbolLiteralExpression (com.jetbrains.lang.dart.psi.DartSymbolLiteralExpression)1 DartTernaryExpression (com.jetbrains.lang.dart.psi.DartTernaryExpression)1