com.intellij.openapi.editor.markup.GutterIconRenderer Java Examples

The following examples show how to use com.intellij.openapi.editor.markup.GutterIconRenderer. 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: XBreakpointUtil.java    From consulo with Apache License 2.0 7 votes vote down vote up
@Nonnull
public static Pair<GutterIconRenderer, Object> findSelectedBreakpoint(@Nonnull final Project project, @Nonnull final Editor editor) {
  int offset = editor.getCaretModel().getOffset();
  Document editorDocument = editor.getDocument();

  List<DebuggerSupport> debuggerSupports = DebuggerSupport.getDebuggerSupports();
  for (DebuggerSupport debuggerSupport : debuggerSupports) {
    final BreakpointPanelProvider<?> provider = debuggerSupport.getBreakpointPanelProvider();

    final int textLength = editor.getDocument().getTextLength();
    if (offset > textLength) {
      offset = textLength;
    }

    Object breakpoint = provider.findBreakpoint(project, editorDocument, offset);
    if (breakpoint != null) {
      final GutterIconRenderer iconRenderer = provider.getBreakpointGutterIconRenderer(breakpoint);
      return Pair.create(iconRenderer, breakpoint);
    }
  }
  return Pair.create(null, null);
}
 
Example #2
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private LineMarkerInfo getRelatedPopover(String singleItemTitle, String singleItemTooltipPrefix, PsiElement lineMarkerTarget, List<GotoRelatedItem> gotoRelatedItems, Icon icon) {

        // single item has no popup
        String title = singleItemTitle;
        if(gotoRelatedItems.size() == 1) {
            String customName = gotoRelatedItems.get(0).getCustomName();
            if(customName != null) {
                title = String.format(singleItemTooltipPrefix, customName);
            }
        }

        return new LineMarkerInfo<>(
            lineMarkerTarget,
            lineMarkerTarget.getTextRange(),
            icon,
            6,
            new ConstantFunction<>(title),
            new RelatedPopupGotoLineMarker.NavigationHandler(gotoRelatedItems),
            GutterIconRenderer.Alignment.RIGHT
        );
    }
 
Example #3
Source File: LineMarkerInfo.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a line marker info for the element.
 *
 * @param element         the element for which the line marker is created.
 * @param range           the range (relative to beginning of file) with which the marker is associated
 * @param icon            the icon to show in the gutter for the line marker
 * @param updatePass      the ID of the daemon pass during which the marker should be recalculated
 * @param tooltipProvider the callback to calculate the tooltip for the gutter icon
 * @param navHandler      the handler executed when the gutter icon is clicked
 */
public LineMarkerInfo(@Nonnull T element,
                      @Nonnull TextRange range,
                      Image icon,
                      int updatePass,
                      @Nullable Function<? super T, String> tooltipProvider,
                      @Nullable GutterIconNavigationHandler<T> navHandler,
                      @Nonnull GutterIconRenderer.Alignment alignment) {
  myIcon = icon;
  myTooltipProvider = tooltipProvider;
  myIconAlignment = alignment;
  elementRef = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
  myNavigationHandler = navHandler;
  startOffset = range.getStartOffset();
  endOffset = range.getEndOffset();
  this.updatePass = 11; //Pass.LINE_MARKERS;
}
 
Example #4
Source File: UnityEventCSharpMethodLineMarkerProvider.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredReadAction
private static LineMarkerInfo createMarker(final PsiElement element)
{
	CSharpMethodDeclaration methodDeclaration = CSharpLineMarkerUtil.getNameIdentifierAs(element, CSharpMethodDeclaration.class);
	if(methodDeclaration != null)
	{
		Unity3dModuleExtension extension = ModuleUtilCore.getExtension(element, Unity3dModuleExtension.class);
		if(extension == null)
		{
			return null;
		}

		UnityFunctionManager.FunctionInfo magicMethod = findMagicMethod(methodDeclaration);
		if(magicMethod != null)
		{
			return new LineMarkerInfo<>(element, element.getTextRange(), Unity3dIcons.EventMethod, Pass.LINE_MARKERS, new ConstantFunction<>(magicMethod.getDescription()), null,
					GutterIconRenderer.Alignment.LEFT);
		}
	}

	return null;
}
 
