com.intellij.navigation.GotoRelatedItem Java Examples

The following examples show how to use com.intellij.navigation.GotoRelatedItem. 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: NavigationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Returns navigation popup that shows list of related items from {@code items} list
 *
 * @param items
 * @param title
 * @param showContainingModules Whether the popup should show additional information that aligned at the right side of the dialog.<br>
 *                              It's usually a module name or library name of corresponding navigation item.<br>
 *                              {@code false} by default
 * @return
 */
@Nonnull
public static JBPopup getRelatedItemsPopup(final List<? extends GotoRelatedItem> items, String title, boolean showContainingModules) {
  Object[] elements = new Object[items.size()];
  //todo[nik] move presentation logic to GotoRelatedItem class
  final Map<PsiElement, GotoRelatedItem> itemsMap = new HashMap<>();
  for (int i = 0; i < items.size(); i++) {
    GotoRelatedItem item = items.get(i);
    elements[i] = item.getElement() != null ? item.getElement() : item;
    itemsMap.put(item.getElement(), item);
  }

  return getPsiElementPopup(elements, itemsMap, title, showContainingModules, element -> {
    if (element instanceof PsiElement) {
      //noinspection SuspiciousMethodCalls
      itemsMap.get(element).navigate();
    }
    else {
      ((GotoRelatedItem)element).navigate();
    }
    return true;
  });
}
 
Example #2
Source File: NavigationGutterIconBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
public RelatedItemLineMarkerInfo<PsiElement> createLineMarkerInfo(@Nonnull PsiElement element) {
  final MyNavigationGutterIconRenderer renderer = createGutterIconRenderer(element.getProject());
  final String tooltip = renderer.getTooltipText();
  NotNullLazyValue<Collection<? extends GotoRelatedItem>> gotoTargets = new NotNullLazyValue<Collection<? extends GotoRelatedItem>>() {
    @Nonnull
    @Override
    protected Collection<? extends GotoRelatedItem> compute() {
      if (myGotoRelatedItemProvider != null) {
        return ContainerUtil.concat(myTargets.getValue(), myGotoRelatedItemProvider);
      }
      return Collections.emptyList();
    }
  };
  return new RelatedItemLineMarkerInfo<PsiElement>(element, element.getTextRange(), renderer.getIcon(), Pass.LINE_MARKERS,
                                                   tooltip == null ? null : new ConstantFunction<PsiElement, String>(tooltip),
                                                   renderer.isNavigateAction() ? renderer : null, renderer.getAlignment(),
                                                   gotoTargets);
}
 
Example #3
Source File: DelegatingSwitchToHeaderOrSourceProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public List<? extends GotoRelatedItem> getItems(PsiElement psiElement) {
  PsiFile psiFile = psiElement.getContainingFile();
  Project project = psiElement.getProject();
  if (!(psiFile instanceof OCFile) || !Blaze.isBlazeProject(project)) {
    return ImmutableList.of();
  }
  OCFile ocFile = (OCFile) psiFile;
  // Try to find the corresponding file quickly. If we can't even figure that out (e.g.,
  // if headers are stored in a different directory) then delegate to the original provider.
  OCFile correspondingFile = SwitchToHeaderOrSourceSearch.getCorrespondingFile(ocFile);
  if (correspondingFile == null) {
    Optional<List<? extends GotoRelatedItem>> fromDelegate =
        getItemsWithTimeout(() -> DELEGATE.getItems(psiElement));
    if (fromDelegate.isPresent()) {
      return fromDelegate.get();
    }
    logger.info("Timed out without a fallback.");
    return ImmutableList.of();
  }
  return ImmutableList.of(
      new GotoRelatedItem(
          correspondingFile, correspondingFile.isHeader() ? "Headers" : "Sources"));
}
 
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: NavigationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static List<GotoRelatedItem> collectRelatedItems(@Nonnull PsiElement contextElement, @Nullable DataContext dataContext) {
  Set<GotoRelatedItem> items = ContainerUtil.newLinkedHashSet();
  for (GotoRelatedProvider provider : Extensions.getExtensions(GotoRelatedProvider.EP_NAME)) {
    items.addAll(provider.getItems(contextElement));
    if (dataContext != null) {
      items.addAll(provider.getItems(dataContext));
    }
  }
  GotoRelatedItem[] result = items.toArray(new GotoRelatedItem[items.size()]);
  Arrays.sort(result, (i1, i2) -> {
    String o1 = i1.getGroup();
    String o2 = i2.getGroup();
    return StringUtil.isEmpty(o1) ? 1 : StringUtil.isEmpty(o2) ? -1 : o1.compareTo(o2);
  });
  return Arrays.asList(result);
}
 
