use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class SingleInspectionProfilePanel method copyUsedSeveritiesIfUndefined.
private static void copyUsedSeveritiesIfUndefined(InspectionProfileImpl selectedProfile, BaseInspectionProfileManager profileManager) {
final SeverityRegistrar registrar = profileManager.getSeverityRegistrar();
final Set<HighlightSeverity> severities = selectedProfile.getUsedSeverities();
for (Iterator<HighlightSeverity> iterator = severities.iterator(); iterator.hasNext(); ) {
HighlightSeverity severity = iterator.next();
if (registrar.isSeverityValid(severity.getName())) {
iterator.remove();
}
}
if (!severities.isEmpty()) {
final SeverityRegistrar oppositeRegister = selectedProfile.getProfileManager().getSeverityRegistrar();
for (HighlightSeverity severity : severities) {
final TextAttributesKey attributesKey = TextAttributesKey.find(severity.getName());
final TextAttributes textAttributes = oppositeRegister.getTextAttributesBySeverity(severity);
if (textAttributes == null) {
continue;
}
HighlightInfoType.HighlightInfoTypeImpl info = new HighlightInfoType.HighlightInfoTypeImpl(severity, attributesKey);
registrar.registerSeverity(new SeverityRegistrar.SeverityBasedTextAttributes(textAttributes.clone(), info), textAttributes.getErrorStripeColor());
}
}
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class NodeRenderer method customizeCellRenderer.
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Color color = null;
NodeDescriptor descriptor = null;
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object userObject = node.getUserObject();
if (userObject instanceof NodeDescriptor) {
descriptor = (NodeDescriptor) userObject;
color = descriptor.getColor();
setIcon(descriptor.getIcon());
}
}
if (descriptor instanceof PresentableNodeDescriptor) {
final PresentableNodeDescriptor node = (PresentableNodeDescriptor) descriptor;
final PresentationData presentation = node.getPresentation();
final List<PresentableNodeDescriptor.ColoredFragment> coloredText = presentation.getColoredText();
if (coloredText.isEmpty()) {
String text = tree.convertValueToText(value.toString(), selected, expanded, leaf, row, hasFocus);
SimpleTextAttributes simpleTextAttributes = getSimpleTextAttributes(node, presentation.getForcedTextForeground() != null ? presentation.getForcedTextForeground() : color);
append(text, simpleTextAttributes);
String location = presentation.getLocationString();
if (!StringUtil.isEmpty(location)) {
SimpleTextAttributes attributes = SimpleTextAttributes.merge(simpleTextAttributes, SimpleTextAttributes.GRAYED_ATTRIBUTES);
append(presentation.getLocationPrefix() + location + presentation.getLocationSuffix(), attributes, false);
}
} else {
boolean first = true;
for (PresentableNodeDescriptor.ColoredFragment each : coloredText) {
SimpleTextAttributes simpleTextAttributes = each.getAttributes();
if (each.getAttributes().getFgColor() == null && presentation.getForcedTextForeground() != null) {
simpleTextAttributes = addColorToSimpleTextAttributes(each.getAttributes(), presentation.getForcedTextForeground() != null ? presentation.getForcedTextForeground() : color);
}
if (first) {
final TextAttributesKey textAttributesKey = presentation.getTextAttributesKey();
if (textAttributesKey != null) {
final TextAttributes forcedAttributes = getColorsScheme().getAttributes(textAttributesKey);
if (forcedAttributes != null) {
simpleTextAttributes = SimpleTextAttributes.merge(simpleTextAttributes, SimpleTextAttributes.fromTextAttributes(forcedAttributes));
}
}
first = false;
}
// treat grayed text as non-main
boolean isMain = simpleTextAttributes != SimpleTextAttributes.GRAYED_ATTRIBUTES;
append(each.getText(), simpleTextAttributes, isMain);
}
String location = presentation.getLocationString();
if (!StringUtil.isEmpty(location)) {
append(presentation.getLocationPrefix() + location + presentation.getLocationSuffix(), SimpleTextAttributes.GRAY_ATTRIBUTES, false);
}
}
setToolTipText(presentation.getTooltip());
} else if (value != null) {
String text = value.toString();
if (descriptor != null) {
text = descriptor.myName;
}
text = tree.convertValueToText(text, selected, expanded, leaf, row, hasFocus);
if (text == null) {
text = "";
}
append(text);
setToolTipText(null);
}
if (!AbstractTreeUi.isLoadingNode(value)) {
SpeedSearchUtil.applySpeedSearchHighlighting(tree, this, true, selected);
}
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class FindManagerImpl method findInCommentsAndLiterals.
@NotNull
private FindResult findInCommentsAndLiterals(@NotNull CharSequence text, char[] textArray, int offset, @NotNull FindModel model, @NotNull final VirtualFile file) {
synchronized (model) {
FileType ftype = file.getFileType();
Language lang = null;
if (ftype instanceof LanguageFileType) {
lang = ((LanguageFileType) ftype).getLanguage();
}
CommentsLiteralsSearchData data = model.getUserData(ourCommentsLiteralsSearchDataKey);
if (data == null || !Comparing.equal(data.lastFile, file) || !data.model.equals(model)) {
SyntaxHighlighter highlighter = getHighlighter(file, lang);
if (highlighter == null) {
// no syntax highlighter -> no search
return NOT_FOUND_RESULT;
}
TokenSet tokensOfInterest = TokenSet.EMPTY;
Set<Language> relevantLanguages;
if (lang != null) {
final Language finalLang = lang;
relevantLanguages = ApplicationManager.getApplication().runReadAction(new Computable<Set<Language>>() {
@Override
public Set<Language> compute() {
THashSet<Language> result = new THashSet<>();
FileViewProvider viewProvider = PsiManager.getInstance(myProject).findViewProvider(file);
if (viewProvider != null) {
result.addAll(viewProvider.getLanguages());
}
if (result.isEmpty()) {
result.add(finalLang);
}
return result;
}
});
for (Language relevantLanguage : relevantLanguages) {
tokensOfInterest = addTokenTypesForLanguage(model, relevantLanguage, tokensOfInterest);
}
if (model.isInStringLiteralsOnly()) {
// TODO: xml does not have string literals defined so we add XmlAttributeValue element type as convenience
final Lexer xmlLexer = getHighlighter(null, Language.findLanguageByID("XML")).getHighlightingLexer();
final String marker = "xxx";
xmlLexer.start("<a href=\"" + marker + "\" />");
while (!marker.equals(xmlLexer.getTokenText())) {
xmlLexer.advance();
if (xmlLexer.getTokenType() == null)
break;
}
IElementType convenienceXmlAttrType = xmlLexer.getTokenType();
if (convenienceXmlAttrType != null) {
tokensOfInterest = TokenSet.orSet(tokensOfInterest, TokenSet.create(convenienceXmlAttrType));
}
}
} else {
relevantLanguages = ContainerUtil.newHashSet();
if (ftype instanceof AbstractFileType) {
if (model.isInCommentsOnly()) {
tokensOfInterest = TokenSet.create(CustomHighlighterTokenType.LINE_COMMENT, CustomHighlighterTokenType.MULTI_LINE_COMMENT);
}
if (model.isInStringLiteralsOnly()) {
tokensOfInterest = TokenSet.orSet(tokensOfInterest, TokenSet.create(CustomHighlighterTokenType.STRING, CustomHighlighterTokenType.SINGLE_QUOTED_STRING));
}
}
}
Matcher matcher = model.isRegularExpressions() ? compileRegExp(model, "") : null;
StringSearcher searcher = matcher != null ? null : new StringSearcher(model.getStringToFind(), model.isCaseSensitive(), true);
SyntaxHighlighterOverEditorHighlighter highlighterAdapter = new SyntaxHighlighterOverEditorHighlighter(highlighter, file, myProject);
data = new CommentsLiteralsSearchData(file, relevantLanguages, highlighterAdapter, tokensOfInterest, searcher, matcher, model.clone());
data.highlighter.restart(text);
model.putUserData(ourCommentsLiteralsSearchDataKey, data);
}
int initialStartOffset = model.isForward() && data.startOffset < offset ? data.startOffset : 0;
data.highlighter.resetPosition(initialStartOffset);
final Lexer lexer = data.highlighter.getHighlightingLexer();
IElementType tokenType;
TokenSet tokens = data.tokensOfInterest;
int lastGoodOffset = 0;
boolean scanningForward = model.isForward();
FindResultImpl prevFindResult = NOT_FOUND_RESULT;
while ((tokenType = lexer.getTokenType()) != null) {
if (lexer.getState() == 0)
lastGoodOffset = lexer.getTokenStart();
final TextAttributesKey[] keys = data.highlighter.getTokenHighlights(tokenType);
if (tokens.contains(tokenType) || (model.isInStringLiteralsOnly() && ChunkExtractor.isHighlightedAsString(keys)) || (model.isInCommentsOnly() && ChunkExtractor.isHighlightedAsComment(keys))) {
int start = lexer.getTokenStart();
int end = lexer.getTokenEnd();
if (model.isInStringLiteralsOnly()) {
// skip literal quotes itself from matching
char c = text.charAt(start);
if (c == '"' || c == '\'') {
while (start < end && c == text.charAt(start)) {
++start;
if (c == text.charAt(end - 1) && start < end)
--end;
}
}
}
while (true) {
FindResultImpl findResult = null;
if (data.searcher != null) {
int matchStart = data.searcher.scan(text, textArray, start, end);
if (matchStart != -1 && matchStart >= start) {
final int matchEnd = matchStart + model.getStringToFind().length();
if (matchStart >= offset || !scanningForward)
findResult = new FindResultImpl(matchStart, matchEnd);
else {
start = matchEnd;
continue;
}
}
} else if (start <= end) {
data.matcher.reset(StringPattern.newBombedCharSequence(text.subSequence(start, end)));
if (data.matcher.find()) {
final int matchEnd = start + data.matcher.end();
int matchStart = start + data.matcher.start();
if (matchStart >= offset || !scanningForward) {
findResult = new FindResultImpl(matchStart, matchEnd);
} else {
int diff = 0;
if (start == end) {
diff = scanningForward ? 1 : -1;
}
start = matchEnd + diff;
continue;
}
}
}
if (findResult != null) {
if (scanningForward) {
data.startOffset = lastGoodOffset;
return findResult;
} else {
if (findResult.getEndOffset() >= offset)
return prevFindResult;
prevFindResult = findResult;
start = findResult.getEndOffset();
continue;
}
}
break;
}
} else {
Language tokenLang = tokenType.getLanguage();
if (tokenLang != lang && tokenLang != Language.ANY && !data.relevantLanguages.contains(tokenLang)) {
tokens = addTokenTypesForLanguage(model, tokenLang, tokens);
data.tokensOfInterest = tokens;
data.relevantLanguages.add(tokenLang);
}
}
lexer.advance();
}
return prevFindResult;
}
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class ColorSettingsUtil method keyToDisplayTextMap.
public static Map<TextAttributesKey, String> keyToDisplayTextMap(final ColorSettingsPage page) {
final List<AttributesDescriptor> attributeDescriptors = getAllAttributeDescriptors(page);
final Map<TextAttributesKey, String> displayText = new HashMap<>();
for (AttributesDescriptor attributeDescriptor : attributeDescriptors) {
final TextAttributesKey key = attributeDescriptor.getKey();
displayText.put(key, attributeDescriptor.getDisplayName());
}
return displayText;
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class ColorSettingsUtil method addInspectionSeverityAttributes.
private static void addInspectionSeverityAttributes(List<AttributesDescriptor> descriptors) {
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unknown.symbol"), CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.deprecated.symbol"), CodeInsightColors.DEPRECATED_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unused.symbol"), CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.error"), CodeInsightColors.ERRORS_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.warning"), CodeInsightColors.WARNINGS_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.weak.warning"), CodeInsightColors.WEAK_WARNING_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.problems"), CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.duplicate"), CodeInsightColors.DUPLICATE_FROM_SERVER));
for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
for (HighlightInfoType highlightInfoType : provider.getSeveritiesHighlightInfoTypes()) {
final TextAttributesKey attributesKey = highlightInfoType.getAttributesKey();
descriptors.add(new AttributesDescriptor(toDisplayName(attributesKey), attributesKey));
}
}
}
Aggregations