com.intellij.codeInsight.daemon.GutterMark Java Examples

The following examples show how to use com.intellij.codeInsight.daemon.GutterMark. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
public void testCamelGutterForVariableAndConstant() {
    myFixture.configureByFiles("JavaCamelRouteLineMarkerProviderFromVariableTestData.java");
    List<GutterMark> gutters = myFixture.findAllGutters();
    assertNotNull(gutters);

    //remove first element since it is navigate to super implementation gutter icon
    gutters.remove(0);

    assertEquals("Should contain 2 Camel gutters", 2, gutters.size());

    assertGuttersHasCamelIcon(gutters);

    LineMarkerInfo.LineMarkerGutterIconRenderer firstGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(0);
    assertTrue(firstGutter.getLineMarkerInfo().getElement() instanceof PsiIdentifier);
    assertEquals("The navigation start element doesn't match", "uriVar",
        firstGutter.getLineMarkerInfo().getElement().getText());

    List<GotoRelatedItem> firstGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstGutter);
    assertEquals("Navigation should have two targets", 2, firstGutterTargets.size());
}
 
Example #2
Source File: JavaCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
public void testCamelGutterForMethodCallFrom() {
    myFixture.configureByFiles("JavaCamelRouteLineMarkerProviderFromMethodCallTestData.java");
    List<GutterMark> gutters = myFixture.findAllGutters();
    assertNotNull(gutters);

    //remove first element since it is navigate to super implementation gutter icon
    gutters.remove(0);
    // remove last element since it is from method returning route uri
    gutters.remove(gutters.size() - 1);

    assertEquals("Should contain 1 Camel gutters", 1, gutters.size());

    assertGuttersHasCamelIcon(gutters);

    LineMarkerInfo.LineMarkerGutterIconRenderer firstGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(0);
    assertTrue(firstGutter.getLineMarkerInfo().getElement() instanceof PsiIdentifier);
    assertEquals("The navigation start element doesn't match", "calcEndpoint",
        firstGutter.getLineMarkerInfo().getElement().getText());

    List<GotoRelatedItem> firstGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstGutter);
    assertEquals("Navigation should have two targets", 2, firstGutterTargets.size());
    assertEquals("The navigation variable target element doesn't match", "calcEndpoint",
        GutterTestUtil.getGuttersWithMethodTarget(firstGutterTargets).get(0).getName());
}
 
Example #3
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
public GutterMark getGutterRenderer(final Point p) {
  int line = myEditor.yToVisualLine(p.y);
  List<GutterMark> renderers = getGutterRenderers(line);
  if (renderers.isEmpty()) {
    return null;
  }

  final GutterMark[] result = {null};
  processIconsRow(line, renderers, (x, y, renderer) -> {
    final int ex = convertX((int)p.getX());
    Icon icon = scaleIcon(renderer.getIcon());
    // Do not check y to extend the area where users could click
    if (x <= ex && ex <= x + icon.getIconWidth()) {
      result[0] = renderer;
    }
  });

  return result[0];
}
 
Example #4
Source File: XmlCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
public void testCamelGutterForToD() {
    myFixture.configureByFiles("XmlCamelRouteLineMarkerProviderToDTestData.xml");
    List<GutterMark> gutters = myFixture.findAllGutters();
    assertNotNull(gutters);

    assertEquals("Should contain 1 Camel gutter", 1, gutters.size());

    assertSame("Gutter should have the Camel icon", ServiceManager.getService(CamelPreferenceService.class).getCamelIcon(), gutters.get(0).getIcon());
    assertEquals("Camel route", gutters.get(0).getTooltipText());

    LineMarkerInfo.LineMarkerGutterIconRenderer gutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(0);

    assertTrue(gutter.getLineMarkerInfo().getElement() instanceof XmlToken);
    assertEquals("The navigation start element doesn't match", "file:inbox",
            PsiTreeUtil.getParentOfType(gutter.getLineMarkerInfo().getElement(), XmlTag.class).getAttribute("uri").getValue());

    List<GotoRelatedItem> gutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(gutter);
    assertEquals("Navigation should have one target", 1, gutterTargets.size());
    assertEquals("The navigation target route doesn't match", "file:inbox", gutterTargets.get(0).getElement().getText());
    assertEquals("The navigation target tag name doesn't match", "toD",
            GutterTestUtil.getGuttersWithXMLTarget(gutterTargets).get(0).getLocalName());

}
 
