Search in sources :

Example 11 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class XmlTagTreeHighlightingPass method getHighlights.

public List<HighlightInfo> getHighlights() {
    clearLineMarkers(myEditor);
    final int count = myPairsToHighlight.size();
    final List<HighlightInfo> highlightInfos = new ArrayList<>(count * 2);
    final MarkupModel markupModel = myEditor.getMarkupModel();
    final Color[] baseColors = XmlTagTreeHighlightingUtil.getBaseColors();
    final Color[] colorsForEditor = count > 1 ? toColorsForEditor(baseColors) : new Color[] { myEditor.getColorsScheme().getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES).getBackgroundColor() };
    final Color[] colorsForLineMarkers = toColorsForLineMarkers(baseColors);
    final List<RangeHighlighter> newHighlighters = new ArrayList<>();
    assert colorsForEditor.length > 0;
    for (int i = 0; i < count && i < baseColors.length; i++) {
        Pair<TextRange, TextRange> pair = myPairsToHighlight.get(i);
        if (pair.first == null && pair.second == null) {
            continue;
        }
        Color color = colorsForEditor[i];
        if (color == null) {
            continue;
        }
        if (pair.first != null && !pair.first.isEmpty()) {
            highlightInfos.add(createHighlightInfo(color, pair.first));
        }
        if (pair.second != null && !pair.second.isEmpty()) {
            highlightInfos.add(createHighlightInfo(color, pair.second));
        }
        final int start = pair.first != null ? pair.first.getStartOffset() : pair.second.getStartOffset();
        final int end = pair.second != null ? pair.second.getEndOffset() : pair.first.getEndOffset();
        final Color lineMarkerColor = colorsForLineMarkers[i];
        if (count > 1 && lineMarkerColor != null && start != end) {
            final RangeHighlighter highlighter = createHighlighter(markupModel, new TextRange(start, end), lineMarkerColor);
            newHighlighters.add(highlighter);
        }
    }
    myEditor.putUserData(TAG_TREE_HIGHLIGHTERS_IN_EDITOR_KEY, newHighlighters);
    return highlightInfos;
}
Also used : ArrayList(java.util.ArrayList) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) TextRange(com.intellij.openapi.util.TextRange) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel)

Example 12 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class XmlTagTreeHighlightingPass method clearHighlightingAndLineMarkers.

public static void clearHighlightingAndLineMarkers(final Editor editor, @NotNull Project project) {
    final MarkupModel markupModel = DocumentMarkupModel.forDocument(editor.getDocument(), project, true);
    for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) {
        Object tooltip = highlighter.getErrorStripeTooltip();
        if (!(tooltip instanceof HighlightInfo)) {
            continue;
        }
        if (((HighlightInfo) tooltip).type == TYPE) {
            highlighter.dispose();
        }
    }
    clearLineMarkers(editor);
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel)

Example 13 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class JavaFxFieldToPropertyTest method getIntentionAction.

protected IntentionAction getIntentionAction() throws Exception {
    final List<HighlightInfo> infos = doHighlighting();
    final Editor editor = getEditor();
    final PsiFile file = getFile();
    return findIntentionAction(infos, actionName, editor, file);
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 14 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class JavaFXCollapseSubtagToAttributeTest method doTest.

private void doTest(boolean available, final String tagName) throws Exception {
    configureByFiles(null, getTestName(true) + ".fxml");
    final List<HighlightInfo> infos = doHighlighting();
    Editor editor = getEditor();
    PsiFile file = getFile();
    IntentionAction intentionAction = findIntentionAction(infos, "Collapse tag '" + tagName + "' to attribute", editor, file);
    if (available) {
        assertNotNull("Collapse tag '" + tagName + "' to attribute", intentionAction);
        assertTrue(CodeInsightTestFixtureImpl.invokeIntention(intentionAction, file, editor, "Collapse tag '" + tagName + "' to attribute"));
        checkResultByFile(getTestName(true) + "_after.fxml");
    } else {
        assertNull(intentionAction);
    }
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 15 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class JavaFXExpandAttributeTest method doTest.

private void doTest(boolean available, final String attrName) throws Exception {
    configureByFiles(null, getTestName(true) + ".fxml");
    final List<HighlightInfo> infos = doHighlighting();
    Editor editor = getEditor();
    PsiFile file = getFile();
    final String actionName = "Expand '" + attrName + "' to tag";
    IntentionAction intentionAction = findIntentionAction(infos, actionName, editor, file);
    if (available) {
        assertNotNull(actionName, intentionAction);
        assertTrue(CodeInsightTestFixtureImpl.invokeIntention(intentionAction, file, editor, actionName));
        checkResultByFile(getTestName(true) + "_after.fxml");
    } else {
        assertNull(intentionAction);
    }
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Aggregations

HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)221 Nullable (org.jetbrains.annotations.Nullable)51 TextRange (com.intellij.openapi.util.TextRange)33 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)30 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 NotNull (org.jetbrains.annotations.NotNull)17 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)16 Document (com.intellij.openapi.editor.Document)12 ArrayList (java.util.ArrayList)11 PsiElement (com.intellij.psi.PsiElement)10 File (java.io.File)8 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)7 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)6 Pair (com.intellij.openapi.util.Pair)6 PsiFile (com.intellij.psi.PsiFile)6 Editor (com.intellij.openapi.editor.Editor)5 NonNls (org.jetbrains.annotations.NonNls)5 StringUtil (com.intellij.openapi.util.text.StringUtil)4 IElementType (com.intellij.psi.tree.IElementType)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4