Java 类com.intellij.openapi.editor.markup.MarkupModel 实例源码

项目:samebug-idea-plugin    文件:ConsoleWatcher.java   
private RangeHighlighter addMarkerAtOffset(int offset, SearchMark mark) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    final Document document = editor.getDocument();

    if (0 <= offset && offset < document.getTextLength()) {
        editor.getSettings().setLineMarkerAreaShown(true);
        final int line = document.getLineNumber(offset);
        final MarkupModel markupModel = editor.getMarkupModel();

        RangeHighlighter highlighter;
        highlighter = markupModel.addLineHighlighter(line, HighlighterLayer.ADDITIONAL_SYNTAX, null);
        highlighter.setGutterIconRenderer(mark);
        return highlighter;
    } else {
        return null;
    }
}
项目:intellij-ce-playground    文件:UnifiedEditorRangeHighlighter.java   
public void apply(@Nullable Project project, @NotNull Document document) {
  MarkupModel model = DocumentMarkupModel.forDocument(document, project, true);

  for (Element piece : myPieces) {
    RangeHighlighterEx delegate = piece.getDelegate();
    if (!delegate.isValid()) continue;

    RangeHighlighter highlighter = model
      .addRangeHighlighter(piece.getStart(), piece.getEnd(), delegate.getLayer(), delegate.getTextAttributes(), delegate.getTargetArea());
    highlighter.setEditorFilter(delegate.getEditorFilter());
    highlighter.setCustomRenderer(delegate.getCustomRenderer());
    highlighter.setErrorStripeMarkColor(delegate.getErrorStripeMarkColor());
    highlighter.setErrorStripeTooltip(delegate.getErrorStripeTooltip());
    highlighter.setGutterIconRenderer(delegate.getGutterIconRenderer());
    highlighter.setLineMarkerRenderer(delegate.getLineMarkerRenderer());
    highlighter.setLineSeparatorColor(delegate.getLineSeparatorColor());
    highlighter.setThinErrorStripeMark(delegate.isThinErrorStripeMark());
    highlighter.setLineSeparatorPlacement(delegate.getLineSeparatorPlacement());
    highlighter.setLineSeparatorRenderer(delegate.getLineSeparatorRenderer());
  }
}
项目:intellij-ce-playground    文件:DocumentMarkupModelTest.java   
public void testInfoTestAttributes() throws Exception {
  LanguageExtensionPoint<Annotator> extension = new LanguageExtensionPoint<Annotator>();
  extension.language="TEXT";
  extension.implementationClass = TestAnnotator.class.getName();
  PlatformTestUtil.registerExtension(ExtensionPointName.create(LanguageAnnotators.EP_NAME), extension, getTestRootDisposable());
  myFixture.configureByText(PlainTextFileType.INSTANCE, "foo");
  EditorColorsScheme scheme = new EditorColorsSchemeImpl(new DefaultColorsScheme()){{initFonts();}};
  scheme.setAttributes(HighlighterColors.TEXT, new TextAttributes(Color.black, Color.white, null, null, Font.PLAIN));
  ((EditorEx)myFixture.getEditor()).setColorsScheme(scheme);
  myFixture.doHighlighting();
  MarkupModel model = DocumentMarkupModel.forDocument(myFixture.getEditor().getDocument(), getProject(), false);
  RangeHighlighter[] highlighters = model.getAllHighlighters();
  assertEquals(1, highlighters.length);
  TextAttributes attributes = highlighters[0].getTextAttributes();
  assertNotNull(attributes);
  assertNull(attributes.getBackgroundColor());
  assertNull(attributes.getForegroundColor());
}
项目:jetbrains-plugin-st4    文件:SyntaxHighlighter.java   
protected void syntaxError(String annotation, Token offendingToken) {
//      Annotation annot = new Annotation(20, 30, HighlightSeverity.ERROR, "Test!", "Test Message!");
//      HighlightInfo info = HighlightInfo.fromAnnotation(annot);
//      List<HighlightInfo> al = new ArrayList<HighlightInfo>();
//      al.add(info);
//      UpdateHighlightersUtil.setHighlightersToEditor(project, doc, 20, 30, al, null, 0)

        final TextAttributes attr = new TextAttributes();
        attr.setForegroundColor(JBColor.RED);
        attr.setEffectColor(JBColor.RED);
        attr.setEffectType(EffectType.WAVE_UNDERSCORE);
        MarkupModel markupModel = editor.getMarkupModel();
        RangeHighlighter h =
            markupModel.addRangeHighlighter(startIndex+offendingToken.getStartIndex(),
                                            startIndex+offendingToken.getStopIndex()+1,
                                            HighlighterLayer.ERROR, // layer
                                            attr,
                                            HighlighterTargetArea.EXACT_RANGE);
        h.putUserData(SYNTAX_HIGHLIGHTING_TAG, offendingToken); // store any non-null value to tag it
    }