Example #5
Source File: RecursiveCallCollector.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Override
public void collect(PsiElement psiElement, @Nonnull Consumer<LineMarkerInfo> consumer)
{
	if(psiElement.getNode().getElementType() == CSharpTokens.IDENTIFIER && psiElement.getParent() instanceof CSharpReferenceExpression &&
			psiElement.getParent().getParent() instanceof CSharpMethodCallExpressionImpl)
	{
		PsiElement resolvedElement = ((CSharpReferenceExpression) psiElement.getParent()).resolve();
		if(resolvedElement instanceof CSharpMethodDeclaration)
		{
			CSharpMethodDeclaration methodDeclaration = PsiTreeUtil.getParentOfType(psiElement, CSharpMethodDeclaration.class);
			if(resolvedElement.isEquivalentTo(methodDeclaration))
			{
				LineMarkerInfo<PsiElement> lineMarkerInfo = new LineMarkerInfo<PsiElement>(psiElement, psiElement.getTextRange(), AllIcons.Gutter.RecursiveMethod, Pass.LINE_MARKERS,
						FunctionUtil.constant("Recursive call"), null, GutterIconRenderer.Alignment.CENTER);
				consumer.consume(lineMarkerInfo);
			}
		}
	}
}
 
Example #6
Source File: SmartyTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
private LineMarkerInfo getRelatedPopover(String singleItemTitle, String singleItemTooltipPrefix, PsiElement lineMarkerTarget, List<GotoRelatedItem> gotoRelatedItems) {

        // single item has no popup
        String title = singleItemTitle;
        if(gotoRelatedItems.size() == 1) {
            String customName = gotoRelatedItems.get(0).getCustomName();
            if(customName != null) {
                title = String.format(singleItemTooltipPrefix, customName);
            }
        }

        return new LineMarkerInfo<>(
            lineMarkerTarget,
            lineMarkerTarget.getTextRange(),
            ShopwarePluginIcons.SHOPWARE_LINEMARKER,
            6,
            new ConstantFunction<>(title),
            new fr.adrienbrault.idea.symfony2plugin.dic.RelatedPopupGotoLineMarker.NavigationHandler(gotoRelatedItems),
            GutterIconRenderer.Alignment.RIGHT
        );
    }
 
Example #7
Source File: TemplateLineMarker.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
@NotNull
private LineMarkerInfo getRelatedPopover(@NotNull String singleItemTitle, @NotNull String singleItemTooltipPrefix, @NotNull PsiElement lineMarkerTarget, @NotNull Collection<GotoRelatedItem> gotoRelatedItems, @NotNull Icon icon) {
    // single item has no popup
    String title = singleItemTitle;
    if(gotoRelatedItems.size() == 1) {
        String customName = gotoRelatedItems.iterator().next().getCustomName();
        if(customName != null) {
            title = String.format(singleItemTooltipPrefix, customName);
        }
    }

    return new LineMarkerInfo<>(
        lineMarkerTarget,
        lineMarkerTarget.getTextRange(),
        icon,
        6,
        new ConstantFunction<>(title),
        new RelatedPopupGotoLineMarker.NavigationHandler(gotoRelatedItems),
        GutterIconRenderer.Alignment.RIGHT
    );
}
 
