Search in sources :

Example 16 with StructureViewTreeElement

use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-plugins by JetBrains.

the class DartStructureViewElement method getChildrenBase.

@NotNull
@Override
public Collection<StructureViewTreeElement> getChildrenBase() {
    final NavigatablePsiElement element = getElement();
    final List<StructureViewTreeElement> result = new ArrayList<>();
    if (element instanceof DartFile || element instanceof DartEmbeddedContent) {
        THashSet<DartComponentName> componentNames = new THashSet<>();
        DartPsiCompositeElementImpl.processDeclarationsImpl(element, new ComponentNameScopeProcessor(componentNames), ResolveState.initial(), null);
        for (DartComponentName componentName : componentNames) {
            PsiElement parent = componentName.getParent();
            if (parent instanceof DartComponent) {
                result.add(new DartStructureViewElement((DartComponent) parent));
            }
        }
    } else if (element instanceof DartClass) {
        for (DartComponent subNamedComponent : DartResolveUtil.getNamedSubComponents((DartClass) element)) {
            result.add(new DartStructureViewElement(subNamedComponent));
        }
    }
    Collections.sort(result, (o1, o2) -> {
        PsiElement element1, element2;
        if (o1 instanceof DartStructureViewElement && o2 instanceof DartStructureViewElement && (element1 = ((DartStructureViewElement) o1).getElement()) != null && (element2 = ((DartStructureViewElement) o2).getElement()) != null) {
            return element1.getTextRange().getStartOffset() - element2.getTextRange().getStartOffset();
        }
        return 0;
    });
    return result;
}
Also used : THashSet(gnu.trove.THashSet) ComponentNameScopeProcessor(com.jetbrains.lang.dart.resolve.ComponentNameScopeProcessor) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with StructureViewTreeElement

use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.

the class StructureTreeBuilder method isAutoExpandNode.

@Override
protected final boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) {
    StructureViewModel model = myStructureModel;
    if (model instanceof TreeModelWrapper) {
        model = ((TreeModelWrapper) model).getModel();
    }
    if (model instanceof StructureViewModel.ExpandInfoProvider) {
        StructureViewModel.ExpandInfoProvider provider = (StructureViewModel.ExpandInfoProvider) model;
        Object element = nodeDescriptor.getElement();
        if (element instanceof StructureViewComponent.StructureViewTreeElementWrapper) {
            StructureViewComponent.StructureViewTreeElementWrapper wrapper = (StructureViewComponent.StructureViewTreeElementWrapper) element;
            if (wrapper.getValue() instanceof StructureViewTreeElement) {
                final StructureViewTreeElement value = (StructureViewTreeElement) wrapper.getValue();
                if (value != null) {
                    return provider.isAutoExpand(value);
                }
            }
        } else if (element instanceof GroupWrapper) {
            final Group group = ((GroupWrapper) element).getValue();
            for (TreeElement treeElement : group.getChildren()) {
                if (treeElement instanceof StructureViewTreeElement && !provider.isAutoExpand((StructureViewTreeElement) treeElement)) {
                    return false;
                }
            }
        }
    }
    // expand root node & its immediate children
    final NodeDescriptor parent = nodeDescriptor.getParentDescriptor();
    return super.isAutoExpandNode(parent == null ? nodeDescriptor : parent);
}
Also used : Group(com.intellij.ide.util.treeView.smartTree.Group) GroupWrapper(com.intellij.ide.util.treeView.smartTree.GroupWrapper) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement)

Example 18 with StructureViewTreeElement

use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.

the class JavaFileTreeElement method getChildrenBase.

@Override
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
    PsiClassOwner element = getElement();
    if (element == null)
        return Collections.emptyList();
    PsiClass[] classes = element.getClasses();
    ArrayList<StructureViewTreeElement> result = new ArrayList<>();
    for (PsiClass aClass : classes) {
        result.add(new JavaClassTreeElement(aClass, false, new HashSet<>()));
    }
    return result;
}
Also used : PsiClassOwner(com.intellij.psi.PsiClassOwner) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with StructureViewTreeElement

use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.

the class GroupByWordPrefixes method group.