项目:intellij-plugin-v4    文件:ProfilerPanel.java   
public Token addDecisionEventHighlighter(PreviewState previewState, MarkupModel markupModel,
                                         DecisionEventInfo info, Color errorStripeColor,
                                         EffectType effectType) {
    TokenStream tokens = previewState.parsingResult.parser.getInputStream();
    Token startToken = tokens.get(info.startIndex);
    Token stopToken = tokens.get(info.stopIndex);
    TextAttributes textAttributes =
        new TextAttributes(JBColor.BLACK, JBColor.WHITE, errorStripeColor,
                           effectType, Font.PLAIN);
    textAttributes.setErrorStripeColor(errorStripeColor);
    final RangeHighlighter rangeHighlighter =
        markupModel.addRangeHighlighter(
            startToken.getStartIndex(), stopToken.getStopIndex()+1,
            HighlighterLayer.ADDITIONAL_SYNTAX, textAttributes,
            HighlighterTargetArea.EXACT_RANGE);
    rangeHighlighter.putUserData(DECISION_EVENT_INFO_KEY, info);
    rangeHighlighter.setErrorStripeMarkColor(errorStripeColor);
    return startToken;
}
项目:intellij-plugin-v4    文件:InputPanel.java   
public void highlightAndOfferHint(Editor editor, int offset,
                                  Interval sourceInterval,
                                  JBColor color,
                                  EffectType effectType, String hintText) {
    CaretModel caretModel = editor.getCaretModel();
    final TextAttributes attr = new TextAttributes();
    attr.setForegroundColor(color);
    attr.setEffectColor(color);
    attr.setEffectType(effectType);
    MarkupModel markupModel = editor.getMarkupModel();
    markupModel.addRangeHighlighter(
        sourceInterval.a,
        sourceInterval.b,
        InputPanel.TOKEN_INFO_LAYER, // layer
        attr,
        HighlighterTargetArea.EXACT_RANGE
                                   );

    if ( hintText.contains("<") ) {
        hintText = hintText.replaceAll("<", "&lt;");
    }

    // HINT
    caretModel.moveToOffset(offset); // info tooltip only shows at cursor :(
    HintManager.getInstance().showInformationHint(editor, hintText);
}
项目:consulo    文件:UnifiedEditorRangeHighlighter.java   
public void apply(@Nullable Project project, @Nonnull Document document) {
  MarkupModel model = DocumentMarkupModel.forDocument(document, project, true);

  for (Element piece : myPieces) {
    RangeHighlighterEx delegate = piece.getDelegate();
    if (!delegate.isValid()) continue;

    RangeHighlighter highlighter = model
            .addRangeHighlighter(piece.getStart(), piece.getEnd(), delegate.getLayer(), delegate.getTextAttributes(), delegate.getTargetArea());
    highlighter.setEditorFilter(delegate.getEditorFilter());
    highlighter.setCustomRenderer(delegate.getCustomRenderer());
    highlighter.setErrorStripeMarkColor(delegate.getErrorStripeMarkColor());
    highlighter.setErrorStripeTooltip(delegate.getErrorStripeTooltip());
    highlighter.setGutterIconRenderer(delegate.getGutterIconRenderer());
    highlighter.setLineMarkerRenderer(delegate.getLineMarkerRenderer());
    highlighter.setLineSeparatorColor(delegate.getLineSeparatorColor());
    highlighter.setThinErrorStripeMark(delegate.isThinErrorStripeMark());
    highlighter.setLineSeparatorPlacement(delegate.getLineSeparatorPlacement());
    highlighter.setLineSeparatorRenderer(delegate.getLineSeparatorRenderer());
  }
}
项目:consulo    文件:NavigationUtil.java   
/**
 * Patches attributes to be visible under debugger active line
 */
