Search in sources :

Example 1 with HighlightSeverity

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();
    }
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TextRange(com.intellij.openapi.util.TextRange) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) NotNull(org.jetbrains.annotations.NotNull) Annotation(com.intellij.lang.annotation.Annotation) IElementType(com.intellij.psi.tree.IElementType) Project(com.intellij.openapi.project.Project) Lexer(com.intellij.lexer.Lexer) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 2 with HighlightSeverity

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);
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Element(org.jdom.Element)

Example 3 with HighlightSeverity

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);
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with HighlightSeverity

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();
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity)

Example 5 with HighlightSeverity

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();
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) JDOMExternalizableStringList(com.intellij.openapi.util.JDOMExternalizableStringList) Element(org.jdom.Element)

Aggregations

HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)33 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)8 Element (org.jdom.Element)8 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)6 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)6 NotNull (org.jetbrains.annotations.NotNull)6 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)5 SeverityRegistrar (com.intellij.codeInsight.daemon.impl.SeverityRegistrar)5 Annotation (com.intellij.lang.annotation.Annotation)5 TextRange (com.intellij.openapi.util.TextRange)4 Nullable (org.jetbrains.annotations.Nullable)4 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)2 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)2 Lexer (com.intellij.lexer.Lexer)2 Document (com.intellij.openapi.editor.Document)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 Project (com.intellij.openapi.project.Project)2 JDOMExternalizableStringList (com.intellij.openapi.util.JDOMExternalizableStringList)2 PsiElement (com.intellij.psi.PsiElement)2 IElementType (com.intellij.psi.tree.IElementType)2