use of com.intellij.openapi.editor.colors.TextAttributesKey in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoHighlightingAnnotator method highlightRefIfNeeded.
private static void highlightRefIfNeeded(@NotNull GoReferenceExpressionBase o, @Nullable PsiElement resolve, @NotNull AnnotationHolder holder) {
if (resolve instanceof GoTypeSpec) {
TextAttributesKey key = GoPsiImplUtil.builtin(resolve) ? BUILTIN_TYPE_REFERENCE : getColor((GoTypeSpec) resolve);
if (o.getParent() instanceof GoType) {
GoType topmostType = PsiTreeUtil.getTopmostParentOfType(o, GoType.class);
if (topmostType != null && topmostType.getParent() instanceof GoReceiver) {
key = TYPE_REFERENCE;
}
}
setHighlighting(o.getIdentifier(), holder, key);
} else if (resolve instanceof GoConstDefinition) {
TextAttributesKey color = GoPsiImplUtil.builtin(resolve) ? BUILTIN_TYPE_REFERENCE : getColor((GoConstDefinition) resolve);
setHighlighting(o.getIdentifier(), holder, color);
} else if (resolve instanceof GoVarDefinition) {
TextAttributesKey color = GoPsiImplUtil.builtin(resolve) ? BUILTIN_TYPE_REFERENCE : getColor((GoVarDefinition) resolve);
setHighlighting(o.getIdentifier(), holder, color);
} else if (resolve instanceof GoFieldDefinition) {
setHighlighting(o.getIdentifier(), holder, getColor((GoFieldDefinition) resolve));
} else if (resolve instanceof GoFunctionOrMethodDeclaration || resolve instanceof GoMethodSpec) {
setHighlighting(o.getIdentifier(), holder, getColor((GoNamedSignatureOwner) resolve));
} else if (resolve instanceof GoReceiver) {
setHighlighting(o.getIdentifier(), holder, METHOD_RECEIVER);
} else if (resolve instanceof GoParamDefinition) {
setHighlighting(o.getIdentifier(), holder, FUNCTION_PARAMETER);
}
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class ComponentTree method getAttributeWrapper.
private AttributeWrapper getAttributeWrapper(RadComponent component) {
AttributeWrapper wrapper = AttributeWrapper.DEFAULT;
final HighlightDisplayLevel level = getHighlightDisplayLevel(myDesigner.getProject(), component);
if (level != null) {
TextAttributesKey attributesKey = SeverityRegistrar.getSeverityRegistrar(myDesigner.getProject()).getHighlightInfoTypeBySeverity(level.getSeverity()).getAttributesKey();
final TextAttributes textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey);
wrapper = new AttributeWrapper() {
@Override
public SimpleTextAttributes getAttribute(SimpleTextAttributes attributes) {
Color bgColor = textAttributes.getBackgroundColor();
try {
textAttributes.setBackgroundColor(null);
return SimpleTextAttributes.fromTextAttributes(TextAttributes.merge(attributes.toTextAttributes(), textAttributes));
} finally {
textAttributes.setBackgroundColor(bgColor);
}
}
};
}
return wrapper;
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class PyConsoleSourceHighlighter method convertAttributes.
protected TextAttributes convertAttributes(TextAttributesKey[] keys) {
EditorColorsScheme scheme = myScheme;
TextAttributes attrs = scheme.getAttributes(HighlighterColors.TEXT);
for (TextAttributesKey key : keys) {
TextAttributes attrs2 = scheme.getAttributes(key);
if (attrs2 != null) {
attrs = TextAttributes.merge(attrs, attrs2);
}
}
return attrs;
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class XmlNamespaceAnnotator method annotate.
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (element instanceof XmlTag) {
XmlTag tag = (XmlTag) element;
String namespace = tag.getNamespace();
for (XmlNSColorProvider provider : PROVIDERS) {
TextAttributesKey key = provider.getKeyForNamespace(namespace, tag);
if (key != null) {
TextRange range = XmlTagUtil.getStartTagRange(tag);
if (range != null) {
holder.createInfoAnnotation(range, null).setTextAttributes(key);
}
TextRange endTagRange = XmlTagUtil.getEndTagRange(tag);
if (endTagRange != null) {
holder.createInfoAnnotation(endTagRange, null).setTextAttributes(key);
}
return;
}
}
}
}
use of com.intellij.openapi.editor.colors.TextAttributesKey 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();
}
}
Aggregations