@SuppressWarnings("UseJBColor")
public static TextAttributes patchAttributesColor(TextAttributes attributes, @Nonnull TextRange range, @Nonnull Editor editor) {
  if (attributes.getForegroundColor() == null && attributes.getEffectColor() == null) return attributes;
  MarkupModel model = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);
  if (model != null) {
    if (!((MarkupModelEx)model).processRangeHighlightersOverlappingWith(range.getStartOffset(), range.getEndOffset(), highlighter -> {
      if (highlighter.isValid() && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
        TextAttributes textAttributes = highlighter.getTextAttributes();
        if (textAttributes != null) {
          Color color = textAttributes.getBackgroundColor();
          return !(color != null && color.getBlue() > 128 && color.getRed() < 128 && color.getGreen() < 128);
        }
      }
      return true;
    })) {
      TextAttributes clone = attributes.clone();
      clone.setForegroundColor(Color.orange);
      clone.setEffectColor(Color.orange);
      return clone;
    }
  }
  return attributes;
}
项目:consulo-xml    文件:XmlTagTreeHighlightingPass.java   
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);
}
项目:educational-plugin    文件:CCTestCase.java   
@Nullable
public static RangeHighlighter getHighlighter(MarkupModel model, AnswerPlaceholder placeholder) {
  for (RangeHighlighter highlighter : model.getAllHighlighters()) {
    int endOffset = placeholder.getOffset() + placeholder.getRealLength();
    if (highlighter.getStartOffset() == placeholder.getOffset() && highlighter.getEndOffset() == endOffset) {
      return highlighter;
    }
  }
  return null;
}
项目:educational-plugin    文件:CCTestCase.java   
protected static void checkHighlighters(TaskFile taskFile, MarkupModel markupModel) {
  for (AnswerPlaceholder answerPlaceholder : taskFile.getActivePlaceholders()) {
    if (getHighlighter(markupModel, answerPlaceholder) == null) {
      throw new AssertionError("No highlighter for placeholder: " + CCTestsUtil.getPlaceholderPresentation(answerPlaceholder));
    }
  }
}
项目:intellij-ce-playground    文件:PersistentRangeHighlighterImpl.java   
static PersistentRangeHighlighterImpl create(@NotNull MarkupModel model,
                                             int offset,
                                             int layer,
                                             @NotNull HighlighterTargetArea target,
                                             @Nullable TextAttributes textAttributes,
                                             boolean normalizeStartOffset) {
  int line = model.getDocument().getLineNumber(offset);
  int startOffset = normalizeStartOffset ? model.getDocument().getLineStartOffset(line) : offset;
  return new PersistentRangeHighlighterImpl(model, startOffset, line, layer, target, textAttributes);
}
项目:intellij-ce-playground    文件:PersistentRangeHighlighterImpl.java   
private PersistentRangeHighlighterImpl(@NotNull MarkupModel model,
                                       int startOffset,
                                       int line,
                                       int layer,
                                       @NotNull HighlighterTargetArea target,
                                       @Nullable TextAttributes textAttributes) {
  super(model, startOffset, model.getDocument().getLineEndOffset(line), layer, target, textAttributes, false, false);

  myLine = line;
}
项目:intellij-ce-playground    文件:RangeMarkerTest.java   
public void testRangeHighlightersRecreateBug() throws Exception {
  Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]");

  MarkupModel markupModel = DocumentMarkupModel.forDocument(document, ourProject, true);
  for (int i=0; i<2; i++) {
    RangeMarker m = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
    RangeMarker m2 = markupModel.addRangeHighlighter(2, 7, 0, null, HighlighterTargetArea.EXACT_RANGE);
    RangeMarker m3 = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
    markupModel.removeAllHighlighters();
  }
}
项目:intellij-ce-playground    文件:RangeMarkerTest.java   
public void testRangeHighlighterDisposeVsRemoveAllConflict() throws Exception {
  Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]");

  MarkupModel markupModel = DocumentMarkupModel.forDocument(document, ourProject, true);
  RangeMarker m = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
  assertTrue(m.isValid());
  markupModel.removeAllHighlighters();
  assertFalse(m.isValid());
  assertEmpty(markupModel.getAllHighlighters());
  m.dispose();
  assertFalse(m.isValid());
}
项目:intellij-ce-playground    文件:BreakpointItem.java   
protected static void showInEditor(DetailView panel, VirtualFile virtualFile, int line) {
  TextAttributes attributes =
    EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES);

  DetailView.PreviewEditorState state = DetailView.PreviewEditorState.create(virtualFile, line, attributes);

  if (state.equals(panel.getEditorState())) {
    return;
  }

  panel.navigateInPreviewEditor(state);

  TextAttributes softerAttributes = attributes.clone();
  Color backgroundColor = softerAttributes.getBackgroundColor();
  if (backgroundColor != null) {
    softerAttributes.setBackgroundColor(ColorUtil.softer(backgroundColor));
  }

  final Editor editor = panel.getEditor();
  if (editor != null) {
    final MarkupModel editorModel = editor.getMarkupModel();
    final MarkupModel documentModel =
      DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);

    for (RangeHighlighter highlighter : documentModel.getAllHighlighters()) {
      if (highlighter.getUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY) == Boolean.TRUE) {
        final int line1 = editor.offsetToLogicalPosition(highlighter.getStartOffset()).line;
        if (line1 != line) {
          editorModel.addLineHighlighter(line1,
                                         DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes);
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:NavigationUtil.java   
/**
 * Patches attributes to be visible under debugger active line
 */
@SuppressWarnings("UseJBColor")
public static TextAttributes patchAttributesColor(TextAttributes attributes, @NotNull TextRange range, @NotNull Editor editor) {
  MarkupModel model = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);
  if (model != null) {
    if (!((MarkupModelEx)model).processRangeHighlightersOverlappingWith(range.getStartOffset(), range.getEndOffset(),
         new Processor<RangeHighlighterEx>() {
           @Override
           public boolean process(RangeHighlighterEx highlighter) {
             if (highlighter.isValid() && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
               TextAttributes textAttributes = highlighter.getTextAttributes();
               if (textAttributes != null) {
                 Color color = textAttributes.getBackgroundColor();
                 return !(color != null && color.getBlue() > 128 && color.getRed() < 128 && color.getGreen() < 128);
               }
             }
             return true;
           }
         })) {
      TextAttributes clone = attributes.clone();
      clone.setForegroundColor(Color.orange);
      clone.setEffectColor(Color.orange);
      return clone;
    }
  }
  return attributes;
}
项目:intellij-ce-playground    文件:IndentsPass.java   
@NotNull
private static RangeHighlighter createHighlighter(MarkupModel mm, TextRange range) {
  final RangeHighlighter highlighter =
    mm.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.EXACT_RANGE);
  highlighter.setCustomRenderer(RENDERER);
  return highlighter;
}
项目:intellij-ce-playground    文件:IdentifierHighlighterPass.java   
public static void clearMyHighlights(Document document, Project project) {
  MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true);
  for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) {
    Object tooltip = highlighter.getErrorStripeTooltip();
    if (!(tooltip instanceof HighlightInfo)) {
      continue;
    }
    HighlightInfo info = (HighlightInfo)tooltip;
    if (info.type == HighlightInfoType.ELEMENT_UNDER_CARET_READ || info.type == HighlightInfoType.ELEMENT_UNDER_CARET_WRITE) {
      highlighter.dispose();
    }
  }
}
项目:intellij-ce-playground    文件:DefaultHighlightInfoProcessor.java   
@Override
public void highlightsInsideVisiblePartAreProduced(@NotNull final HighlightingSession session,
                                                   @NotNull final List<HighlightInfo> infos,
                                                   @NotNull TextRange priorityRange,
                                                   @NotNull TextRange restrictRange,
                                                   final int groupId) {
  final PsiFile psiFile = session.getPsiFile();
  final Project project = psiFile.getProject();
  final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
  if (document == null) return;
  final long modificationStamp = document.getModificationStamp();
  final TextRange priorityIntersection = priorityRange.intersection(restrictRange);

  final Editor editor = session.getEditor();
  UIUtil.invokeLaterIfNeeded(new Runnable() {
    @Override
    public void run() {
      if (project.isDisposed() || modificationStamp != document.getModificationStamp()) return;
      if (priorityIntersection != null) {
        MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true);

        EditorColorsScheme scheme = session.getColorsScheme();
        UpdateHighlightersUtil.setHighlightersInRange(project, document, priorityIntersection, scheme, infos,
                                                      (MarkupModelEx)markupModel, groupId);
      }
      if (editor != null && !editor.isDisposed()) {
        // usability: show auto import popup as soon as possible
        new ShowAutoImportPass(project, psiFile, editor).applyInformationToEditor();

        DaemonListeners.repaintErrorStripeRenderer(editor, project);
      }
    }
  });
}
项目:review-board-idea-plugin    文件:CommentsDiffTool.java   
private void updateHighLights(Editor editor) {
    MarkupModel markup = editor.getMarkupModel();

    for (RangeHighlighter customRangeHighlighter : newCommentHighlighters) {
        markup.removeHighlighter(customRangeHighlighter);
    }
    newCommentHighlighters.clear();

    int lineCount = markup.getDocument().getLineCount();

    Map<Integer, List<Comment>> lineComments = lineComments(comments);
    for (Map.Entry<Integer, List<Comment>> entry : lineComments.entrySet()) {
        if (entry.getKey() > lineCount) continue;

        boolean hasNewComments = false;
        for (Comment comment : entry.getValue()) {
            if (comment.id == null) {
                hasNewComments = true;
                break;
            }
        }

        TextAttributes attributes = new TextAttributes();
        if (hasNewComments) attributes.setBackgroundColor(JBColor.PINK);
        else attributes.setBackgroundColor(JBColor.YELLOW);

        RangeHighlighter rangeHighlighter = markup
                .addLineHighlighter(entry.getKey() - 1, HighlighterLayer.SELECTION + (hasNewComments ? 2 : 1), attributes);
        rangeHighlighter.setGutterIconRenderer(new CommentGutterIconRenderer());
        newCommentHighlighters.add(rangeHighlighter);
    }
}
项目:jetbrains-plugin-st4    文件:SyntaxHighlighter.java   
protected void highlightToken(Token t, TextAttributesKey[] keys) {
    MarkupModel markupModel = getEditor().getMarkupModel();
    EditorColorsScheme scheme = editorColorsManager.getGlobalScheme();
    TextAttributes attr = merge(scheme, keys);
    RangeHighlighter h =
        markupModel.addRangeHighlighter(
            startIndex+t.getStartIndex(),
            startIndex+t.getStopIndex()+1,
            HighlighterLayer.SYNTAX, // layer
            attr,
            HighlighterTargetArea.EXACT_RANGE);
    h.putUserData(SYNTAX_HIGHLIGHTING_TAG, t); // store any non-null value to tag it
}
项目:tools-idea    文件:PersistentRangeHighlighterImpl.java   
PersistentRangeHighlighterImpl(@NotNull MarkupModel model,
                               int offset,
                               int layer,
                               @NotNull HighlighterTargetArea target,
                               TextAttributes textAttributes) {
  super(model, model.getDocument().getLineStartOffset(model.getDocument().getLineNumber(offset)), model.getDocument().getLineEndOffset(model.getDocument().getLineNumber(offset)),layer, target, textAttributes,
        false, false);
  setLine(model.getDocument().getLineNumber(offset));
}
项目:tools-idea    文件:RangeMarkerTest.java   
public void testRangeHighlightersRecreateBug() throws Exception {
  Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]");

  MarkupModel markupModel = DocumentMarkupModel.forDocument(document, ourProject, true);
  for (int i=0; i<2; i++) {
    RangeMarker m = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
    RangeMarker m2 = markupModel.addRangeHighlighter(2, 7, 0, null, HighlighterTargetArea.EXACT_RANGE);
    RangeMarker m3 = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
    markupModel.removeAllHighlighters();
  }
}
项目:tools-idea    文件:BreakpointItem.java   
protected static void showInEditor(DetailView panel, VirtualFile virtualFile, int line) {
  TextAttributes attributes =
    EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES);

  DetailView.PreviewEditorState state = DetailView.PreviewEditorState.create(virtualFile, line, attributes);

  if (state.equals(panel.getEditorState())) {
    return;
  }

  panel.navigateInPreviewEditor(state);

  TextAttributes softerAttributes = attributes.clone();
  Color backgroundColor = softerAttributes.getBackgroundColor();
  if (backgroundColor != null) {
    softerAttributes.setBackgroundColor(ColorUtil.softer(backgroundColor));
  }

  final Editor editor = panel.getEditor();
  final MarkupModel editorModel = editor.getMarkupModel();
  final MarkupModel documentModel =
    DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);

  for (RangeHighlighter highlighter : documentModel.getAllHighlighters()) {
    if (highlighter.getUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY) == Boolean.TRUE) {
      final int line1 = editor.offsetToLogicalPosition(highlighter.getStartOffset()).line;
      if (line1 != line) {
        editorModel.addLineHighlighter(line1,
                                       DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes);
      }
    }
  }
}
项目:tools-idea    文件:IndentsPass.java   
@NotNull
private static RangeHighlighter createHighlighter(MarkupModel mm, TextRange range) {
  final RangeHighlighter highlighter =
    mm.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.EXACT_RANGE);
  highlighter.setCustomRenderer(RENDERER);
  return highlighter;
}
项目:tools-idea    文件:IdentifierHighlighterPass.java   
public static void clearMyHighlights(Document document, Project project) {
  MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true);
  for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) {
    Object tooltip = highlighter.getErrorStripeTooltip();
    if (!(tooltip instanceof HighlightInfo)) {
      continue;
    }
    HighlightInfo info = (HighlightInfo)tooltip;
    if (info.type == ourReadHighlightInfoType || info.type == ourWriteHighlightInfoType) {
      highlighter.dispose();
    }
  }
}
项目:tools-idea    文件:GeneralHighlightingPass.java   
public GeneralHighlightingPass(@NotNull Project project,
                               @NotNull PsiFile file,
                               @NotNull Document document,
                               int startOffset,
                               int endOffset,
                               boolean updateAll,
                               @NotNull ProperTextRange priorityRange,
                               @Nullable Editor editor) {
  super(project, document, PRESENTABLE_NAME, file, true);
  myStartOffset = startOffset;
  myEndOffset = endOffset;
  myUpdateAll = updateAll;
  myPriorityRange = priorityRange;
  myEditor = editor;

  LOG.assertTrue(file.isValid());
  setId(Pass.UPDATE_ALL);
  myHasErrorElement = !isWholeFileHighlighting() && Boolean.TRUE.equals(myFile.getUserData(HAS_ERROR_ELEMENT));
  FileStatusMap fileStatusMap = ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject)).getFileStatusMap();
  myErrorFound = !isWholeFileHighlighting() && fileStatusMap.wasErrorFound(myDocument);

  myApplyCommand = new Runnable() {
    @Override
    public void run() {
      ProperTextRange range = new ProperTextRange(myStartOffset, myEndOffset);
      MarkupModel model = DocumentMarkupModel.forDocument(myDocument, myProject, true);
      UpdateHighlightersUtil.cleanFileLevelHighlights(myProject, Pass.UPDATE_ALL,myFile);
      final EditorColorsScheme colorsScheme = getColorsScheme();
      UpdateHighlightersUtil.setHighlightersInRange(myProject, myDocument, range, colorsScheme, myHighlights, (MarkupModelEx)model, Pass.UPDATE_ALL);
    }
  };

  // initial guess to show correct progress in the traffic light icon
  setProgressLimit(document.getTextLength()/2); // approx number of PSI elements = file length/2
  myGlobalScheme = EditorColorsManager.getInstance().getGlobalScheme();
}
项目:intellij-plugin-v4    文件:MyActionUtils.java   
@NotNull
    public static List<RangeHighlighter> getRangeHighlightersAtOffset(Editor editor, int offset) {
        MarkupModel markupModel = editor.getMarkupModel();
        // collect all highlighters and combine to make a single tool tip
        List<RangeHighlighter> highlightersAtOffset = new ArrayList<RangeHighlighter>();
        for (RangeHighlighter r : markupModel.getAllHighlighters()) {
            int a = r.getStartOffset();
            int b = r.getEndOffset();
//          System.out.printf("#%d: %d..%d %s\n", i, a, b, r.toString());
            if (offset >= a && offset < b) { // cursor is over some kind of highlighting
                highlightersAtOffset.add(r);
            }
        }
        return highlightersAtOffset;
    }
