com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo Java Examples

The following examples show how to use com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
Source File: FileResourceUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
public static RelatedItemLineMarkerInfo<PsiElement> getFileImplementsLineMarker(@NotNull PsiFile psiFile) {
    final Project project = psiFile.getProject();

    VirtualFile virtualFile = psiFile.getVirtualFile();
    if(virtualFile == null) {
        return null;
    }

    String bundleLocateName = FileResourceUtil.getBundleLocateName(project, virtualFile);
    if(bundleLocateName == null) {
        return null;
    }

    if(FileResourceUtil.getFileResourceRefers(project, bundleLocateName).size() == 0) {
        return null;
    }

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(PhpIcons.IMPLEMENTS).
        setTargets(new FileResourceUtil.FileResourceNotNullLazyValue(project, bundleLocateName)).
        setTooltipText("Navigate to resource");

    return builder.createLineMarkerInfo(psiFile);
}
 
Example #7
Source File: YamlLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> lineMarkerInfos) {
    if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) {
        return;
    }

    for(PsiElement psiElement : psiElements) {
        attachRouteActions(lineMarkerInfos, psiElement);
        attachEntityClass(lineMarkerInfos, psiElement);
        attachRelationClass(lineMarkerInfos, psiElement);

        if(psiElement instanceof YAMLFile) {
            RelatedItemLineMarkerInfo<PsiElement> lineMarker = FileResourceUtil.getFileImplementsLineMarker((PsiFile) psiElement);
            if(lineMarker != null) {
                lineMarkerInfos.add(lineMarker);
            }
        }
    }
}
 
Example #8
Source File: XmlLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> lineMarkerInfos) {
    if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) {
        return;
    }

    for(PsiElement psiElement: psiElements) {
        if(XmlHelper.getXmlTagNameLeafStartPattern().accepts(psiElement)) {
            attachRouteActions(psiElement, lineMarkerInfos);
        } else if(psiElement instanceof XmlFile) {
            RelatedItemLineMarkerInfo<PsiElement> lineMarker = FileResourceUtil.getFileImplementsLineMarker((PsiFile) psiElement);
            if(lineMarker != null) {
                lineMarkerInfos.add(lineMarker);
            }
        }
    }

}
 
Example #9
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;
}
 
Example #10
Source File: HaskellLineMarkerProvider.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element,
                        Collection<? super RelatedItemLineMarkerInfo> result) {
    if (false && element instanceof PsiNamedElement) {
        PsiNamedElement namedElement = (PsiNamedElement) element;
        String value = namedElement.getName();
        if (value != null) {
            Project project = element.getProject();
            final List<HaskellUtil.FoundDefinition> found =
                    HaskellUtil.findDefinitionNode(project, value, namedElement);
            final List<PsiNamedElement> namedNodes = ContainerUtil.newArrayList();
            for (HaskellUtil.FoundDefinition fd : found) {
                namedNodes.add(fd.element);
            }

            if (namedNodes.size() > 0) {
                NavigationGutterIconBuilder<PsiElement> builder =
                        NavigationGutterIconBuilder.create(HaskellIcons.FILE).
                                setTargets(namedNodes).
                                setTooltipText("Navigate to element definition");
                result.add(builder.createLineMarkerInfo(element));
            }
        }
    }
}
 
Example #11
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 #12
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 #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: ClassLineMarkerProvider.java    From phpstorm-plugin with MIT License 6 votes vote down vote up
private void classNameMarker(PhpClass currentClass, Collection<? super RelatedItemLineMarkerInfo> result, Project project) {
    Collection<PhpClass> target;
    String tooltip;

    if (Utils.isClassAtoumTest(currentClass)) {
        target = Utils.locateTestedClasses(project, currentClass);
        tooltip = "Navigate to tested class";
    } else {
        target = Utils.locateTestClasses(project, currentClass);
        tooltip = "Navigate to test";
    }

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

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Icons.ATOUM).
            setTargets(target).
            setTooltipText(tooltip);
    result.add(builder.createLineMarkerInfo(currentClass));
}
 