@Override
@NotNull
public Collection<Group> group(@NotNull final AbstractTreeNode parent, @NotNull Collection<TreeElement> children) {
    List<Key> keys = new ArrayList<>();
    String parentPrefix;
    int parentPrefixLength;
    if (parent.getValue() instanceof PropertiesPrefixGroup) {
        parentPrefix = ((PropertiesPrefixGroup) parent.getValue()).getPrefix();
        parentPrefixLength = StringUtil.split(parentPrefix, mySeparator).size();
    } else {
        parentPrefix = "";
        parentPrefixLength = 0;
    }
    for (TreeElement element : children) {
        if (!(element instanceof StructureViewTreeElement)) {
            continue;
        }
        Object value = ((StructureViewTreeElement) element).getValue();
        if (!(value instanceof IProperty)) {
            continue;
        }
        final String text = ((IProperty) value).getUnescapedKey();
        if (text == null)
            continue;
        LOG.assertTrue(text.startsWith(parentPrefix) || text.startsWith(mySeparator));
        List<String> words = StringUtil.split(text, mySeparator);
        keys.add(new Key(words, element));
    }
    Collections.sort(keys, (k1, k2) -> {
        List<String> o1 = k1.words;
        List<String> o2 = k2.words;
        for (int i = 0; i < Math.max(o1.size(), o2.size()); i++) {
            if (i == o1.size())
                return 1;
            if (i == o2.size())
                return -1;
            String s1 = o1.get(i);
            String s2 = o2.get(i);
            int res = s1.compareTo(s2);
            if (res != 0)
                return res;
        }
        return 0;
    });
    List<Group> groups = new ArrayList<>();
    int groupStart = 0;
    for (int i = 0; i <= keys.size(); i++) {
        if (!isEndOfGroup(i, keys, parentPrefixLength)) {
            continue;
        }
        // find longest group prefix
        List<String> firstKey = groupStart == keys.size() ? Collections.<String>emptyList() : keys.get(groupStart).words;
        int prefixLen = firstKey.size();
        for (int j = groupStart + 1; j < i; j++) {
            List<String> prevKey = keys.get(j - 1).words;
            List<String> nextKey = keys.get(j).words;
            for (int k = parentPrefixLength; k < prefixLen; k++) {
                String word = k < nextKey.size() ? nextKey.get(k) : null;
                String wordInPrevKey = k < prevKey.size() ? prevKey.get(k) : null;
                if (!Comparing.strEqual(word, wordInPrevKey)) {
                    prefixLen = k;
                    break;
                }
            }
        }
        String[] strings = firstKey.subList(0, prefixLen).toArray(new String[prefixLen]);
        String prefix = StringUtil.join(strings, mySeparator);
        String presentableName = prefix.substring(parentPrefix.length());
        presentableName = StringUtil.trimStart(presentableName, mySeparator);
        if (i - groupStart > 1) {
            groups.add(new PropertiesPrefixGroup(children, prefix, presentableName, mySeparator));
        } else if (groupStart != keys.size()) {
            TreeElement node = keys.get(groupStart).node;
            if (node instanceof PropertiesStructureViewElement) {
                ((PropertiesStructureViewElement) node).setPresentableName(presentableName);
            } else {
                ((ResourceBundlePropertyStructureViewElement) node).setPresentableName(presentableName);
            }
        }
        groupStart = i;
    }
    return groups;
}
Also used : StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) IProperty(com.intellij.lang.properties.IProperty) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with StructureViewTreeElement

use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.

the class PropertiesFileStructureViewElement method getChildrenBase.

@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
    List<? extends IProperty> properties = getElement().getProperties();
    Collection<StructureViewTreeElement> elements = new ArrayList<>(properties.size());
    for (IProperty property : properties) {
        elements.add(new PropertiesStructureViewElement((Property) property));
    }
    return elements;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) ArrayList(java.util.ArrayList) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)25 NotNull (org.jetbrains.annotations.NotNull)16 PsiElement (com.intellij.psi.PsiElement)9 ArrayList (java.util.ArrayList)8 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)5 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 IProperty (com.intellij.lang.properties.IProperty)3 PsiFile (com.intellij.psi.PsiFile)3 XmlFile (com.intellij.psi.xml.XmlFile)3 ProjectListBuilder (com.intellij.ide.commander.ProjectListBuilder)2 TextRange (com.intellij.openapi.util.TextRange)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)2 CfmlFile (com.intellij.coldFusion.model.files.CfmlFile)1 CfmlFunction (com.intellij.coldFusion.model.psi.CfmlFunction)1 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)1 StructureView (com.intellij.ide.structureView.StructureView)1 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)1 StructureViewExtension (com.intellij.ide.structureView.StructureViewExtension)1 StructureViewFactoryEx (com.intellij.ide.structureView.StructureViewFactoryEx)1