Example #5
Source File: SelectedTestRunLineMarkerContributorTest.java    From buck with Apache License 2.0 6 votes vote down vote up
private AnAction findActionAtCaretWithText(Predicate<String> textMatcher) {
  List<GutterMark> gutterMarks = myFixture.findGuttersAtCaret();
  for (GutterMark gutterMark : gutterMarks) {
    if (!(gutterMark instanceof GutterIconRenderer)) {
      continue;
    }
    GutterIconRenderer renderer = (GutterIconRenderer) gutterMark;
    ActionGroup group = renderer.getPopupMenuActions();
    for (AnAction action : group.getChildren(new TestActionEvent())) {
      TestActionEvent actionEvent = new TestActionEvent();
      action.update(actionEvent);
      String actualText = actionEvent.getPresentation().getText();
      if (actualText == null) {
        actualText = action.getTemplatePresentation().getText();
        if (actualText == null) {
          continue;
        }
      }
      if (textMatcher.test(actualText)) {
        return action;
      }
    }
  }
  return null;
}
 
Example #6
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public List<GutterMark> getGutterRenderers(int line) {
  if (myLineToGutterRenderers == null || myLineToGutterRenderersCacheForLogicalLines != logicalLinesMatchVisualOnes()) {
    buildGutterRenderersCache();
  }

  Segment focusModeRange = myEditor.getFocusModeRange();
  if (focusModeRange != null) {
    int start = myEditor.offsetToVisualLine(focusModeRange.getStartOffset());
    int end = myEditor.offsetToVisualLine(focusModeRange.getEndOffset());
    if (line < start || line > end) return Collections.emptyList();
  }

  List<GutterMark> marks = myLineToGutterRenderers.get(line);
  return marks != null ? marks : Collections.emptyList();
}
 
Example #7
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public Collection<GutterMark> findAllGutters(final String filePath) {
  final Project project = getProject();
  final SortedMap<Integer, List<GutterMark>> result = new TreeMap<Integer, List<GutterMark>>();
  configureByFilesInner(filePath);

  List<HighlightInfo> infos = doHighlighting();
  for (HighlightInfo info : infos) {
    addGutterIconRenderer(info.getGutterIconRenderer(), info.startOffset, result);
  }

  RangeHighlighter[] highlighters = DocumentMarkupModel.forDocument(myEditor.getDocument(), project, true).getAllHighlighters();
  for (final RangeHighlighter highlighter : highlighters) {
    if (!highlighter.isValid()) continue;
    addGutterIconRenderer(highlighter.getGutterIconRenderer(), highlighter.getStartOffset(), result);
  }
  return ContainerUtil.concat(result.values());
}
 