Example #15
Source File: TemplateLineMarkerProvider.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {
    if (!PlatformPatterns.psiElement(FluidFile.class).accepts(element)) {
        return;
    }

    Collection<Method> possibleMethodTargetsForControllerAction = FluidUtil.findPossibleMethodTargetsForControllerAction(
        element.getProject(),
        FluidUtil.inferControllerNameFromTemplateFile((FluidFile) element),
        FluidUtil.inferActionNameFromTemplateFile((FluidFile) element)
    );

    if (possibleMethodTargetsForControllerAction.size() > 0) {
        result.add(
            NavigationGutterIconBuilder
                .create(PhpIcons.METHOD)
                .setTargets(possibleMethodTargetsForControllerAction)
                .setTooltipText("Navigate to controller action")
                .createLineMarkerInfo(element)
        );
    }
}
 
Example #16
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 #17
Source File: ControllerLineMarkerProvider.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {
    if (!PlatformPatterns.psiElement(PhpTokenTypes.IDENTIFIER).withParent(PlatformPatterns.psiElement(Method.class).withName(PlatformPatterns.string().endsWith("Action"))).accepts(element)) {
        return;
    }

    Collection<FluidFile> possibleMatchedTemplates = FluidUtil.findTemplatesForControllerAction((Method) element.getParent());
    if (possibleMatchedTemplates.size() > 0) {
        result.add(
            NavigationGutterIconBuilder
                .create(FluidIcons.TEMPLATE_LINE_MARKER)
                .setTargets(possibleMatchedTemplates)
                .setTooltipText("Navigate to template")
                .createLineMarkerInfo(element)
        );
    }
}
 
Example #18
Source File: MethodLineMarkerProvider.java    From intellij-neos with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
    for (PsiElement el : elements) {
        if (el instanceof Method && ((Method) el).getAccess().isPublic()) {
            VirtualFile template = ResolveEngine.findTemplate((Method) el);
            if (template != null) {
                PsiFile target = PsiManager.getInstance(el.getProject()).findFile(template);
                RelatedItemLineMarkerInfo info = NavigationGutterIconBuilder
                        .create(NeosIcons.NODE_TYPE)
                        .setTarget(target)
                        .setTooltipText("Go to template")
                        .createLineMarkerInfo(el);
                result.add(info);
            }
        }
    }
}
 
Example #19
Source File: NodeTypeLineMarkerProvider.java    From intellij-neos with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
    for (PsiElement el : elements) {
        if (!(el instanceof FusionType)
                || !(el.getParent() instanceof FusionPrototypeSignature)
                || (((FusionPrototypeSignature) el.getParent()).isInheritedInDefinition())
                || (el.getParent().getParent().getParent() instanceof FusionPropertyDeletion)) {
            continue;
        }

        FusionType type = (FusionType) el;
        Collection<PsiElement> targets = ResolveEngine.getNodeTypeDefinitions(el.getProject(), type);
        if (!targets.isEmpty()) {
            RelatedItemLineMarkerInfo info = NavigationGutterIconBuilder
                    .create(NeosIcons.NODE_TYPE)
                    .setTargets(targets)
                    .setTooltipText("Go to node type definition")
                    .createLineMarkerInfo(el);
            result.add(info);
        }
    }
}
 
Example #20
Source File: FileResourceUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * On route annotations we can have folder scope so: "@FooBundle/Controller/foo.php" can be equal "@FooBundle/Controller/"
 */
@Nullable
public static RelatedItemLineMarkerInfo<PsiElement> getFileImplementsLineMarkerInFolderScope(@NotNull PsiFile psiFile) {
    VirtualFile virtualFile = psiFile.getVirtualFile();
    if(virtualFile == null) {
        return null;
    }

    final Project project = psiFile.getProject();
    String bundleLocateName = FileResourceUtil.getBundleLocateName(project, virtualFile);
    if(bundleLocateName == null) {
        return null;
    }

    Set<String> names = new HashSet<>();
    names.add(bundleLocateName);

    // strip filename
    int i = bundleLocateName.lastIndexOf("/");
    if(i > 0) {
        names.add(bundleLocateName.substring(0, i));
    }

    int targets = 0;
    for (String name : names) {
        targets += FileResourceUtil.getFileResourceRefers(project, name).size();
    }

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

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(PhpIcons.IMPLEMENTS).
        setTargets(new FileResourceUtil.FileResourceNotNullLazyValue(project, names)).
        setTooltipText("Navigate to resource");

    return builder.createLineMarkerInfo(psiFile);
}
 
