use of com.intellij.lang.annotation.HighlightSeverity 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.HighlightSeverity in project intellij-community by JetBrains.
the class HighlightSeveritiesTest method testSeveritiesMigration.
public void testSeveritiesMigration() throws Exception {
final Element element = new Element("temp");
new HighlightSeverity(HighlightSeverity.ERROR.myName, 500).writeExternal(element);
HighlightSeverity newSeverity = new HighlightSeverity(element);
assertEquals(500, newSeverity.myVal);
}
use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.
the class SeverityRegistrar method fromList.
@NotNull
private static OrderMap fromList(@NotNull List<HighlightSeverity> orderList) {
if (orderList.size() != new HashSet<>(orderList).size()) {
LOG.error("Severities order list MUST contain only unique severities: " + orderList);
}
TObjectIntHashMap<HighlightSeverity> map = new TObjectIntHashMap<>();
for (int i = 0; i < orderList.size(); i++) {
HighlightSeverity severity = orderList.get(i);
map.put(severity, i);
}
return new OrderMap(map);
}
use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.
the class SeverityRegistrar method registerSeverity.
public void registerSeverity(@NotNull SeverityBasedTextAttributes info, Color renderColor) {
final HighlightSeverity severity = info.getType().getSeverity(null);
myMap.put(severity.getName(), info);
if (renderColor != null) {
myRendererColors.put(severity.getName(), renderColor);
}
myOrderMap = null;
HighlightDisplayLevel.registerSeverity(severity, getHighlightInfoTypeBySeverity(severity).getAttributesKey(), null);
severitiesChanged();
}
use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.
the class SeverityRegistrar method readExternal.
public void readExternal(@NotNull Element element) {
myMap.clear();
myRendererColors.clear();
for (Element infoElement : element.getChildren(INFO_TAG)) {
SeverityBasedTextAttributes highlightInfo = new SeverityBasedTextAttributes(infoElement);
String colorStr = infoElement.getAttributeValue(COLOR_ATTRIBUTE);
@SuppressWarnings("UseJBColor") Color color = colorStr == null ? null : new Color(Integer.parseInt(colorStr, 16));
registerSeverity(highlightInfo, color);
}
myReadOrder = new JDOMExternalizableStringList();
myReadOrder.readExternal(element);
List<HighlightSeverity> read = new ArrayList<>(myReadOrder.size());
final List<HighlightSeverity> knownSeverities = getDefaultOrder();
for (String name : myReadOrder) {
HighlightSeverity severity = getSeverity(name);
if (severity != null && knownSeverities.contains(severity)) {
read.add(severity);
}
}
myOrderMap = ensureAllStandardIncluded(read, knownSeverities);
severitiesChanged();
}
Aggregations