Example #6
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 #7
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 #8
Source File: RelatedItemLineMarkerGotoAdapter.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addItemsForMarkers(List<RelatedItemLineMarkerInfo> markers,
                                       List<GotoRelatedItem> result) {
  Set<PsiFile> addedFiles = new HashSet<PsiFile>();
  for (RelatedItemLineMarkerInfo<?> marker : markers) {
    Collection<? extends GotoRelatedItem> items = marker.createGotoRelatedItems();
    for (GotoRelatedItem item : items) {
      PsiElement element = item.getElement();
      if (element instanceof PsiFile) {
        PsiFile file = (PsiFile)element;
        if (addedFiles.contains(file)) {
          continue;
        }
      }
      if (element != null) {
        ContainerUtil.addIfNotNull(element.getContainingFile(), addedFiles);
      }
      result.add(item);
    }
  }
}
 
Example #9
Source File: GotoRelatedFileAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {

  DataContext context = e.getDataContext();
  Editor editor = context.getData(PlatformDataKeys.EDITOR);
  PsiFile psiFile = context.getData(LangDataKeys.PSI_FILE);
  if (psiFile == null) return;

  List<GotoRelatedItem> items = getItems(psiFile, editor, context);
  if (items.isEmpty()) return;
  if (items.size() == 1 && items.get(0).getElement() != null) {
    items.get(0).navigate();
    return;
  }
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    //noinspection UseOfSystemOutOrSystemErr
    System.out.println(items);
  }
  createPopup(items, "Go to Related Files").showInBestPositionFor(context);
}
 
Example #10
Source File: GotoRelatedFileAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static JBPopup createPopup(final List<? extends GotoRelatedItem> items, final String title) {
  Object[] elements = new Object[items.size()];
  //todo[nik] move presentation logic to GotoRelatedItem class
  final Map<PsiElement, GotoRelatedItem> itemsMap = new HashMap<PsiElement, GotoRelatedItem>();
  for (int i = 0; i < items.size(); i++) {
    GotoRelatedItem item = items.get(i);
    elements[i] = item.getElement() != null ? item.getElement() : item;
    itemsMap.put(item.getElement(), item);
  }

  return getPsiElementPopup(elements, itemsMap, title, new Processor<Object>() {
    @Override
    public boolean process(Object element) {
      if (element instanceof PsiElement) {
        //noinspection SuspiciousMethodCalls
        itemsMap.get(element).navigate();
      }
      else {
        ((GotoRelatedItem)element).navigate();
      }
      return true;
    }
  }
  );
}
 
Example #11
Source File: GotoRelatedFileAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static List<GotoRelatedItem> getItems(@Nonnull PsiFile psiFile, @Nullable Editor editor, @Nullable DataContext dataContext) {
  PsiElement contextElement = psiFile;
  if (editor != null) {
    PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset());
    if (element != null) {
      contextElement = element;
    }
  }

  Set<GotoRelatedItem> items = new LinkedHashSet<GotoRelatedItem>();

  for (GotoRelatedProvider provider : Extensions.getExtensions(GotoRelatedProvider.EP_NAME)) {
    items.addAll(provider.getItems(contextElement));
    if (dataContext != null) {
      items.addAll(provider.getItems(dataContext));
    }
  }
  sortByGroupNames(items);
  return new ArrayList<GotoRelatedItem>(items);
}
 
Example #12
Source File: GotoRelatedFileAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static Action createNumberAction(final int mnemonic,
                                         final ListPopupImpl listPopup,
                                         final Map<PsiElement, GotoRelatedItem> itemsMap,
                                         final Processor<Object> processor) {
  return new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent e) {
      for (final Object item : listPopup.getListStep().getValues()) {
        if (getMnemonic(item, itemsMap) == mnemonic) {
          listPopup.setFinalRunnable(new Runnable() {
            @Override
            public void run() {
              processor.process(item);
            }
          });
          listPopup.closeOk(null);
        }
      }
    }
  };
}
 