Example #21
Source File: ServiceUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * Provides a lazy linemarker based on the given id eg for "decorated" or "parent" services:
 *
 * <service id="foo_bar_main" decorates="app.mailer"/>
 */
@NotNull
public static RelatedItemLineMarkerInfo<PsiElement> getLineMarkerForDecoratesServiceId(@NotNull PsiElement psiElement, @NotNull ServiceLineMarker lineMarker, @NotNull String foreignId) {
    return NavigationGutterIconBuilder.create(PhpIcons.OVERRIDEN)
        .setTargets(ServiceIndexUtil.getServiceIdDefinitionLazyValue(psiElement.getProject(), Collections.singletonList(foreignId)))
        .setTooltipText(lineMarker == ServiceLineMarker.DECORATE ? "Navigate to decorated service" : "Navigate to parent service")
        .createLineMarkerInfo(psiElement);
}
 
Example #22
Source File: ServiceLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void formNameMarker(PsiElement psiElement, Collection<? super RelatedItemLineMarkerInfo> result) {

        if(!(psiElement instanceof StringLiteralExpression)) {
            return;
        }

        Method method = PsiTreeUtil.getParentOfType(psiElement, Method.class);
        if(method == null) {
            return;
        }

        if(PhpElementsUtil.isMethodInstanceOf(method, "\\Symfony\\Component\\Form\\FormTypeInterface", "getParent")) {
            // get form string; on blank string we dont need any further action

            String contents = ((StringLiteralExpression) psiElement).getContents();
            if(StringUtils.isBlank(contents)) {
                return;
            }

            PsiElement formPsiTarget = FormUtil.getFormTypeToClass(psiElement.getProject(), contents);
            if(formPsiTarget != null) {
                NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.FORM_TYPE_LINE_MARKER).
                    setTargets(formPsiTarget).
                    setTooltipText("Navigate to form type");

                result.add(builder.createLineMarkerInfo(psiElement));
            }

        }

    }
 
Example #23
Source File: ServiceLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void repositoryClassMarker(PsiElement psiElement, Collection<? super RelatedItemLineMarkerInfo> result) {

        PsiElement phpClassContext = psiElement.getContext();
        if(!(phpClassContext instanceof PhpClass)) {
            return;
        }

        Collection<PsiFile> psiFiles = new ArrayList<>();
        for (VirtualFile virtualFile : DoctrineMetadataUtil.findMetadataForRepositoryClass((PhpClass) phpClassContext)) {
            PsiFile file = PsiManager.getInstance(psiElement.getProject()).findFile(virtualFile);
            if(file == null) {
                continue;
            }

            psiFiles.add(file);
        }

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

        NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.DOCTRINE_LINE_MARKER).
            setTargets(psiFiles).
            setTooltipText("Navigate to metadata");

        result.add(builder.createLineMarkerInfo(psiElement));
    }
 
Example #24
Source File: ServiceLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void entityClassMarker(PsiElement psiElement, Collection<? super RelatedItemLineMarkerInfo> result) {

        PsiElement phpClassContext = psiElement.getContext();
        if(!(phpClassContext instanceof PhpClass)) {
            return;
        }

        Collection<PsiFile> psiFiles = new ArrayList<>();
        // @TODO: use DoctrineMetadataUtil, for single resolve; we have collecting overhead here
        for(DoctrineModel doctrineModel: EntityHelper.getModelClasses(psiElement.getProject())) {
            PhpClass phpClass = doctrineModel.getPhpClass();
            if(!PhpElementsUtil.isEqualClassName(phpClass, (PhpClass) phpClassContext)) {
                continue;
            }

            PsiFile psiFile = EntityHelper.getModelConfigFile(phpClass);

            // prevent self navigation for line marker
            if(psiFile == null || psiFile instanceof PhpFile) {
                continue;
            }

            psiFiles.add(psiFile);
        }

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

        NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.DOCTRINE_LINE_MARKER).
            setTargets(psiFiles).
            setTooltipText("Navigate to model");

        result.add(builder.createLineMarkerInfo(psiElement));
    }
 