项目:intellij-plugin-v4    文件:InputPanel.java   
/**
 * Clear all input highlighters
 */
public void clearInputEditorHighlighters() {
    Editor editor = getInputEditor();
    if ( editor==null ) return;

    MarkupModel markupModel = editor.getMarkupModel();
    markupModel.removeAllHighlighters();
}
项目:intellij-plugin-v4    文件:InputPanel.java   
/**
 * Remove any previous underlining or boxing, but not errors or decision event info
 */
public static void clearTokenInfoHighlighters(Editor editor) {
    MarkupModel markupModel = editor.getMarkupModel();
    for (RangeHighlighter r : markupModel.getAllHighlighters()) {
        if ( r.getUserData(ProfilerPanel.DECISION_EVENT_INFO_KEY)==null &&
            r.getUserData(SYNTAX_ERROR)==null ) {
            markupModel.removeHighlighter(r);
        }
    }
}
项目:intellij-plugin-v4    文件:InputPanel.java   
public void annotateErrorsInPreviewInputEditor(SyntaxError e) {
    Editor editor = getInputEditor();
    if ( editor==null ) return;
    MarkupModel markupModel = editor.getMarkupModel();

    int a, b; // Start and stop index
    RecognitionException cause = e.getException();
    if ( cause instanceof LexerNoViableAltException ) {
        a = ((LexerNoViableAltException) cause).getStartIndex();
        b = ((LexerNoViableAltException) cause).getStartIndex()+1;
    }
    else {
        Token offendingToken = (Token) e.getOffendingSymbol();
        a = offendingToken.getStartIndex();
        b = offendingToken.getStopIndex()+1;
    }
    final TextAttributes attr = new TextAttributes();
    attr.setForegroundColor(JBColor.RED);
    attr.setEffectColor(JBColor.RED);
    attr.setEffectType(EffectType.WAVE_UNDERSCORE);
    RangeHighlighter highlighter =
        markupModel.addRangeHighlighter(a,
                                        b,
                                        ERROR_LAYER, // layer
                                        attr,
                                        HighlighterTargetArea.EXACT_RANGE);
    highlighter.putUserData(SYNTAX_ERROR, e);
}
项目:intellij-plugin-v4    文件:InputPanel.java   
public static void removeHighlighters(Editor editor, Key<?> key) {
    // Remove anything with user data accessible via key
    MarkupModel markupModel = editor.getMarkupModel();
    for (RangeHighlighter r : markupModel.getAllHighlighters()) {
        if ( r.getUserData(key)!=null ) {
            markupModel.removeHighlighter(r);
        }
    }
}
项目:consulo    文件:PersistentRangeHighlighterImpl.java   
static PersistentRangeHighlighterImpl create(@Nonnull MarkupModel model,
                                             int offset,
                                             int layer,
                                             @Nonnull HighlighterTargetArea target,
                                             @Nullable TextAttributes textAttributes,
                                             boolean normalizeStartOffset) {
  int line = model.getDocument().getLineNumber(offset);
  int startOffset = normalizeStartOffset ? model.getDocument().getLineStartOffset(line) : offset;
  return new PersistentRangeHighlighterImpl(model, startOffset, line, layer, target, textAttributes);
}
项目:consulo    文件:PersistentRangeHighlighterImpl.java   
private PersistentRangeHighlighterImpl(@Nonnull MarkupModel model,
                                       int startOffset,
                                       int line,
                                       int layer,
                                       @Nonnull HighlighterTargetArea target,
                                       @Nullable TextAttributes textAttributes) {
  super(model, startOffset, model.getDocument().getLineEndOffset(line), layer, target, textAttributes, false, false);

  myLine = line;
}
项目:consulo    文件:RangeMarkerTest.java   
public void testRangeHighlightersRecreateBug() throws Exception {
  Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]");

  MarkupModel markupModel = DocumentMarkupModel.forDocument(document, ourProject, true);
  for (int i=0; i<2; i++) {
    RangeMarker m = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
    RangeMarker m2 = markupModel.addRangeHighlighter(2, 7, 0, null, HighlighterTargetArea.EXACT_RANGE);
    RangeMarker m3 = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
    markupModel.removeAllHighlighters();
  }
}
项目:consulo    文件:RangeMarkerTest.java   
public void testRangeHighlighterDisposeVsRemoveAllConflict() throws Exception {
  Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]");

  MarkupModel markupModel = DocumentMarkupModel.forDocument(document, ourProject, true);
  RangeMarker m = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
  assertTrue(m.isValid());
  markupModel.removeAllHighlighters();
  assertFalse(m.isValid());
  assertEmpty(markupModel.getAllHighlighters());
  m.dispose();
  assertFalse(m.isValid());
}
项目:consulo    文件:BreakpointItem.java   
protected static void showInEditor(DetailView panel, VirtualFile virtualFile, int line) {
  TextAttributes attributes =
          EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES);

  DetailView.PreviewEditorState state = DetailView.PreviewEditorState.create(virtualFile, line, attributes);

  if (state.equals(panel.getEditorState())) {
    return;
  }

  panel.navigateInPreviewEditor(state);

  TextAttributes softerAttributes = attributes.clone();
  Color backgroundColor = softerAttributes.getBackgroundColor();
  if (backgroundColor != null) {
    softerAttributes.setBackgroundColor(ColorUtil.softer(backgroundColor));
  }

  final Editor editor = panel.getEditor();
  final MarkupModel editorModel = editor.getMarkupModel();
  final MarkupModel documentModel =
          DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);

  for (RangeHighlighter highlighter : documentModel.getAllHighlighters()) {
    if (highlighter.getUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY) == Boolean.TRUE) {
      final int line1 = editor.offsetToLogicalPosition(highlighter.getStartOffset()).line;
      if (line1 != line) {
        editorModel.addLineHighlighter(line1,
                                       DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes);
      }
    }
  }
}
项目:consulo    文件:LineStatusTracker.java   
@Override
@RequiredDispatchThread
protected void createHighlighter(@Nonnull Range range) {
  myApplication.assertIsDispatchThread();

  if (range.getHighlighter() != null) {
    LOG.error("Multiple highlighters registered for the same Range");
    return;
  }

  if (myMode == Mode.SILENT) return;

  int first =
          range.getLine1() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine1());
  int second =
          range.getLine2() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine2());

  MarkupModel markupModel = DocumentMarkupModel.forDocument(myDocument, myProject, true);

  RangeHighlighter highlighter = LineStatusMarkerRenderer.createRangeHighlighter(range, new TextRange(first, second), markupModel);
  highlighter.setLineMarkerRenderer(LineStatusMarkerRenderer.createRenderer(range, (editor) -> {
    return new LineStatusTrackerDrawing.MyLineStatusMarkerPopup(this, editor, range);
  }));

  highlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter());

  range.setHighlighter(highlighter);
}
项目:consulo    文件:IdentifierHighlighterPass.java   
public static void clearMyHighlights(Document document, Project project) {
  MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true);
  for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) {
    Object tooltip = highlighter.getErrorStripeTooltip();
    if (!(tooltip instanceof HighlightInfo)) {
      continue;
    }
    HighlightInfo info = (HighlightInfo)tooltip;
    if (info.type == HighlightInfoType.ELEMENT_UNDER_CARET_READ || info.type == HighlightInfoType.ELEMENT_UNDER_CARET_WRITE) {
      highlighter.dispose();
    }
  }
}