Search in sources :

Example 1 with PerlItemPresentationBase

use of com.perl5.lang.perl.idea.presentations.PerlItemPresentationBase in project Perl5-IDEA by Camelcade.

the class PerlLightTestCase method serializeTree.

private void serializeTree(@NotNull StructureViewTreeElement currentElement, @NotNull StructureViewModel structureViewModel, @NotNull StringBuilder sb, @Nullable Collection<Pair<Grouper, Group>> groups, @NotNull String prefix, @NotNull Set<Object> recursionSet) {
    Object value = currentElement.getValue();
    ItemPresentation presentation = currentElement.getPresentation();
    assertNotNull(presentation);
    String locationString = presentation.getLocationString();
    sb.append(prefix).append(presentation.getPresentableText()).append(" in ").append(locationString == null ? null : locationString.replaceAll("\\\\", "/")).append("; ").append(getIconText(presentation.getIcon(true)));
    if (presentation instanceof PerlItemPresentationBase) {
        sb.append("; ").append(((PerlItemPresentationBase) presentation).getTextAttributesKey());
    }
    if (value instanceof PsiElement) {
        sb.append(" -> ").append(serializePsiElement((PsiElement) value));
    }
    sb.append("\n");
    // filters
    if (structureViewModel.getFilters().length > 0) {
        List<String> passedFilters = new ArrayList<>();
        for (Filter filter : structureViewModel.getFilters()) {
            if (filter.isVisible(currentElement)) {
                passedFilters.add(filter.getName());
            }
        }
        if (!passedFilters.isEmpty()) {
            sb.append(prefix).append("Passed by filters: ").append(StringUtil.join(passedFilters, ", ")).append("\n");
        }
    }
    // groups
    if (groups != null) {
        for (Pair<Grouper, Group> groupPair : groups) {
            Grouper grouper = groupPair.first;
            Group group = groupPair.second;
            ItemPresentation groupPresentation = group.getPresentation();
            sb.append(prefix).append("Grouped by: '").append(grouper.getPresentation().getText()).append("' (").append(grouper.getName()).append(") to ").append(groupPresentation.getPresentableText()).append(" in ").append(groupPresentation.getLocationString()).append("\n");
        }
    }
    if (recursionSet.add(value)) {
        sb.append("\n");
        TreeElement[] children = currentElement.getChildren();
        MultiMap<TreeElement, Pair<Grouper, Group>> groupingResults = new MultiMap<>();
        for (Grouper grouper : structureViewModel.getGroupers()) {
            for (Group group : grouper.group(new TreeElementWrapper(getProject(), currentElement, structureViewModel), Arrays.asList(children))) {
                for (TreeElement element : group.getChildren()) {
                    groupingResults.putValue(element, Pair.create(grouper, group));
                }
            }
        }
        for (TreeElement childElement : children) {
            assertInstanceOf(childElement, StructureViewTreeElement.class);
            serializeTree((StructureViewTreeElement) childElement, structureViewModel, sb, groupingResults.get(childElement), prefix + "  ", new THashSet<>(recursionSet));
        }
    } else {
        sb.append("(recursion)").append("\n\n");
    }
}
Also used : ItemPresentation(com.intellij.navigation.ItemPresentation) PerlItemPresentationBase(com.perl5.lang.perl.idea.presentations.PerlItemPresentationBase) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) MultiMap(com.intellij.util.containers.MultiMap) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter) Pair(com.intellij.openapi.util.Pair)

Example 2 with PerlItemPresentationBase

use of com.perl5.lang.perl.idea.presentations.PerlItemPresentationBase in project Perl5-IDEA by Camelcade.

the class PerlStructureViewElement method getPresentation.

@NotNull
@Override
public ItemPresentation getPresentation() {
    ItemPresentation itemPresentation = createPresentation();
    if ((isInherited() || isImported()) && itemPresentation instanceof PerlItemPresentationBase) {
        if (getValue() instanceof PerlDeprecatable && ((PerlDeprecatable) getValue()).isDeprecated()) {
            ((PerlItemPresentationBase) itemPresentation).setAttributesKey(PerlSyntaxHighlighter.UNUSED_DEPRECATED);
        } else {
            ((PerlItemPresentationBase) itemPresentation).setAttributesKey(CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
        }
    }
    if (isImported() && itemPresentation instanceof PerlItemPresentationSimple) {
        PerlExportDescriptor exportDescriptor = getExportDescriptor();
        assert exportDescriptor != null;
        ((PerlItemPresentationSimple) itemPresentation).setPresentableText(exportDescriptor.getImportedName());
    }
    return itemPresentation;
}
Also used : PerlItemPresentationSimple(com.perl5.lang.perl.idea.presentations.PerlItemPresentationSimple) PerlExportDescriptor(com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor) ItemPresentation(com.intellij.navigation.ItemPresentation) PerlItemPresentationBase(com.perl5.lang.perl.idea.presentations.PerlItemPresentationBase) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ItemPresentation (com.intellij.navigation.ItemPresentation)2 PerlItemPresentationBase (com.perl5.lang.perl.idea.presentations.PerlItemPresentationBase)2 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 Pair (com.intellij.openapi.util.Pair)1 VirtualFileFilter (com.intellij.openapi.vfs.VirtualFileFilter)1 MultiMap (com.intellij.util.containers.MultiMap)1 PerlExportDescriptor (com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor)1 PerlItemPresentationSimple (com.perl5.lang.perl.idea.presentations.PerlItemPresentationSimple)1 NotNull (org.jetbrains.annotations.NotNull)1