Example #8
Source File: SimpleDiffChange.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private GutterIconRenderer createIconRenderer(@Nonnull final Side sourceSide,
                                              @Nonnull final String tooltipText,
                                              @Nonnull final Image icon,
                                              @Nonnull final Runnable perform) {
  if (!DiffUtil.isEditable(myViewer.getEditor(sourceSide.other()))) return null;
  return new DiffGutterRenderer(icon, tooltipText) {
    @Override
    protected void performAction(AnActionEvent e) {
      if (!myIsValid) return;
      final Project project = e.getProject();
      final Document document = myViewer.getEditor(sourceSide.other()).getDocument();
      DiffUtil.executeWriteCommand(document, project, "Replace change", perform);
    }
  };
}
 
Example #9
Source File: ANTLRv4LineMarkerProvider.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
	final GutterIconNavigationHandler<PsiElement> navHandler =
		new GutterIconNavigationHandler<PsiElement>() {
			@Override
			public void navigate(MouseEvent e, PsiElement elt) {
				System.out.println("don't click on me");
			}
		};
	if ( element instanceof RuleSpecNode ) {
		return new LineMarkerInfo<PsiElement>(element, element.getTextRange(), Icons.FILE,
											  Pass.UPDATE_ALL, null, navHandler,
											  GutterIconRenderer.Alignment.LEFT);
	}
	return null;
}
 
Example #10
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 #11
Source File: SimpleDiffChange.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
public GutterIconRenderer createRenderer() {
  myCtrlPressed = myViewer.getModifierProvider().isCtrlPressed();

  boolean isOtherEditable = DiffUtil.isEditable(myViewer.getEditor(mySide.other()));
  boolean isAppendable = myFragment.getStartLine1() != myFragment.getEndLine1() &&
                         myFragment.getStartLine2() != myFragment.getEndLine2();

  if (isOtherEditable) {
    if (myCtrlPressed && isAppendable) {
      return createAppendRenderer(mySide);
    }
    else {
      return createApplyRenderer(mySide);
    }
  }
  return null;
}
 
