public void eraseHighlight(List<RangeHighlighter> list) { for (RangeHighlighter l : list) { this.markupModelEx.removeHighlighter(l); } }
public synchronized void removeInvalidMethods(MarkupModelEx markupModel) { List<PsiMethod> invalidMethods = null; for (PsiMethod psiMethod : rangeHighlighters.keySet()) { if (!psiMethod.isValid()) { if (invalidMethods == null) { invalidMethods = new ArrayList<>(); } invalidMethods.add(psiMethod); } } if (invalidMethods != null) { for (PsiMethod invalidMethod : invalidMethods) { try { markupModel.removeHighlighter(rangeHighlighters.get(invalidMethod)); } catch (AssertionError ignored) { /* Method is thrown if range is outdated. * It means line marker was already removed. */ } rangeHighlighters.remove(invalidMethod); } } }
@Override public void fileClosed(@NotNull FileEditorManager fileEditorManager, @NotNull VirtualFile virtualFile) { FileEditor[] editors = fileEditorManager.getEditors(virtualFile); for (FileEditor editor : editors) { EditorEx editorEx = getEditorEx(editor); if (editorEx != null) { Map<Expression, RangeHighlighterEx> m = highlighters.remove(editorEx); if (m != null) { m.forEach((expression, highlighter) -> editorEx.getMarkupModel().removeHighlighter(highlighter) ); } } } }
/** * Before calling this method all PsiMethod instances in {@link #rangeHighlighters} * should be valid. To remove invalid instances call {@link #removeInvalidMethods(MarkupModelEx)} */ public synchronized void removeIconIfPresent(PsiMethod method, MarkupModelEx markupModel) { for (PsiMethod methodWithIcon : rangeHighlighters.keySet()) { /* PsiMethod does not have equals() and hashCode() method * so we check all methods in set by isEquivalentTo() */ try { if (methodWithIcon.isEquivalentTo(method)) { RangeHighlighter highlighter = rangeHighlighters.get(methodWithIcon); markupModel.removeHighlighter(highlighter); rangeHighlighters.remove(methodWithIcon); return; } } catch (AssertionError e) { /* it is thrown from com.intellij.psi.impl.source.tree.AstPath.ChildPath.getNode * when isEquivalentTo() method is called * I do not know why and how to fix it. It is okay to just ignore it */ LOG.warn(e); } } }
RangeHighlighterEx __highlighter = m.remove(expression); if (__highlighter != null) { editorEx.getMarkupModel().removeHighlighter(__highlighter);