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 RegExpAnnotator method visitRegExpBackref.
@Override
public void visitRegExpBackref(final RegExpBackref backref) {
final RegExpGroup group = backref.resolve();
if (group == null) {
final Annotation a = myHolder.createErrorAnnotation(backref, "Unresolved back reference");
a.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
} else if (PsiTreeUtil.isAncestor(group, backref, true)) {
myHolder.createWarningAnnotation(backref, "Back reference is nested into the capturing group it refers to");
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class RegExpAnnotator method visitRegExpChar.
@Override
public void visitRegExpChar(final RegExpChar ch) {
final PsiElement child = ch.getFirstChild();
final IElementType type = child.getNode().getElementType();
if (type == StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN) {
myHolder.createErrorAnnotation(ch, "Illegal/unsupported escape sequence");
return;
} else if (type == RegExpTT.BAD_HEX_VALUE) {
myHolder.createErrorAnnotation(ch, "Illegal hexadecimal escape sequence");
return;
} else if (type == RegExpTT.BAD_OCT_VALUE) {
myHolder.createErrorAnnotation(ch, "Illegal octal escape sequence");
return;
} else if (type == StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN) {
myHolder.createErrorAnnotation(ch, "Illegal unicode escape sequence");
return;
}
final String text = ch.getUnescapedText();
if (type == RegExpTT.ESC_CTRL_CHARACTER && text.equals("\\b") && !myLanguageHosts.supportsLiteralBackspace(ch)) {
myHolder.createErrorAnnotation(ch, "Illegal/unsupported escape sequence");
}
if (text.startsWith("\\") && myLanguageHosts.isRedundantEscape(ch, text)) {
final ASTNode astNode = ch.getNode().getFirstChildNode();
if (astNode != null && astNode.getElementType() == RegExpTT.REDUNDANT_ESCAPE) {
final Annotation a = myHolder.createWeakWarningAnnotation(ch, "Redundant character escape");
registerFix(a, new RemoveRedundantEscapeAction(ch));
}
}
final RegExpChar.Type charType = ch.getType();
if (charType == RegExpChar.Type.HEX || charType == RegExpChar.Type.UNICODE) {
if (ch.getValue() == -1) {
myHolder.createErrorAnnotation(ch, "Illegal unicode escape sequence");
return;
}
if (text.charAt(text.length() - 1) == '}') {
if (!myLanguageHosts.supportsExtendedHexCharacter(ch)) {
myHolder.createErrorAnnotation(ch, "This hex character syntax is not supported in this regex dialect");
}
}
}
}
Aggregations