Example #13
Source File: AnnotationLightCodeInsightFixtureTestCase.java    From idea-php-generics-plugin with MIT License 6 votes vote down vote up
@Override
public boolean match(@NotNull LineMarkerInfo markerInfo) {
    if(markerInfo.getLineMarkerTooltip() == null || !markerInfo.getLineMarkerTooltip().equals(toolTip)) {
        return false;
    }

    if(!(markerInfo instanceof RelatedItemLineMarkerInfo)) {
        return false;
    }

    for (Object o : ((RelatedItemLineMarkerInfo) markerInfo).createGotoRelatedItems()) {
        if(o instanceof GotoRelatedItem && this.pattern.accepts(((GotoRelatedItem) o).getElement())) {
            return true;
        }
    }

    return false;
}
 
Example #14
Source File: GotoTestRelatedProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public List<? extends GotoRelatedItem> getItems(@Nonnull DataContext context) {
  final PsiFile file = context.getData(LangDataKeys.PSI_FILE);
  List<PsiElement> result;
  final boolean isTest = TestFinderHelper.isTest(file);
  if (isTest) {
    result = TestFinderHelper.findClassesForTest(file);
  } else {
    result = TestFinderHelper.findTestsForClass(file);
  }

  if (!result.isEmpty()) {
    final List<GotoRelatedItem> items = new ArrayList<GotoRelatedItem>();
    for (PsiElement element : result) {
      items.add(new GotoRelatedItem(element, isTest ? "Tests" : "Testee classes"));
    }
    return items;
  }
  return super.getItems(context);
}
 
Example #15
Source File: DelegatingSwitchToHeaderOrSourceProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Runs the getter under a progress indicator that cancels itself after a certain timeout (assumes
 * that the getter will check for cancellation cooperatively).
 *
 * @param getter computes the GotoRelatedItems.
 * @return a list of items computed, or Optional.empty if timed out.
 */
private Optional<List<? extends GotoRelatedItem>> getItemsWithTimeout(
    ThrowableComputable<List<? extends GotoRelatedItem>, RuntimeException> getter) {
  try {
    ProgressIndicator indicator = new ProgressIndicatorBase();
    ProgressIndicator wrappedIndicator =
        new WatchdogIndicator(indicator, TIMEOUT_MS, TimeUnit.MILLISECONDS);
    // We don't use "runProcessWithProgressSynchronously" because that pops up a ProgressWindow,
    // and that will cause the event IDs to bump up and no longer match the event ID stored in
    // DataContexts which may be used in one of the GotoRelatedProvider#getItems overloads.
    return Optional.of(
        ProgressManager.getInstance()
            .runProcess(() -> ReadAction.compute(getter), wrappedIndicator));
  } catch (ProcessCanceledException e) {
    return Optional.empty();
  }
}
 
Example #16
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 #17
Source File: TemplateLineMarker.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
private void visitOverwrittenTemplateFile(@NotNull PsiFile psiFile, @NotNull List<GotoRelatedItem> gotoRelatedItems, @NotNull String sectionName, int depth, @NotNull LazyVirtualFileTemplateResolver resolver) {
    // simple secure recursive calls
    if(depth-- <= 0) {
        return;
    }

    BladeTemplateUtil.DirectiveParameterVisitor visitor = parameter -> {
        if (sectionName.equalsIgnoreCase(parameter.getContent())) {
            gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(parameter.getPsiElement()).withIcon(LaravelIcons.LARAVEL, LaravelIcons.LARAVEL));
        }
    };

    BladeTemplateUtil.visitSection(psiFile, visitor);
    BladeTemplateUtil.visitYield(psiFile, visitor);

    final int finalDepth = depth;
    BladeTemplateUtil.visitExtends(psiFile, parameter -> {
        for (VirtualFile virtualFile : resolver.resolveTemplateName(psiFile.getProject(), parameter.getContent())) {
            PsiFile templatePsiFile = PsiManager.getInstance(psiFile.getProject()).findFile(virtualFile);
            if (templatePsiFile != null) {
                visitOverwrittenTemplateFile(templatePsiFile, gotoRelatedItems, sectionName, finalDepth, resolver);
            }
        }
    });

}
 
