Java Code Examples for com.intellij.codeInsight.navigation.NavigationGutterIconBuilder#createLineMarkerInfo()

The following examples show how to use com.intellij.codeInsight.navigation.NavigationGutterIconBuilder#createLineMarkerInfo() . 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: 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 2
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 3
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
private LineMarkerInfo attachIncludes(@NotNull TwigFile twigFile) {
    Collection<String> templateNames = TwigUtil.getTemplateNamesForFile(twigFile);

    boolean found = false;
    for(String templateName: templateNames) {
        Project project = twigFile.getProject();

        Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance().getContainingFiles(
            TwigIncludeStubIndex.KEY, templateName, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), TwigFileType.INSTANCE)
        );

        // stop on first target, we load them lazily afterwards
        if(containingFiles.size() > 0) {
            found = true;
            break;
        }
    }

    if(!found) {
        return null;
    }

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(PhpIcons.IMPLEMENTED)
        .setTargets(new MyTemplateIncludeLazyValue(twigFile, templateNames))
        .setTooltipText("Navigate to includes")
        .setCellRenderer(new MyFileReferencePsiElementListCellRenderer());

    return builder.createLineMarkerInfo(twigFile);
}
 
Example 4
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
private LineMarkerInfo attachExtends(@NotNull TwigFile twigFile) {
    Collection<String> templateNames = TwigUtil.getTemplateNamesForFile(twigFile);

    boolean found = false;
    for(String templateName: templateNames) {
        Project project = twigFile.getProject();

        Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance().getContainingFiles(
            TwigExtendsStubIndex.KEY, templateName, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), TwigFileType.INSTANCE)
        );

        // stop on first target, we load them lazily afterwards
        if(containingFiles.size() > 0) {
            found = true;
            break;
        }
    }

    if(!found) {
        return null;
    }

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(PhpIcons.IMPLEMENTED)
        .setTargets(new TemplateExtendsLazyTargets(twigFile.getProject(), twigFile.getVirtualFile()))
        .setTooltipText("Navigate to extends")
        .setCellRenderer(new MyFileReferencePsiElementListCellRenderer());

    return builder.createLineMarkerInfo(twigFile);
}
 
Example 5
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
private LineMarkerInfo attachBlockImplements(@NotNull PsiElement psiElement, @NotNull FileImplementsLazyLoader implementsLazyLoader) {
    if(!TwigBlockUtil.hasBlockImplementations(psiElement, implementsLazyLoader)) {
        return null;
    }

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(PhpIcons.IMPLEMENTED)
        .setTargets(new BlockImplementationLazyValue(psiElement))
        .setTooltipText("Implementations")
        .setCellRenderer(new MyBlockListCellRenderer());

    return builder.createLineMarkerInfo(psiElement);
}
 
Example 6
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
private LineMarkerInfo attachBlockOverwrites(@NotNull PsiElement psiElement, @NotNull FileOverwritesLazyLoader loader) {
    if(!TwigBlockUtil.hasBlockOverwrites(psiElement, loader)) {
        return null;
    }

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(PhpIcons.OVERRIDES)
        .setTargets(new BlockOverwriteLazyValue(psiElement))
        .setTooltipText("Overwrites")
        .setCellRenderer(new MyBlockListCellRenderer());

    return builder.createLineMarkerInfo(psiElement);
}
 
Example 7
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 8
Source File: ControllerMethodLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Nullable
public LineMarkerInfo collect(PsiElement psiElement) {
    if(!Symfony2ProjectComponent.isEnabled(psiElement) || psiElement.getNode().getElementType() != PhpTokenTypes.IDENTIFIER) {
        return null;
    }

    PsiElement method = psiElement.getParent();
    if(!(method instanceof Method) || !((Method) method).getAccess().isPublic()) {
        return null;
    }

    List<GotoRelatedItem> gotoRelatedItems = getGotoRelatedItems((Method) method);

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

    // only one item dont need popover
    if(gotoRelatedItems.size() == 1) {

        GotoRelatedItem gotoRelatedItem = gotoRelatedItems.get(0);

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

        if(icon == null) {
           icon = Symfony2Icons.SYMFONY_LINE_MARKER;
        }

        NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(icon).
            setTargets(gotoRelatedItems.get(0).getElement());

        String customName = gotoRelatedItems.get(0).getCustomName();
        if(customName != null) {
            builder.setTooltipText(customName);
        }

        return builder.createLineMarkerInfo(psiElement);
    }

    return new LineMarkerInfo<>(
        psiElement,
        psiElement.getTextRange(),
        Symfony2Icons.SYMFONY_LINE_MARKER,
        6,
        new ConstantFunction<>("Related Files"),
        new RelatedPopupGotoLineMarker.NavigationHandler(gotoRelatedItems),
        GutterIconRenderer.Alignment.RIGHT
    );
}