use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class AdvHighlightingTest method testScopeBased.
public void testScopeBased() throws Exception {
NamedScope xScope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_SOURCE, null));
NamedScope utilScope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null));
NamedScopeManager scopeManager = NamedScopeManager.getInstance(getProject());
scopeManager.addScope(xScope);
scopeManager.addScope(utilScope);
EditorColorsManager manager = EditorColorsManager.getInstance();
EditorColorsScheme scheme = (EditorColorsScheme) manager.getGlobalScheme().clone();
manager.addColorsScheme(scheme);
EditorColorsManager.getInstance().setGlobalScheme(scheme);
TextAttributesKey xKey = ScopeAttributesUtil.getScopeTextAttributeKey(xScope.getName());
TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, EffectType.BOXED, Font.ITALIC);
scheme.setAttributes(xKey, xAttributes);
TextAttributesKey utilKey = ScopeAttributesUtil.getScopeTextAttributeKey(utilScope.getName());
TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD);
scheme.setAttributes(utilKey, utilAttributes);
try {
testFile(BASE_PATH + "/scopeBased/x/X.java").projectRoot(BASE_PATH + "/scopeBased").checkSymbolNames().test();
} finally {
scopeManager.removeAllSets();
}
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class ChunkExtractor method convertAttributes.
@NotNull
private TextAttributes convertAttributes(@NotNull TextAttributesKey[] keys) {
TextAttributes attrs = myColorsScheme.getAttributes(HighlighterColors.TEXT);
for (TextAttributesKey key : keys) {
TextAttributes attrs2 = myColorsScheme.getAttributes(key);
if (attrs2 != null) {
attrs = TextAttributes.merge(attrs, attrs2);
}
}
attrs = attrs.clone();
return attrs;
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class ExpectedHighlightingData method extractExpectedHighlight.
private int extractExpectedHighlight(final Matcher matcher, final String text, final Document document, final Ref<Integer> textOffset) {
document.deleteString(textOffset.get(), textOffset.get() + matcher.end() - matcher.start());
int groupIdx = 1;
final String marker = matcher.group(groupIdx++);
String descr = matcher.group(groupIdx++);
final String typeString = matcher.group(groupIdx++);
final String foregroundColor = matcher.group(groupIdx++);
final String backgroundColor = matcher.group(groupIdx++);
final String effectColor = matcher.group(groupIdx++);
final String effectType = matcher.group(groupIdx++);
final String fontType = matcher.group(groupIdx++);
final String attrKey = matcher.group(groupIdx++);
final String bundleMessage = matcher.group(groupIdx++);
final boolean closed = matcher.group(groupIdx) != null;
if (descr == null) {
// no descr means any string by default
descr = ANY_TEXT;
} else if (descr.equals("null")) {
// explicit "null" descr
descr = null;
}
if (descr != null) {
// replace: \\" to ", doesn't check symbol before sequence \\"
descr = descr.replaceAll("\\\\\\\\\"", "\"");
descr = descr.replaceAll("\\\\\"", "\"");
}
HighlightInfoType type = WHATEVER;
if (typeString != null) {
try {
type = getTypeByName(typeString);
} catch (Exception e) {
LOG.error(e);
}
LOG.assertTrue(type != null, "Wrong highlight type: " + typeString);
}
TextAttributes forcedAttributes = null;
if (foregroundColor != null) {
//noinspection MagicConstant
forcedAttributes = new TextAttributes(Color.decode(foregroundColor), Color.decode(backgroundColor), Color.decode(effectColor), EffectType.valueOf(effectType), Integer.parseInt(fontType));
}
final int rangeStart = textOffset.get();
final int toContinueFrom;
if (closed) {
toContinueFrom = matcher.end();
} else {
int pos = matcher.end();
final Matcher closingTagMatcher = Pattern.compile("</" + marker + ">").matcher(text);
while (true) {
if (!closingTagMatcher.find(pos)) {
LOG.error("Cannot find closing </" + marker + "> in position " + pos);
}
final int nextTagStart = matcher.find(pos) ? matcher.start() : text.length();
if (closingTagMatcher.start() < nextTagStart) {
textOffset.set(textOffset.get() + closingTagMatcher.start() - pos);
document.deleteString(textOffset.get(), textOffset.get() + closingTagMatcher.end() - closingTagMatcher.start());
toContinueFrom = closingTagMatcher.end();
break;
}
textOffset.set(textOffset.get() + nextTagStart - pos);
pos = extractExpectedHighlight(matcher, text, document, textOffset);
}
}
final ExpectedHighlightingSet expectedHighlightingSet = myHighlightingTypes.get(marker);
if (expectedHighlightingSet.enabled) {
TextAttributesKey forcedTextAttributesKey = attrKey == null ? null : TextAttributesKey.createTextAttributesKey(attrKey);
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(rangeStart, textOffset.get()).severity(expectedHighlightingSet.severity);
if (forcedAttributes != null)
builder.textAttributes(forcedAttributes);
if (forcedTextAttributesKey != null)
builder.textAttributes(forcedTextAttributesKey);
if (bundleMessage != null) {
final List<String> split = StringUtil.split(bundleMessage, "|");
final ResourceBundle bundle = ResourceBundle.getBundle(split.get(0));
descr = CommonBundle.message(bundle, split.get(1), split.stream().skip(2).toArray());
}
if (descr != null) {
builder.description(descr);
builder.unescapedToolTip(descr);
}
if (expectedHighlightingSet.endOfLine)
builder.endOfLine();
HighlightInfo highlightInfo = builder.createUnconditionally();
expectedHighlightingSet.infos.add(highlightInfo);
}
return toContinueFrom;
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-plugins by JetBrains.
the class DartAnnotator method highlightEscapeSequences.
private static void highlightEscapeSequences(final PsiElement node, final AnnotationHolder holder) {
final List<Pair<TextRange, Boolean>> escapeSequenceRangesAndValidity = getEscapeSequenceRangesAndValidity(node.getText());
for (Pair<TextRange, Boolean> rangeAndValidity : escapeSequenceRangesAndValidity) {
final TextRange range = rangeAndValidity.first.shiftRight(node.getTextRange().getStartOffset());
final TextAttributesKey attribute = rangeAndValidity.second ? DartSyntaxHighlighterColors.VALID_STRING_ESCAPE : DartSyntaxHighlighterColors.INVALID_STRING_ESCAPE;
if (rangeAndValidity.second) {
holder.createInfoAnnotation(range, null).setTextAttributes(attribute);
} else {
holder.createErrorAnnotation(range, DartBundle.message("dart.color.settings.description.invalid.string.escape")).setTextAttributes(attribute);
}
}
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-plugins by JetBrains.
the class MarkdownHighlightingAnnotator method annotate.
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
final IElementType type = element.getNode().getElementType();
if (type == MarkdownTokenTypes.EMPH) {
final PsiElement parent = element.getParent();
if (parent == null) {
return;
}
final IElementType parentType = parent.getNode().getElementType();
if (parentType == MarkdownElementTypes.EMPH || parentType == MarkdownElementTypes.STRONG) {
final Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setTextAttributes(parentType == MarkdownElementTypes.EMPH ? MarkdownHighlighterColors.ITALIC_MARKER_ATTR_KEY : MarkdownHighlighterColors.BOLD_MARKER_ATTR_KEY);
}
return;
}
if (element instanceof LeafPsiElement) {
return;
}
final TextAttributesKey[] tokenHighlights = SYNTAX_HIGHLIGHTER.getTokenHighlights(type);
if (tokenHighlights.length > 0 && !MarkdownHighlighterColors.TEXT_ATTR_KEY.equals(tokenHighlights[0])) {
final Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setTextAttributes(tokenHighlights[0]);
}
}
Aggregations