Example #18
Source File: AnnotationLightCodeInsightFixtureTestCase.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Override
public boolean match(@NotNull LineMarkerInfo markerInfo) {
    if(markerInfo.getLineMarkerTooltip() == null || !markerInfo.getLineMarkerTooltip().equals(toolTip)) {
        return false;
    }

    if(!(markerInfo instanceof RelatedItemLineMarkerInfo)) {
        return false;
    }

    for (Object o : ((RelatedItemLineMarkerInfo) markerInfo).createGotoRelatedItems()) {
        if(o instanceof GotoRelatedItem && this.pattern.accepts(((GotoRelatedItem) o).getElement())) {
            return true;
        }
    }

    return false;
}
 
Example #19
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public boolean match(@NotNull LineMarkerInfo markerInfo) {
    if(markerInfo.getLineMarkerTooltip() == null || !markerInfo.getLineMarkerTooltip().equals(toolTip)) {
        return false;
    }

    if(!(markerInfo instanceof RelatedItemLineMarkerInfo)) {
        return false;
    }

    for (Object o : ((RelatedItemLineMarkerInfo) markerInfo).createGotoRelatedItems()) {
        if(o instanceof GotoRelatedItem && this.pattern.accepts(((GotoRelatedItem) o).getElement())) {
            return true;
        }
    }

    return false;
}
 
Example #20
Source File: TemplateLineMarker.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
/**
 * Support: @push('foobar')
 */
@NotNull
private Collection<LineMarkerInfo> collectPushOverwrites(@NotNull LeafPsiElement psiElement, @NotNull String sectionName) {
    final List<GotoRelatedItem> gotoRelatedItems = new ArrayList<>();

    BladeTemplateUtil.visitUpPath(psiElement.getContainingFile(), 10, parameter -> {
        if(sectionName.equalsIgnoreCase(parameter.getContent())) {
            gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(parameter.getPsiElement()).withIcon(LaravelIcons.LARAVEL, LaravelIcons.LARAVEL));
        }
    }, BladeTokenTypes.STACK_DIRECTIVE);

    if(gotoRelatedItems.size() == 0) {
        return Collections.emptyList();
    }

    return Collections.singletonList(
        getRelatedPopover("Stack Section", "Stack Overwrites", psiElement, gotoRelatedItems, PhpIcons.OVERRIDES)
    );
}
 
Example #21
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 #22
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
private LineMarkerInfo attachOverwrites(@NotNull TwigFile twigFile) {
    Collection<PsiFile> targets = new ArrayList<>();

    for (String templateName: TwigUtil.getTemplateNamesForFile(twigFile)) {
        for (PsiFile psiFile : TwigUtil.getTemplatePsiElements(twigFile.getProject(), templateName)) {
            if(!psiFile.getVirtualFile().equals(twigFile.getVirtualFile()) && !targets.contains(psiFile)) {
                targets.add(psiFile);
            }
        }
    }

    if(targets.size() == 0) {
        return null;
    }

    List<GotoRelatedItem> gotoRelatedItems = new ArrayList<>();
    for(PsiElement blockTag: targets) {
        gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(
            blockTag,
            TwigUtil.getPresentableTemplateName(blockTag, true)
        ).withIcon(TwigIcons.TwigFileIcon, Symfony2Icons.TWIG_LINE_OVERWRITE));
    }

    return getRelatedPopover("Overwrites", "Overwrite", twigFile, gotoRelatedItems, Symfony2Icons.TWIG_LINE_OVERWRITE);
}
 
Example #23
Source File: PhpGotoRelatedProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement psiElement) {

    if(!Symfony2ProjectComponent.isEnabled(psiElement)) {
        return Collections.emptyList();
    }

    if(psiElement.getLanguage() != PhpLanguage.INSTANCE) {
        return Collections.emptyList();
    }

    Method method = PsiTreeUtil.getParentOfType(psiElement, Method.class);
    if(method == null || !method.getName().endsWith("Action")) {
        return Collections.emptyList();
    }

    return ControllerMethodLineMarkerProvider.getGotoRelatedItems(method);
}
 
Example #24
Source File: LaravelLightCodeInsightFixtureTestCase.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
@Override
public boolean match(@NotNull LineMarkerInfo markerInfo) {
    if(markerInfo.getLineMarkerTooltip() == null || !markerInfo.getLineMarkerTooltip().equals(toolTip)) {
        return false;
    }

    if(!(markerInfo instanceof RelatedItemLineMarkerInfo)) {
        return false;
    }

    for (Object o : ((RelatedItemLineMarkerInfo) markerInfo).createGotoRelatedItems()) {
        if(o instanceof GotoRelatedItem && this.pattern.accepts(((GotoRelatedItem) o).getElement())) {
            return true;
        }
    }

    return false;
}
 