Example #8
Source File: JavaCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void testCamelGutterForToDAndToF() {
    myFixture.configureByFiles("JavaCamelRouteLineMarkerProviderAlternateToTestData.java");
    List<GutterMark> gutters = myFixture.findAllGutters();
    assertNotNull(gutters);

    //remove first element since it is navigate to super implementation gutter icon
    gutters.remove(0);

    assertEquals("Should contain 2 Camel gutters", 2, gutters.size());

    assertGuttersHasCamelIcon(gutters);

    LineMarkerInfo.LineMarkerGutterIconRenderer firstGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(0);

    assertTrue(firstGutter.getLineMarkerInfo().getElement() instanceof PsiJavaToken);
    assertEquals("The navigation start element doesn't match", "\"file:test\"",
        firstGutter.getLineMarkerInfo().getElement().getText());


    List<GotoRelatedItem> firstGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstGutter);
    assertEquals("Navigation should have one target", 1, firstGutterTargets.size());
    assertEquals("The navigation target element doesn't match", "from(\"file:test\")",
        GutterTestUtil.getGuttersWithJavaTarget(firstGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());


    LineMarkerInfo.LineMarkerGutterIconRenderer secondGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(1);

    assertTrue(secondGutter.getLineMarkerInfo().getElement() instanceof PsiJavaToken);
    assertEquals("The navigation start element doesn't match", "\"file:test\"",
        secondGutter.getLineMarkerInfo().getElement().getText());

    List<GotoRelatedItem> secondGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(secondGutter);
    assertEquals("Navigation should have one target", 1, secondGutterTargets.size());
    assertEquals("The navigation target element doesn't match", "from(\"file:test\")",
        GutterTestUtil.getGuttersWithJavaTarget(secondGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());
}
 
Example #9
Source File: Bookmark.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void release() {
  int line = getLine();
  if (line < 0) {
    return;
  }
  final Document document = getDocument();
  if (document == null) return;
  MarkupModelEx markup = (MarkupModelEx)DocumentMarkupModel.forDocument(document, myProject, true);
  final Document markupDocument = markup.getDocument();
  if (markupDocument.getLineCount() <= line) return;
  final int startOffset = markupDocument.getLineStartOffset(line);
  final int endOffset = markupDocument.getLineEndOffset(line);

  final Ref<RangeHighlighterEx> found = new Ref<RangeHighlighterEx>();
  markup.processRangeHighlightersOverlappingWith(startOffset, endOffset, new Processor<RangeHighlighterEx>() {
    @Override
    public boolean process(RangeHighlighterEx highlighter) {
      GutterMark renderer = highlighter.getGutterIconRenderer();
      if (renderer instanceof MyGutterIconRenderer && ((MyGutterIconRenderer)renderer).myBookmark == Bookmark.this) {
        found.set(highlighter);
        return false;
      }
      return true;
    }
  });
  if (!found.isNull()) found.get().dispose();
}
 
Example #10
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Point getClickedIconCenter(@Nonnull MouseEvent e) {
  GutterMark renderer = getGutterRenderer(e);
  final Ref<Point> point = new Ref<>(e.getPoint());
  int line = myEditor.yToVisualLine(e.getY());
  List<GutterMark> row = getGutterRenderers(line);
  processIconsRow(line, row, (x, y, r) -> {
    if (renderer == r) {
      Icon icon = scaleIcon(r.getIcon());
      point.set(new Point(x + icon.getIconWidth() / 2, y + icon.getIconHeight() / 2));
    }
  });
  return point.get();
}
 
Example #11
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
void tooltipAvailable(@Nullable String toolTip, @Nonnull MouseEvent e, @Nullable GutterMark renderer) {
  myCalculatingInBackground = null;
  TooltipController controller = TooltipController.getInstance();
  if (toolTip == null || toolTip.isEmpty() || myEditor.isDisposed()) {
    controller.cancelTooltip(GUTTER_TOOLTIP_GROUP, e, false);
  }
  else {
    final Ref<Point> t = new Ref<>(e.getPoint());
    int line = myEditor.yToVisualLine(e.getY());
    List<GutterMark> row = getGutterRenderers(line);
    Balloon.Position ballPosition = Balloon.Position.atRight;
    if (!row.isEmpty()) {
      Map<Integer, GutterMark> xPos = new TreeMap<>();
      final int[] currentPos = {0};
      processIconsRow(line, row, (x, y, r) -> {
        xPos.put(x, r);
        if (renderer == r) {
          currentPos[0] = x;
          Icon icon = scaleIcon(r.getIcon());
          t.set(new Point(x + icon.getIconWidth() / 2, y + icon.getIconHeight() / 2));
        }
      });

      List<Integer> xx = new ArrayList<>(xPos.keySet());
      int posIndex = xx.indexOf(currentPos[0]);
      if (xPos.size() > 1 && posIndex == 0) {
        ballPosition = Balloon.Position.below;
      }
    }

    RelativePoint showPoint = new RelativePoint(this, t.get());

    TooltipRenderer tr = ((EditorMarkupModel)myEditor.getMarkupModel()).getErrorStripTooltipRendererProvider().calcTooltipRenderer(toolTip);
    HintHint hint = new HintHint(this, t.get()).setAwtTooltip(true).setPreferredPosition(ballPosition).setRequestFocus(ScreenReader.isActive());
    if (myEditor.getComponent().getRootPane() != null) {
      controller.showTooltipByMouseMove(myEditor, showPoint, tr, false, GUTTER_TOOLTIP_GROUP, hint);
    }
  }
}
 
Example #12
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void paintIconRow(int line, List<? extends GutterMark> row, final Graphics2D g) {
  processIconsRow(line, row, (x, y, renderer) -> {
    Icon icon = scaleIcon(renderer.getIcon());

    AffineTransform old = setMirrorTransformIfNeeded(g, x, icon.getIconWidth());
    try {
      icon.paintIcon(this, g, x, y);
    }
    finally {
      if (old != null) g.setTransform(old);
    }
  });
}
 
Example #13
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void calcLineMarkerAreaWidth(boolean canShrink) {
  myLeftFreePaintersAreaShown = myForceLeftFreePaintersAreaShown;
  myRightFreePaintersAreaShown = myForceRightFreePaintersAreaShown;

  processRangeHighlighters(0, myEditor.getDocument().getTextLength(), highlighter -> {
    LineMarkerRenderer lineMarkerRenderer = highlighter.getLineMarkerRenderer();
    if (lineMarkerRenderer != null) {
      LineMarkerRendererEx.Position position = getLineMarkerPosition(lineMarkerRenderer);
      if (position == LineMarkerRendererEx.Position.LEFT && isLineMarkerVisible(highlighter)) myLeftFreePaintersAreaShown = true;
      if (position == LineMarkerRendererEx.Position.RIGHT && isLineMarkerVisible(highlighter)) myRightFreePaintersAreaShown = true;
    }
  });

  int minWidth = areIconsShown() ? scaleWidth(myStartIconAreaWidth) : 0;
  myIconsAreaWidth = canShrink ? minWidth : Math.max(myIconsAreaWidth, minWidth);

  processGutterRenderers((line, renderers) -> {
    int width = 1;
    for (int i = 0; i < renderers.size(); i++) {
      GutterMark renderer = renderers.get(i);
      if (!checkDumbAware(renderer)) continue;
      width += scaleIcon(renderer.getIcon()).getIconWidth();
      if (i > 0) width += getGapBetweenIcons();
    }
    if (myIconsAreaWidth < width) {
      myIconsAreaWidth = width + 1;
    }
    return true;
  });

  if (isDumbMode()) {
    myIconsAreaWidth = Math.max(myIconsAreaWidth, myLastNonDumbModeIconAreaWidth);
  }
  else {
    myLastNonDumbModeIconAreaWidth = myIconsAreaWidth;
  }
}
 
Example #14
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void buildGutterRenderersCache() {
  myLineToGutterRenderersCacheForLogicalLines = logicalLinesMatchVisualOnes();
  myLineToGutterRenderers = new TIntObjectHashMap<>();
  processRangeHighlighters(0, myEditor.getDocument().getTextLength(), highlighter -> {
    GutterMark renderer = highlighter.getGutterIconRenderer();
    if (renderer == null) {
      return;
    }
    if (!areIconsShown() && !(renderer instanceof NonHideableIconGutterMark)) {
      return;
    }
    if (!isHighlighterVisible(highlighter)) {
      return;
    }
    int line = myEditor.offsetToVisualLine(highlighter.getStartOffset());
    List<GutterMark> renderers = myLineToGutterRenderers.get(line);
    if (renderers == null) {
      renderers = new SmartList<>();
      myLineToGutterRenderers.put(line, renderers);
    }

    renderers.add(renderer);
  });

  myLineToGutterRenderers.transformValues(value -> {
    List<GutterMark> newValue = value;
    for (GutterMarkPreprocessor preprocessor : GutterMarkPreprocessor.EP_NAME.getExtensions()) {
      newValue = preprocessor.processMarkers(value);
    }

    // Don't allow more than 5 icons per line
    newValue = ContainerUtil.getFirstItems(newValue, 4);

    return newValue;
  });
}
 
Example #15
Source File: HighlightInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected HighlightInfo(@Nullable TextAttributes forcedTextAttributes,
                        @Nullable TextAttributesKey forcedTextAttributesKey,
                        @Nonnull HighlightInfoType type,
                        int startOffset,
                        int endOffset,
                        @Nullable String escapedDescription,
                        @Nullable String escapedToolTip,
                        @Nonnull HighlightSeverity severity,
                        boolean afterEndOfLine,
                        @Nullable Boolean needsUpdateOnTyping,
                        boolean isFileLevelAnnotation,
                        int navigationShift,
                        ProblemGroup problemGroup,
                        @Nullable String inspectionToolId,
                        GutterMark gutterIconRenderer) {
  if (startOffset < 0 || startOffset > endOffset) {
    LOG.error("Incorrect highlightInfo bounds. description=" + escapedDescription + "; startOffset=" + startOffset + "; endOffset=" + endOffset + ";type=" + type);
  }
  this.forcedTextAttributes = forcedTextAttributes;
  this.forcedTextAttributesKey = forcedTextAttributesKey;
  this.type = type;
  this.startOffset = startOffset;
  this.endOffset = endOffset;
  fixStartOffset = startOffset;
  fixEndOffset = endOffset;
  description = escapedDescription;
  // optimization: do not retain extra memory if can recompute
  toolTip = encodeTooltip(escapedToolTip, escapedDescription);
  this.severity = severity;
  setFlag(AFTER_END_OF_LINE_MASK, afterEndOfLine);
  setFlag(NEEDS_UPDATE_ON_TYPING_MASK, calcNeedUpdateOnTyping(needsUpdateOnTyping, type));
  setFlag(FILE_LEVEL_ANNOTATION_MASK, isFileLevelAnnotation);
  this.navigationShift = navigationShift;
  myProblemGroup = problemGroup;
  this.gutterIconRenderer = gutterIconRenderer;
  this.inspectionToolId = inspectionToolId;
}
 
Example #16
Source File: RangeHighlighterImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void setGutterIconRenderer(GutterIconRenderer renderer) {
  boolean oldRenderedInGutter = isRenderedInGutter();
  GutterMark old = myGutterIconRenderer;
  myGutterIconRenderer = renderer;
  if (isRenderedInGutter() != oldRenderedInGutter) {
    myModel.treeFor(this).updateRenderedFlags(this);
  }
  if (!Comparing.equal(old, renderer)) {
    fireChanged(true, false);
  }
}
 
Example #17
Source File: JavaCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void testCamelGutter() {
    myFixture.configureByFiles("JavaCamelRouteLineMarkerProviderTestData.java");
    List<GutterMark> gutters = myFixture.findAllGutters();
    assertNotNull(gutters);

    //remove first element since it is navigate to super implementation gutter icon
    gutters.remove(0);

    assertEquals("Should contain 3 Camel gutters", 3, gutters.size());

    assertGuttersHasCamelIcon(gutters);

    LineMarkerInfo.LineMarkerGutterIconRenderer firstGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(1);

    assertTrue(firstGutter.getLineMarkerInfo().getElement() instanceof PsiJavaToken);
    assertEquals("The navigation start element doesn't match", "\"file:inbox\"",
        firstGutter.getLineMarkerInfo().getElement().getText());


    List<GotoRelatedItem> firstGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstGutter);
    assertEquals("Navigation should have one target", 1, firstGutterTargets.size());
    assertEquals("The navigation target element doesn't match", "from(\"file:outbox\")",
        GutterTestUtil.getGuttersWithJavaTarget(firstGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());


    LineMarkerInfo.LineMarkerGutterIconRenderer secondGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(2);

    assertTrue(secondGutter.getLineMarkerInfo().getElement() instanceof PsiJavaToken);
    assertEquals("The navigation start element doesn't match", "\"file:outbox\"",
        secondGutter.getLineMarkerInfo().getElement().getText());

    List<GotoRelatedItem> secondGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(secondGutter);
    assertEquals("Navigation should have one target", 1, secondGutterTargets.size());
    assertEquals("The navigation target element doesn't match", "from(\"file:inbox\")",
        GutterTestUtil.getGuttersWithJavaTarget(secondGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());
}
 
Example #18
Source File: JavaCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
private void assertGuttersHasCamelIcon(List<GutterMark> gutters) {
    Icon defaultIcon = ServiceManager.getService(CamelPreferenceService.class).getCamelIcon();
    gutters.forEach(gutterMark -> {
        assertSame("Gutter should have the Camel icon", defaultIcon, gutterMark.getIcon());
        assertEquals("Camel route", gutterMark.getTooltipText());
    });
}
 
Example #19
Source File: BeanInjectLineMarkerProviderTest.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private List<RelatedItemLineMarkerInfo<? extends PsiElement>> findBeanInjectMarkers() {
    List<GutterMark> gutters = myFixture.findAllGutters();
    return gutters.stream()
            .filter(g -> BeanInjectLineMarkerProvider.MARKER_TOOLTIP_TEXT.equals(g.getTooltipText()))
            .map(g -> (LineMarkerInfo.LineMarkerGutterIconRenderer<? extends PsiElement>) g)
            .map(LineMarkerInfo.LineMarkerGutterIconRenderer::getLineMarkerInfo)
            .map(info -> (RelatedItemLineMarkerInfo<? extends PsiElement>) info)
            .collect(Collectors.toList());
}
 
Example #20
Source File: XmlCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void testCamelGutter() {
    myFixture.configureByFiles("XmlCamelRouteLineMarkerProviderTestData.xml");
    List<GutterMark> gutters = myFixture.findAllGutters();
    assertNotNull(gutters);

    assertEquals("Does not contain the expected amount of Camel gutters", 3, gutters.size());

    Icon defaultIcon = ServiceManager.getService(CamelPreferenceService.class).getCamelIcon();
    gutters.forEach(gutterMark -> {
        assertSame("Gutter should have the Camel icon", defaultIcon, gutterMark.getIcon());
        assertEquals("Camel route", gutterMark.getTooltipText());
    });

    LineMarkerInfo.LineMarkerGutterIconRenderer firstGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(1);

    assertTrue(firstGutter.getLineMarkerInfo().getElement() instanceof XmlToken);
    assertEquals("The navigation start element doesn't match", "file:inbox",
            PsiTreeUtil.getParentOfType(firstGutter.getLineMarkerInfo().getElement(), XmlTag.class).getAttribute("uri").getValue());

    List<GotoRelatedItem> firstGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstGutter);
    assertEquals("Navigation should have one target", 1, firstGutterTargets.size());
    assertEquals("The navigation target route doesn't match", "file:inbox", firstGutterTargets.get(0).getElement().getText());
    assertEquals("The navigation target tag name doesn't match", "to",
            GutterTestUtil.getGuttersWithXMLTarget(firstGutterTargets).get(0).getLocalName());

    LineMarkerInfo.LineMarkerGutterIconRenderer secondGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(2);

    assertTrue(secondGutter.getLineMarkerInfo().getElement() instanceof XmlToken);
    assertEquals("The navigation start element doesn't match", "file:outbox",
            PsiTreeUtil.getParentOfType(secondGutter.getLineMarkerInfo().getElement(), XmlTag.class).getAttribute("uri").getValue());

    List<GotoRelatedItem> secondGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(secondGutter);
    assertEquals("Navigation should have one target", 1, secondGutterTargets.size());
    assertEquals("The navigation target route doesn't match", "file:outbox", secondGutterTargets.get(0).getElement().getText());
    assertEquals("The navigation target tag name doesn't match", "to",
            GutterTestUtil.getGuttersWithXMLTarget(secondGutterTargets).get(0).getLocalName());
}
 
Example #21
Source File: MultiLanguageCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void testCamelGutterForJavaAndXMLRoutes() {
    myFixture.configureByFiles("XmlCamelRouteLineMarkerProviderTestData.xml", "JavaCamelRouteLineMarkerProviderTestData.java");
    List<GutterMark> javaGutters = myFixture.findAllGutters("JavaCamelRouteLineMarkerProviderTestData.java");
    assertNotNull(javaGutters);

    List<GutterMark> xmlGutters = myFixture.findAllGutters("XmlCamelRouteLineMarkerProviderTestData.xml");
    assertNotNull(xmlGutters);

    //remove first element since it is navigate to super implementation gutter icon
    javaGutters.remove(0);

    assertEquals("Should contain 3 Java Camel gutters", 3, javaGutters.size());
    assertEquals("Should contain 2 XML Camel gutters", 3, xmlGutters.size());

    //from Java to XML
    LineMarkerInfo.LineMarkerGutterIconRenderer firstJavaGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) javaGutters.get(1);
    assertTrue(firstJavaGutter.getLineMarkerInfo().getElement() instanceof PsiJavaToken);
    assertEquals("The navigation start element doesn't match", "\"file:inbox\"",
        firstJavaGutter.getLineMarkerInfo().getElement().getText());


    List<GotoRelatedItem> firstJavaGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstJavaGutter);
    assertEquals("Navigation should have two targets", 2, firstJavaGutterTargets.size());
    assertEquals("The navigation target XML tag name doesn't match", "to", getGuttersWithXMLTarget(firstJavaGutterTargets).get(0).getLocalName());
    assertEquals("The navigation Java target element doesn't match", "from(\"file:outbox\")",
            getGuttersWithJavaTarget(firstJavaGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());

    //from XML to Java
    LineMarkerInfo.LineMarkerGutterIconRenderer firstXmlGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) xmlGutters.get(1);
    assertTrue(firstXmlGutter.getLineMarkerInfo().getElement() instanceof XmlToken);
    assertEquals("The navigation start element doesn't match", "\"file:inbox\"",
            (firstJavaGutter.getLineMarkerInfo().getElement()).getText());


    List<GotoRelatedItem> firstXmlGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstXmlGutter);
    assertEquals("Navigation should have two targets", 2, firstXmlGutterTargets.size());
    assertEquals("The navigation target XML tag name doesn't match", "to", getGuttersWithXMLTarget(firstXmlGutterTargets).get(0).getLocalName());
    assertEquals("The navigation Java target element doesn't match", "from(\"file:outbox\")",
            getGuttersWithJavaTarget(firstXmlGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());
}
 
