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