Example #25
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 #26
Source File: PrototypeLineMarkerProvider.java    From intellij-neos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
    for (PsiElement el : elements) {
        if (!NeosProjectService.isEnabled(el)) {
            return;
        }

        if (!el.getContainingFile().getVirtualFile().getName().startsWith("NodeTypes.")) {
            continue;
        }

        if (!(el instanceof YAMLKeyValue)) {
            continue;
        }

        YAMLMapping parentMapping = ((YAMLKeyValue) el).getParentMapping();
        if (parentMapping != null && parentMapping.getParent() instanceof YAMLDocument) {
            String nodeType = ((YAMLKeyValue) el).getKeyText();
            String[] nodeTypeSplit = nodeType.split(":");

            if (nodeTypeSplit.length < 2) {
                continue;
            }

            List<PsiElement> targets = ResolveEngine.getPrototypeDefinitions(el.getProject(), nodeTypeSplit[1], nodeTypeSplit[0]);
            if (!targets.isEmpty()) {
                RelatedItemLineMarkerInfo info = NavigationGutterIconBuilder
                        .create(FusionIcons.PROTOTYPE)
                        .setTargets(targets)
                        .setTooltipText("Go to Fusion prototype")
                        .createLineMarkerInfo(el);
                result.add(info);
            }
        }
    }
}
 
Example #27
Source File: RouteLineMarkerProvider.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {
    if (!TYPO3CMSProjectSettings.isEnabled(element)) {
        return;
    }

    if (!getPositionPattern().accepts(element)) {
        return;
    }

    StringLiteralExpression literalExpression = (StringLiteralExpression) element.getParent();
    String value = literalExpression.getContents();

    if (value.isEmpty()) {
        return;
    }

    PsiElement methodReference = PsiTreeUtil.getParentOfType(element, MethodReference.class);
    if (PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "getAjaxUrl") || PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "buildUriFromRoute")) {

        if (RouteIndex.hasRoute(element.getProject(), value)) {
            Collection<RouteStub> routes = RouteIndex.getRoute(element.getProject(), value);
            routes.forEach(def -> {
                PsiElement[] routeDefinitionElements = RouteHelper.getRouteDefinitionElements(element.getProject(), value);
                NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder
                    .create(TYPO3CMSIcons.ROUTE_ICON)
                    .setTargets(routeDefinitionElements);

                if (def.getPath() != null) {
                    builder.setTooltipTitle("Path: " + def.getPath());
                }

                result.add(builder.createLineMarkerInfo(element));
            });

        }
    }
}
 
Example #28
Source File: GutterTestUtil.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
static List<GotoRelatedItem> getGutterNavigationDestinationElements(LineMarkerInfo.LineMarkerGutterIconRenderer gutter) {
    LineMarkerProvider lineMarkerProvider1 = LineMarkersPass.getMarkerProviders(JavaLanguage.INSTANCE, gutter
        .getLineMarkerInfo()
        .getElement().getProject())
        .stream()
        .filter(lineMarkerProvider -> lineMarkerProvider instanceof CamelRouteLineMarkerProvider).findAny()
        .get();
    List<RelatedItemLineMarkerInfo> result = new ArrayList<>();
    ((CamelRouteLineMarkerProvider) lineMarkerProvider1).collectNavigationMarkers(gutter.getLineMarkerInfo().getElement(), result);
    return (List<GotoRelatedItem>) result.get(0).createGotoRelatedItems();
}
 
Example #29
Source File: BeanInjectLineMarkerProviderTest.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void testBeanInjectGutter() {
    myFixture.configureByFiles("TestClass1.java", "TestClass2.java", "TestClass3.java", "beans.xml");

    List<RelatedItemLineMarkerInfo<? extends PsiElement>> beanInjectMarkers = findBeanInjectMarkers();
    assertEquals(4, beanInjectMarkers.size());

    validateBeanInjectWithValue(beanInjectMarkers.get(0));
    validateBeanInjectWithMultipleTargets(beanInjectMarkers.get(1));
    validateBeanInjectWithMultipleTargets(beanInjectMarkers.get(2));
    assertEquals(0, beanInjectMarkers.get(3).createGotoRelatedItems().size());
}
 
Example #30
Source File: BeanInjectLineMarkerProviderTest.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
private List<String> getTargetBeanNames(RelatedItemLineMarkerInfo<? extends PsiElement> marker) {
    return marker.createGotoRelatedItems().stream()
            .map(GotoRelatedItem::getElement)
            .map(element -> element instanceof ReferenceableIdPsiElement ? element.getNavigationElement() : element)
            .filter(Objects::nonNull)
            .map(element -> StringUtil.unquoteString(element.getText()))
            .collect(Collectors.toList());

}