Search in sources :

Example 11 with Annotation

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

the class HighlightingAnnotator method visitPyParameter.

@Override
public void visitPyParameter(PyParameter node) {
    PyFunction function = PsiTreeUtil.getParentOfType(node, PyFunction.class);
    if (function != null) {
        final PsiElement anchor = node.hasDefaultValue() ? node.getFirstChild() : node;
        final Annotation annotation = getHolder().createInfoAnnotation(anchor, null);
        annotation.setTextAttributes(node.isSelf() ? PyHighlighter.PY_SELF_PARAMETER : PyHighlighter.PY_PARAMETER);
    }
}
Also used : PsiElement(com.intellij.psi.PsiElement) Annotation(com.intellij.lang.annotation.Annotation)

Example 12 with Annotation

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

the class PyBuiltinAnnotator method highlightAsAttribute.

/**
   * Try to highlight a node as a class attribute.
   *
   * @param node what to work with
   * @return true iff the node was highlighted.
   */
private boolean highlightAsAttribute(@NotNull PyQualifiedExpression node, @NotNull String name) {
    final LanguageLevel languageLevel = LanguageLevel.forElement(node);
    if (PyNames.UnderscoredAttributes.contains(name) || PyNames.getBuiltinMethods(languageLevel).containsKey(name)) {
        // things like __len__: foo.__len__ or class Foo: ... __len__ = my_len_impl
        if (node.isQualified() || ScopeUtil.getScopeOwner(node) instanceof PyClass) {
            final ASTNode astNode = node.getNode();
            if (astNode != null) {
                // only the id, not all qualifiers subtree
                final ASTNode tgt = astNode.findChildByType(PyTokenTypes.IDENTIFIER);
                if (tgt != null) {
                    final Annotation ann = getHolder().createInfoAnnotation(tgt, null);
                    ann.setTextAttributes(PyHighlighter.PY_PREDEFINED_USAGE);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ASTNode(com.intellij.lang.ASTNode) Annotation(com.intellij.lang.annotation.Annotation)

Example 13 with Annotation

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

the class PyDefinitionsAnnotator method visitPyClass.

@Override
public void visitPyClass(PyClass node) {
    final ASTNode name_node = node.getNameNode();
    if (name_node != null) {
        Annotation ann = getHolder().createInfoAnnotation(name_node, null);
        ann.setTextAttributes(PyHighlighter.PY_CLASS_DEFINITION);
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) Annotation(com.intellij.lang.annotation.Annotation)

Example 14 with Annotation

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

the class ReferenceAnnotator method addError.

private void addError(PsiReference reference) {
    final TextRange rangeInElement = reference.getRangeInElement();
    final TextRange range = TextRange.from(reference.getElement().getTextRange().getStartOffset() + rangeInElement.getStartOffset(), rangeInElement.getLength());
    final Annotation annotation;
    if (reference instanceof EmptyResolveMessageProvider) {
        final String s = ((EmptyResolveMessageProvider) reference).getUnresolvedMessagePattern();
        annotation = myHolder.createErrorAnnotation(range, MessageFormat.format(s, reference.getCanonicalText()));
    } else {
        annotation = myHolder.createErrorAnnotation(range, "Cannot resolve symbol");
    }
    annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
    if (reference instanceof LocalQuickFixProvider) {
        LocalQuickFix[] fixes = ((LocalQuickFixProvider) reference).getQuickFixes();
        if (fixes != null) {
            InspectionManager inspectionManager = InspectionManager.getInstance(reference.getElement().getProject());
            for (LocalQuickFix fix : fixes) {
                ProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(reference.getElement(), annotation.getMessage(), fix, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, true);
                annotation.registerFix(fix, null, null, descriptor);
            }
        }
    }
}
Also used : EmptyResolveMessageProvider(com.intellij.codeInsight.daemon.EmptyResolveMessageProvider) TextRange(com.intellij.openapi.util.TextRange) Annotation(com.intellij.lang.annotation.Annotation)

Example 15 with Annotation

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

the class XPathAnnotator method visitXPathBinaryExpression.

@Override
public void visitXPathBinaryExpression(final XPathBinaryExpression o) {
    final XPathExpression operand = o.getLOperand();
    if (operand != null && o.getXPathVersion() == XPathVersion.V2) {
        final XPathElementType operator = o.getOperator();
        if (XPath2TokenTypes.COMP_OPS.contains(operator)) {
            if (operand instanceof XPathBinaryExpression && XPath2TokenTypes.COMP_OPS.contains(((XPathBinaryExpression) operand).getOperator())) {
                final Annotation annotation = myHolder.createErrorAnnotation(o, "Consecutive comparison is not allowed in XPath 2");
                final XPathExpression rOperand = o.getROperand();
                if (rOperand != null) {
                    final String replacement = "(" + operand.getText() + ") " + o.getOperationSign() + " " + rOperand.getText();
                    annotation.registerFix(new ExpressionReplacementFix(replacement, o));
                }
            }
            if (XPath2TokenTypes.NODE_COMP_OPS.contains(operator)) {
                checkApplicability(o, XPath2Type.NODE);
            } else if (operator == XPath2TokenTypes.WEQ || operator == XPath2TokenTypes.WNE || operator == XPathTokenTypes.EQ || operator == XPathTokenTypes.NE) {
                checkApplicability(o, XPath2Type.NUMERIC, XPath2Type.BOOLEAN, XPath2Type.STRING, XPath2Type.DATE, XPath2Type.TIME, XPath2Type.DATETIME, XPath2Type.DURATION, XPath2Type.HEXBINARY, XPath2Type.BASE64BINARY, XPath2Type.ANYURI, XPath2Type.QNAME);
            } else if (operator == XPath2TokenTypes.WGT || operator == XPath2TokenTypes.WGE || operator == XPath2TokenTypes.WLE || operator == XPath2TokenTypes.WLT || operator == XPathTokenTypes.GT || operator == XPathTokenTypes.GE || operator == XPathTokenTypes.LE || operator == XPathTokenTypes.LT) {
                checkApplicability(o, XPath2Type.NUMERIC, XPath2Type.BOOLEAN, XPath2Type.STRING, XPath2Type.DATE, XPath2Type.TIME, XPath2Type.DATETIME, XPath2Type.DURATION, XPath2Type.ANYURI);
            }
        } else if (XPath2TokenTypes.UNION_OPS.contains(operator) || XPath2TokenTypes.INTERSECT_EXCEPT.contains(operator)) {
            checkApplicability(o, XPath2SequenceType.create(XPath2Type.NODE, XPath2SequenceType.Cardinality.ZERO_OR_MORE));
        } else if (operator == XPath2TokenTypes.TO) {
            checkApplicability(o, XPath2Type.INTEGER);
        } else if (operator == XPathTokenTypes.AND || operator == XPathTokenTypes.OR) {
            checkApplicability(o, XPath2Type.BOOLEAN);
        } else if (XPathTokenTypes.ADD_OPS.contains(operator)) {
            checkApplicability(o, XPath2Type.NUMERIC, XPath2Type.DURATION, XPath2Type.DATE, XPath2Type.TIME, XPath2Type.DATETIME);
        } else if (XPath2TokenTypes.MULT_OPS.contains(operator)) {
            if (operator == XPath2TokenTypes.IDIV || operator == XPathTokenTypes.MOD) {
                checkApplicability(o, XPath2Type.NUMERIC);
            } else if (operator == XPathTokenTypes.DIV) {
                checkApplicability(o, XPath2Type.NUMERIC, XPath2Type.DURATION);
            } else {
                assert operator == XPathTokenTypes.MULT;
                checkApplicability(o, XPath2Type.NUMERIC, XPath2Type.DURATION);
            }
        }
    }
    checkExpression(myHolder, o);
    super.visitXPathBinaryExpression(o);
}
Also used : XPathElementType(org.intellij.lang.xpath.XPathElementType) 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