Example #25
Source File: SmartyTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
private void attachFileContextMaker(SmartyFile smartyFile, @NotNull Collection<LineMarkerInfo> lineMarkerInfos) {
    List<GotoRelatedItem> gotoRelatedItems = new ArrayList<>();

    attachController(smartyFile, gotoRelatedItems);
    attachInclude(smartyFile, gotoRelatedItems);
    attachExtends(smartyFile, gotoRelatedItems);

    if(gotoRelatedItems.size() == 0) {
        return;
    }

    // only one item dont need popover
    if(gotoRelatedItems.size() == 1) {
        lineMarkerInfos.add(RelatedPopupGotoLineMarker.getSingleLineMarker(smartyFile, lineMarkerInfos, gotoRelatedItems.get(0)));
        return;
    }

    lineMarkerInfos.add(getRelatedPopover("Related Files", "", smartyFile, gotoRelatedItems));

}
 
Example #26
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 #27
Source File: SmartyTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
public void attachExtends(final SmartyFile smartyFile, final List<GotoRelatedItem> gotoRelatedItems) {

        final String templateName = TemplateUtil.getTemplateName(smartyFile.getProject(), smartyFile.getVirtualFile());
        if(templateName == null) {
            return;
        }

        FileBasedIndexImpl.getInstance().getFilesWithKey(SmartyExtendsStubIndex.KEY, new HashSet<>(Collections.singletonList(templateName)), virtualFile -> {

            PsiFile psiFile = PsiManager.getInstance(smartyFile.getProject()).findFile(virtualFile);
            if(psiFile != null) {
                gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(psiFile, TemplateUtil.getTemplateName(psiFile.getProject(), psiFile.getVirtualFile())).withIcon(PhpIcons.IMPLEMENTED, PhpIcons.IMPLEMENTED));
            }

            return true;
        }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(smartyFile.getProject()), SmartyFileType.INSTANCE));

    }
 
Example #28
Source File: RelatedPopupGotoLineMarker.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
public static RelatedItemLineMarkerInfo<PsiElement> getSingleLineMarker(SmartyFile smartyFile, Collection<LineMarkerInfo> lineMarkerInfos, GotoRelatedItem gotoRelatedItem) {

        // hell: find any possible small icon
        Icon icon = null;
        if(gotoRelatedItem instanceof RelatedPopupGotoLineMarker.PopupGotoRelatedItem) {
            icon = ((RelatedPopupGotoLineMarker.PopupGotoRelatedItem) gotoRelatedItem).getSmallIcon();
        }

        if(icon == null) {
            icon = ShopwarePluginIcons.SHOPWARE_LINEMARKER;
        }

        NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(icon).
            setTargets(gotoRelatedItem.getElement());

        String customName = gotoRelatedItem.getCustomName();
        if(customName != null) {
            builder.setTooltipText(customName);
        }

        return builder.createLineMarkerInfo(smartyFile);
    }
 
Example #29
Source File: ShopwareLightCodeInsightFixtureTestCase.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
@Override
public boolean match(@NotNull LineMarkerInfo markerInfo) {
    if(markerInfo.getLineMarkerTooltip() == null || !markerInfo.getLineMarkerTooltip().equals(toolTip)) {
        return false;
    }

    if(!(markerInfo instanceof RelatedItemLineMarkerInfo)) {
        return false;
    }

    for (Object o : ((RelatedItemLineMarkerInfo) markerInfo).createGotoRelatedItems()) {
        if(o instanceof GotoRelatedItem && this.pattern.accepts(((GotoRelatedItem) o).getElement())) {
            return true;
        }
    }

    return false;
}
 
Example #30
Source File: DrupalLightCodeInsightFixtureTestCase.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
@Override
public boolean match(@NotNull LineMarkerInfo markerInfo) {
    if(markerInfo.getLineMarkerTooltip() == null || !markerInfo.getLineMarkerTooltip().equals(toolTip)) {
        return false;
    }

    if(!(markerInfo instanceof RelatedItemLineMarkerInfo)) {
        return false;
    }

    for (Object o : ((RelatedItemLineMarkerInfo) markerInfo).createGotoRelatedItems()) {
        if(o instanceof GotoRelatedItem && this.pattern.accepts(((GotoRelatedItem) o).getElement())) {
            return true;
        }
    }

    return false;
}