Search in sources :

Example 6 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class YouTrackHighlightingAnnotator method apply.

@Override
public void apply(@NotNull PsiFile file, List<HighlightRange> ranges, @NotNull AnnotationHolder holder) {
    for (HighlightRange range : ranges) {
        if (range.getStyleClass().equals("error")) {
            holder.createErrorAnnotation(range.getTextRange(), null);
        } else {
            final Annotation infoAnnotation = holder.createInfoAnnotation(range.getTextRange(), null);
            infoAnnotation.setEnforcedTextAttributes(range.getTextAttributes());
        }
    }
}
Also used : HighlightRange(com.intellij.tasks.youtrack.YouTrackIntellisense.HighlightRange) Annotation(com.intellij.lang.annotation.Annotation)

Example 7 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class PropertiesAnnotator method highlightTokens.

private static void highlightTokens(final Property property, final ASTNode node, final AnnotationHolder holder, PropertiesHighlighter highlighter) {
    Lexer lexer = highlighter.getHighlightingLexer();
    final String s = node.getText();
    lexer.start(s);
    while (lexer.getTokenType() != null) {
        IElementType elementType = lexer.getTokenType();
        TextAttributesKey[] keys = highlighter.getTokenHighlights(elementType);
        for (TextAttributesKey key : keys) {
            Pair<String, HighlightSeverity> pair = PropertiesHighlighter.DISPLAY_NAMES.get(key);
            String displayName = pair.getFirst();
            HighlightSeverity severity = pair.getSecond();
            if (severity != null) {
                int start = lexer.getTokenStart() + node.getTextRange().getStartOffset();
                int end = lexer.getTokenEnd() + node.getTextRange().getStartOffset();
                TextRange textRange = new TextRange(start, end);
                final Annotation annotation;
                if (severity == HighlightSeverity.WARNING) {
                    annotation = holder.createWarningAnnotation(textRange, displayName);
                } else if (severity == HighlightSeverity.ERROR) {
                    annotation = holder.createErrorAnnotation(textRange, displayName);
                } else {
                    annotation = holder.createInfoAnnotation(textRange, displayName);
                }
                TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
                annotation.setEnforcedTextAttributes(attributes);
                if (key == PropertiesHighlighter.PROPERTIES_INVALID_STRING_ESCAPE) {
                    annotation.registerFix(new IntentionAction() {

                        @NotNull
                        public String getText() {
                            return PropertiesBundle.message("unescape");
                        }

                        @NotNull
                        public String getFamilyName() {
                            return getText();
                        }

                        public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
                            if (!property.isValid() || !property.getManager().isInProject(property))
                                return false;
                            String text = property.getPropertiesFile().getContainingFile().getText();
                            int startOffset = annotation.getStartOffset();
                            return text.length() > startOffset && text.charAt(startOffset) == '\\';
                        }

                        public void invoke(@NotNull Project project, Editor editor, PsiFile file) {
                            int offset = annotation.getStartOffset();
                            if (property.getPropertiesFile().getContainingFile().getText().charAt(offset) == '\\') {
                                editor.getDocument().deleteString(offset, offset + 1);
                            }
                        }

                        public boolean startInWriteAction() {
                            return true;
                        }
                    });
                }
            }
        }
        lexer.advance();
    }
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TextRange(com.intellij.openapi.util.TextRange) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) NotNull(org.jetbrains.annotations.NotNull) Annotation(com.intellij.lang.annotation.Annotation) IElementType(com.intellij.psi.tree.IElementType) Project(com.intellij.openapi.project.Project) Lexer(com.intellij.lexer.Lexer) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 8 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class DocStringAnnotator method visitPyAssignmentStatement.

@Override
public void visitPyAssignmentStatement(PyAssignmentStatement node) {
    if (node.isAssignmentTo(PyNames.DOC)) {
        PyExpression right = node.getAssignedValue();
        if (right instanceof PyStringLiteralExpression) {
            Annotation ann = getHolder().createInfoAnnotation(right, null);
            ann.setTextAttributes(PyHighlighter.PY_DOC_COMMENT);
            annotateDocStringStmt((PyStringLiteralExpression) right);
        }
    }
}
Also used : Annotation(com.intellij.lang.annotation.Annotation)

Example 9 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class DumbAwareHighlightingAnnotator method highlightAsKeyword.

private void highlightAsKeyword(@Nullable ASTNode astNode) {
    if (astNode != null) {
        final Annotation annotation = getHolder().createInfoAnnotation(astNode, null);
        annotation.setTextAttributes(PyHighlighter.PY_KEYWORD);
    }
}
Also used : Annotation(com.intellij.lang.annotation.Annotation)

Example 10 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class HighlightingAnnotator method visitPyReferenceExpression.

@Override
public void visitPyReferenceExpression(PyReferenceExpression node) {
    final String referencedName = node.getReferencedName();
    if (!node.isQualified() && referencedName != null) {
        PyFunction function = PsiTreeUtil.getParentOfType(node, PyFunction.class);
        if (function != null) {
            final PyNamedParameter element = function.getParameterList().findParameterByName(referencedName);
            if (element != null) {
                Annotation annotation = getHolder().createInfoAnnotation(node, null);
                annotation.setTextAttributes(element.isSelf() ? PyHighlighter.PY_SELF_PARAMETER : PyHighlighter.PY_PARAMETER);
            }
        }
    }
}
Also used : Annotation(com.intellij.lang.annotation.Annotation)

Aggregations

Annotation (com.intellij.lang.annotation.Annotation)97 PsiElement (com.intellij.psi.PsiElement)24 ASTNode (com.intellij.lang.ASTNode)22 TextRange (com.intellij.openapi.util.TextRange)19 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)15 Project (com.intellij.openapi.project.Project)11 NotNull (org.jetbrains.annotations.NotNull)10 PsiFile (com.intellij.psi.PsiFile)8 GrModifierFix (org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix)6 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)4 Editor (com.intellij.openapi.editor.Editor)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 GrModifierList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList)4 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)3 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)3 PsiReference (com.intellij.psi.PsiReference)3 IElementType (com.intellij.psi.tree.IElementType)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 Nullable (org.jetbrains.annotations.Nullable)3 HbCloseBlockMustache (com.dmarcotte.handlebars.psi.HbCloseBlockMustache)2