Example #12
Source File: OkJsonUpdateLineMarkerProvider.java    From NutzCodeInsight with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) {
    try {
        PsiAnnotation psiAnnotation = this.getPsiAnnotation(psiElement);
        if (psiAnnotation != null) {
            PsiLiteralExpression literalExpression = (PsiLiteralExpression) psiAnnotation.findAttributeValue("value");
            String value = String.valueOf(literalExpression.getValue());
            if (value.startsWith(JSON_PREFIX)) {
                return new LineMarkerInfo<>(psiAnnotation, psiAnnotation.getTextRange(), NutzCons.NUTZ,
                        new FunctionTooltip("快速配置"),
                        new OkJsonUpdateNavigationHandler(value),
                        GutterIconRenderer.Alignment.LEFT);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #13
Source File: UnifiedDiffChange.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private GutterIconRenderer createIconRenderer(@Nonnull final Side sourceSide,
                                              @Nonnull final String tooltipText,
                                              @Nonnull final Image icon) {
  return new DiffGutterRenderer(icon, tooltipText) {
    @Override
    protected void performAction(AnActionEvent e) {
      if (myViewer.isStateIsOutOfDate()) return;
      if (!myViewer.isEditable(sourceSide.other(), true)) return;

      final Project project = e.getProject();
      final Document document = myViewer.getDocument(sourceSide.other());

      DiffUtil.executeWriteCommand(document, project, "Replace change", () -> {
        myViewer.replaceChange(UnifiedDiffChange.this, sourceSide);
        myViewer.scheduleRediff();
      });
      // applyChange() will schedule rediff, but we want to try to do it in sync
      // and we can't do it inside write action
      myViewer.rediff();
    }
  };
}
 
Example #14
Source File: IocBeanInterfaceLineMarkerProvider.java    From NutzCodeInsight with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) {
    try {
        PsiField psiFiled = this.getPsiFiled(psiElement);
        PsiAnnotation psiAnnotation = this.getPsiAnnotation(psiFiled);
        if (psiFiled != null && psiAnnotation != null) {
            GlobalSearchScope moduleScope = psiElement.getResolveScope();
            PsiTypeElementImpl psiTypeElement = this.getPsiTypeElement(psiAnnotation);
            PsiClass psiClass = PsiTypesUtil.getPsiClass(psiTypeElement.getType());
            String name = psiClass.getName();
            List<PsiElement> list = this.getImplListElements(name, psiClass.getQualifiedName(), psiElement, moduleScope);
            if (CollectionUtils.isNotEmpty(list)) {
                return new LineMarkerInfo<>(psiTypeElement, psiTypeElement.getTextRange(), icon,
                        new FunctionTooltip(MessageFormat.format("快速跳转至 {0} 的 @IocBean 实现类", name)),
                        new IocBeanInterfaceNavigationHandler(name, list),
                        GutterIconRenderer.Alignment.LEFT);
            }
        }
    } catch (Exception e) {
    }
    return null;
}
 
Example #15
Source File: ORLineMarkerProvider.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
private void extractRelatedExpressions(@Nullable PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo<?>> result,
                                       @NotNull FileBase containingFile) {
    if (element == null) {
        return;
    }

    FileBase psiRelatedFile = PsiFinder.getInstance(containingFile.getProject()).findRelatedFile(containingFile);
    if (psiRelatedFile != null) {
        Collection<PsiNameIdentifierOwner> expressions = psiRelatedFile.getExpressions(element.getText());
        if (expressions.size() == 1) {
            PsiNameIdentifierOwner relatedElement = expressions.iterator().next();
            PsiElement nameIdentifier = relatedElement.getNameIdentifier();
            if (nameIdentifier != null) {
                String tooltip = GutterIconTooltipHelper
                        .composeText(new PsiElement[]{psiRelatedFile}, "", "Implements method <b>" + nameIdentifier.getText() + "</b> in <b>{0}</b>");
                result.add(NavigationGutterIconBuilder.
                        create(containingFile.isInterface() ? ORIcons.IMPLEMENTED : ORIcons.IMPLEMENTING).
                        setTooltipText(tooltip).
                        setAlignment(GutterIconRenderer.Alignment.RIGHT).
                        setTargets(Collections.singleton(nameIdentifier instanceof PsiLowerSymbol ? nameIdentifier.getFirstChild() : nameIdentifier)).
                        createLineMarkerInfo(element));
            }
        }
    }
}
 
Example #16
Source File: GutterIntentionMenuContributor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addActions(@Nonnull Project project,
                               @Nonnull RangeHighlighterEx info,
                               @Nonnull List<? super HighlightInfo.IntentionActionDescriptor> descriptors,
                               @Nonnull DataContext dataContext) {
  final GutterIconRenderer r = info.getGutterIconRenderer();
  if (r == null || DumbService.isDumb(project) && !DumbService.isDumbAware(r)) {
    return;
  }
  List<HighlightInfo.IntentionActionDescriptor> list = new ArrayList<>();
  AtomicInteger order = new AtomicInteger();
  AnAction[] actions = new AnAction[]{r.getClickAction(), r.getMiddleButtonClickAction(), r.getRightButtonClickAction()};
  if (r.getPopupMenuActions() != null) {
    actions = ArrayUtil.mergeArrays(actions, r.getPopupMenuActions().getChildren(null));
  }
  for (AnAction action : actions) {
    if (action != null) {
      addActions(action, list, r, order, dataContext);
    }
  }
  descriptors.addAll(list);
}
 
Example #17
Source File: LineMarkersPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void queryLineMarkersForInjected(@Nonnull PsiElement element,
                                                @Nonnull final PsiFile containingFile,
                                                @Nonnull Set<? super PsiFile> visitedInjectedFiles,
                                                @Nonnull final PairConsumer<? super PsiElement, ? super LineMarkerInfo<PsiElement>> consumer) {
  final InjectedLanguageManager manager = InjectedLanguageManager.getInstance(containingFile.getProject());
  if (manager.isInjectedFragment(containingFile)) return;

  InjectedLanguageManager.getInstance(containingFile.getProject()).enumerateEx(element, containingFile, false, (injectedPsi, places) -> {
    if (!visitedInjectedFiles.add(injectedPsi)) return; // there may be several concatenated literals making the one injected file
    final Project project = injectedPsi.getProject();
    Document document = PsiDocumentManager.getInstance(project).getCachedDocument(injectedPsi);
    if (!(document instanceof DocumentWindow)) return;
    List<PsiElement> injElements = CollectHighlightsUtil.getElementsInRange(injectedPsi, 0, injectedPsi.getTextLength());
    final List<LineMarkerProvider> providers = getMarkerProviders(injectedPsi.getLanguage(), project);

    queryProviders(injElements, injectedPsi, providers, (injectedElement, injectedMarker) -> {
      GutterIconRenderer gutterRenderer = injectedMarker.createGutterRenderer();
      TextRange injectedRange = new TextRange(injectedMarker.startOffset, injectedMarker.endOffset);
      List<TextRange> editables = manager.intersectWithAllEditableFragments(injectedPsi, injectedRange);
      for (TextRange editable : editables) {
        TextRange hostRange = manager.injectedToHost(injectedPsi, editable);
        Image icon = gutterRenderer == null ? null : gutterRenderer.getIcon();
        GutterIconNavigationHandler<PsiElement> navigationHandler = injectedMarker.getNavigationHandler();
        LineMarkerInfo<PsiElement> converted =
                new LineMarkerInfo<>(injectedElement, hostRange, icon, injectedMarker.updatePass, e -> injectedMarker.getLineMarkerTooltip(), navigationHandler, GutterIconRenderer.Alignment.RIGHT);
        consumer.consume(injectedElement, converted);
      }
    });
  });
}
 
Example #18
Source File: ApplyPatchChange.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private GutterIconRenderer createIgnoreRenderer() {
  return createIconRenderer(DiffBundle.message("merge.dialog.ignore.change.action.name"), AllIcons.Diff.Remove, () -> {
    myViewer.executeCommand("Ignore change", () -> {
      myViewer.markChangeResolved(this);
    });
  });
}
 
Example #19
Source File: ApplyPatchChange.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private GutterIconRenderer createApplyRenderer() {
  return createIconRenderer(DiffBundle.message("merge.dialog.apply.change.action.name"), DiffUtil.getArrowIcon(Side.RIGHT), () -> {
    myViewer.executeCommand("Accept change", () -> {
      myViewer.replaceChange(this);
    });
  });
}
 
Example #20
Source File: ApplyPatchChange.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public GutterIconRenderer createRenderer() {
  switch (myType) {
    case APPLY:
      return createApplyRenderer();
    case IGNORE:
      return createIgnoreRenderer();
    default:
      throw new IllegalArgumentException(myType.name());
  }
}
 
Example #21
Source File: XDebuggerManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
void updateExecutionPoint(@Nullable XSourcePosition position, boolean nonTopFrame, @Nullable GutterIconRenderer gutterIconRenderer) {
  if (position != null) {
    myExecutionPointHighlighter.show(position, nonTopFrame, gutterIconRenderer);
  }
  else {
    myExecutionPointHighlighter.hide();
  }
}
 
Example #22
Source File: ApplyPatchChange.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static GutterIconRenderer createIconRenderer(@Nonnull final String text,
                                                     @Nonnull final Image icon,
                                                     @Nonnull final Runnable perform) {
  final String tooltipText = DiffUtil.createTooltipText(text, null);
  return new DiffGutterRenderer(icon, tooltipText) {
    @Override
    protected void performAction(AnActionEvent e) {
      perform.run();
    }
  };
}
 
Example #23
Source File: TextMergeChange.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private GutterIconRenderer createIconRenderer(@Nonnull final String text,
                                              @Nonnull final Image icon,
                                              boolean ctrlClickVisible,
                                              @Nonnull final Runnable perform) {
  final String tooltipText = DiffUtil.createTooltipText(text, ctrlClickVisible ? CTRL_CLICK_TO_RESOLVE : null);
  return new DiffGutterRenderer(icon, tooltipText) {
    @Override
    protected void performAction(AnActionEvent e) {
      perform.run();
    }
  };
}
 
Example #24
Source File: RelatedItemLineMarkerInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
public RelatedItemLineMarkerInfo(@Nonnull T element, @Nonnull TextRange range, Image icon, int updatePass,
                                 @Nullable Function<? super T, String> tooltipProvider,
                                 @Nullable GutterIconNavigationHandler<T> navHandler,
                                 GutterIconRenderer.Alignment alignment,
                                 @Nonnull final Collection<? extends GotoRelatedItem> targets) {
  this(element, range, icon, updatePass, tooltipProvider, navHandler, alignment, new NotNullLazyValue<Collection<? extends GotoRelatedItem>>() {
    @Nonnull
    @Override
    protected Collection<? extends GotoRelatedItem> compute() {
      return targets;
    }
  });
}
 
Example #25
Source File: RelatedItemLineMarkerInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
public RelatedItemLineMarkerInfo(@Nonnull T element, @Nonnull TextRange range, Image icon, int updatePass,
                                 @Nullable Function<? super T, String> tooltipProvider,
                                 @Nullable GutterIconNavigationHandler<T> navHandler,
                                 GutterIconRenderer.Alignment alignment,
                                 @Nonnull NotNullLazyValue<Collection<? extends GotoRelatedItem>> targets) {
  super(element, range, icon, updatePass, tooltipProvider, navHandler, alignment);
  myTargets = targets;
}
 
Example #26
Source File: ExpectedHighlightingData.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void extractExpectedLineMarkerSet(Document document) {
  String text = document.getText();

  @NonNls String pat = ".*?((<" + LINE_MARKER + ")(?: descr=\"((?:[^\"\\\\]|\\\\\")*)\")?>)(.*)";
  final Pattern p = Pattern.compile(pat, Pattern.DOTALL);
  final Pattern pat2 = Pattern.compile("(.*?)(</" + LINE_MARKER + ">)(.*)", Pattern.DOTALL);

  while (true) {
    Matcher m = p.matcher(text);
    if (!m.matches()) break;
    int startOffset = m.start(1);
    final String descr = m.group(3) != null ? m.group(3) : ANY_TEXT;
    String rest = m.group(4);

    document.replaceString(startOffset, m.end(1), "");

    final Matcher matcher2 = pat2.matcher(rest);
    LOG.assertTrue(matcher2.matches(), "Cannot find closing </" + LINE_MARKER + ">");
    String content = matcher2.group(1);
    int endOffset = startOffset + matcher2.start(3);
    String endTag = matcher2.group(2);

    document.replaceString(startOffset, endOffset, content);
    endOffset -= endTag.length();

    LineMarkerInfo markerInfo = new LineMarkerInfo<PsiElement>(myFile, new TextRange(startOffset, endOffset), null, Pass.LINE_MARKERS,
                                                               new ConstantFunction<PsiElement, String>(descr), null,
                                                               GutterIconRenderer.Alignment.RIGHT);

    lineMarkerInfos.put(document.createRangeMarker(startOffset, endOffset), markerInfo);
    text = document.getText();
  }
}
 
Example #27
Source File: ExpectedHighlightingData.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void refreshLineMarkers() {
  for (Map.Entry<RangeMarker, LineMarkerInfo> entry : lineMarkerInfos.entrySet()) {
    RangeMarker rangeMarker = entry.getKey();
    int startOffset = rangeMarker.getStartOffset();
    int endOffset = rangeMarker.getEndOffset();
    final LineMarkerInfo value = entry.getValue();
    LineMarkerInfo markerInfo = new LineMarkerInfo<PsiElement>(value.getElement(), new TextRange(startOffset,endOffset), null, value.updatePass, new Function<PsiElement,String>() {
      @Override
      public String fun(PsiElement psiElement) {
        return value.getLineMarkerTooltip();
      }
    }, null, GutterIconRenderer.Alignment.RIGHT);
    entry.setValue(markerInfo);
  }
}
 
Example #28
Source File: SimpleDiffChange.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private GutterIconRenderer createAppendRenderer(@Nonnull final Side side) {
  return createIconRenderer(side, "Append", DiffUtil.getArrowDownIcon(side), () -> {
    UsageTrigger.trigger("diff.SimpleDiffChange.Append");
    myViewer.appendChange(this, side);
  });
}
 
Example #29
Source File: UnifiedDiffChange.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
public GutterIconRenderer createRenderer() {
  if (myViewer.isStateIsOutOfDate()) return null;
  if (!myViewer.isEditable(mySide.other(), true)) return null;

  if (mySide.isLeft()) {
    return createIconRenderer(mySide, "Revert", AllIcons.Diff.Remove);
  }
  else {
    return createIconRenderer(mySide, "Accept", AllIcons.Actions.Checked);
  }
}
 
Example #30
Source File: ORLineMarkerProvider.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {
    PsiElement parent = element.getParent();
    FileBase containingFile = (FileBase) element.getContainingFile();

    if (element instanceof PsiTypeConstrName) {
        FileBase psiRelatedFile = PsiFinder.getInstance(containingFile.getProject()).findRelatedFile(containingFile);
        if (psiRelatedFile != null) {
            Collection<PsiType> expressions = psiRelatedFile.getExpressions(element.getText(), PsiType.class);
            if (expressions.size() == 1) {
                PsiType relatedType = expressions.iterator().next();
                PsiElement symbol = PsiTreeUtil.findChildOfType(element, PsiLowerSymbol.class);
                PsiElement relatedSymbol = PsiTreeUtil.findChildOfType(relatedType, PsiLowerSymbol.class);
                if (symbol != null && relatedSymbol != null) {
                    result.add(NavigationGutterIconBuilder.
                            create(containingFile.isInterface() ? ORIcons.IMPLEMENTED : ORIcons.IMPLEMENTING).
                            setAlignment(GutterIconRenderer.Alignment.RIGHT).
                            setTargets(Collections.singleton(relatedSymbol.getFirstChild())).
                            createLineMarkerInfo(symbol.getFirstChild()));
                }
            }
        }
    } else if (element instanceof PsiLowerSymbol && parent instanceof PsiLet && ((PsiNameIdentifierOwner) parent).getNameIdentifier() == element) {
        extractRelatedExpressions(element.getFirstChild(), result, containingFile);
    } else if (element instanceof PsiLowerSymbol && parent instanceof PsiVal && ((PsiNameIdentifierOwner) parent).getNameIdentifier() == element) {
        extractRelatedExpressions(element.getFirstChild(), result, containingFile);
    } else if (element instanceof PsiLowerSymbol && parent instanceof PsiExternal && ((PsiNameIdentifierOwner) parent).getNameIdentifier() == element) {
        extractRelatedExpressions(element.getFirstChild(), result, containingFile);
    } else if (element instanceof PsiUpperSymbol && parent instanceof PsiInnerModule && ((PsiNameIdentifierOwner) parent).getNameIdentifier() == element) {
        extractRelatedExpressions(element.getFirstChild(), result, containingFile);
    } else if (element instanceof PsiUpperSymbol && parent instanceof PsiException && ((PsiNameIdentifierOwner) parent).getNameIdentifier() == element) {
        extractRelatedExpressions(element.getFirstChild(), result, containingFile);
    }
}