Example #22
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void addGutterIconRenderer(final GutterMark renderer, final int offset, SortedMap<Integer, List<GutterMark>> result) {
  if (renderer == null) return;

  List<GutterMark> renderers = result.get(offset);
  if (renderers == null) {
    result.put(offset, renderers = new SmartList<GutterMark>());
  }
  renderers.add(renderer);
}
 
Example #23
Source File: CodeInsightTestFixture.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
Collection<GutterMark> findAllGutters(String filePath);
 
Example #24
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void processGutterRenderers(@Nonnull TIntObjectProcedure<List<GutterMark>> processor) {
  if (myLineToGutterRenderers == null || myLineToGutterRenderersCacheForLogicalLines != logicalLinesMatchVisualOnes()) {
    buildGutterRenderersCache();
  }
  myLineToGutterRenderers.forEachEntry(processor);
}
 
Example #25
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void paintIcons(final int firstVisibleLine, final int lastVisibleLine, final Graphics2D g) {
  for (int line = firstVisibleLine; line <= lastVisibleLine; line++) {
    List<GutterMark> renderers = getGutterRenderers(line);
    paintIconRow(line, renderers, g);
  }
}
 
Example #26
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
Image getDragImage(GutterMark renderer) {
  return IconUtil.toImage(scaleIcon(renderer.getIcon()));
}
 
Example #27
Source File: EditorGutterComponentEx.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public GutterMark getGutterRenderer(final Point p) {
  return null;
}
 
Example #28
Source File: EditorGutterComponentEx.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public abstract List<GutterMark> getGutterRenderers(int line);
 
Example #29
Source File: GutterMarkPreprocessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
List<GutterMark> processMarkers(@Nonnull List<GutterMark> list);
 
Example #30
Source File: HighlightInfo.java    From consulo with Apache License 2.0 4 votes vote down vote up
public GutterMark getGutterIconRenderer() {
  return gutterIconRenderer;
}