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);
}
}
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;
}
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);
}
}
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);
}
}
}
}
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);
}
Aggregations