Search in sources :

Example 21 with StructureViewTreeElement

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

the class PropertiesPrefixGroup method getChildren.

@NotNull
public Collection<TreeElement> getChildren() {
    Collection<TreeElement> result = new ArrayList<>();
    List<String> prefixWords = StringUtil.split(myPrefix, mySeparator);
    for (TreeElement treeElement : myProperties) {
        if (!(treeElement instanceof StructureViewTreeElement)) {
            continue;
        }
        Object value = ((StructureViewTreeElement) treeElement).getValue();
        if (!(value instanceof IProperty)) {
            continue;
        }
        final String key = ((IProperty) value).getUnescapedKey();
        if (key == null) {
            continue;
        }
        boolean startsWith;
        if (!key.equals(myPrefix)) {
            List<String> keyWords = StringUtil.split(key, mySeparator);
            startsWith = prefixWords.size() < keyWords.size();
            if (startsWith) {
                for (int i = 0; i < prefixWords.size(); i++) {
                    String prefixWord = prefixWords.get(i);
                    String keyWord = keyWords.get(i);
                    if (!Comparing.strEqual(keyWord, prefixWord)) {
                        startsWith = false;
                        break;
                    }
                }
            }
        } else {
            startsWith = true;
        }
        if (startsWith) {
            result.add(treeElement);
            String presentableName = key.substring(myPrefix.length());
            presentableName = StringUtil.trimStart(presentableName, mySeparator);
            if (treeElement instanceof PropertiesStructureViewElement) {
                ((PropertiesStructureViewElement) treeElement).setPresentableName(presentableName);
            }
            if (treeElement instanceof ResourceBundlePropertyStructureViewElement) {
                ((ResourceBundlePropertyStructureViewElement) treeElement).setPresentableName(presentableName);
            }
        }
    }
    return result;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) ArrayList(java.util.ArrayList) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) ResourceBundlePropertyStructureViewElement(com.intellij.lang.properties.editor.ResourceBundlePropertyStructureViewElement) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with StructureViewTreeElement

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

the class GotoClassAction method findMember.

@Nullable
private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
    final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
    final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
    final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
    if (builder == null || editors.length == 0) {
        return null;
    }
    final StructureView view = builder.createStructureView(editors[0], psiElement.getProject());
    try {
        final StructureViewTreeElement element = findElement(view.getTreeModel().getRoot(), psiElement, 4);
        if (element == null) {
            return null;
        }
        final MinusculeMatcher matcher = NameUtil.buildMatcher(pattern).build();
        int max = Integer.MIN_VALUE;
        Object target = null;
        for (TreeElement treeElement : element.getChildren()) {
            if (treeElement instanceof StructureViewTreeElement) {
                String presentableText = treeElement.getPresentation().getPresentableText();
                if (presentableText != null) {
                    final int degree = matcher.matchingDegree(presentableText);
                    if (degree > max) {
                        max = degree;
                        target = ((StructureViewTreeElement) treeElement).getValue();
                    }
                }
            }
        }
        return target instanceof Navigatable ? (Navigatable) target : null;
    } finally {
        Disposer.dispose(view);
    }
}
Also used : PsiStructureViewFactory(com.intellij.lang.PsiStructureViewFactory) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureView(com.intellij.ide.structureView.StructureView) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with StructureViewTreeElement

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

the class RestStructureViewElement method getChildren.

@NotNull
public StructureViewTreeElement[] getChildren() {
    final Set<RestElement> childrenElements = new LinkedHashSet<>();
    myElement.acceptChildren(new PsiElementVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof RestTitle && ((RestTitle) element).getName() != null)
                childrenElements.add((RestElement) element);
            else
                element.acceptChildren(this);
        }
    });
    StructureViewTreeElement[] children = new StructureViewTreeElement[childrenElements.size()];
    int i = 0;
    for (RestElement element : childrenElements) {
        children[i] = new RestStructureViewElement(element);
        i += 1;
    }
    return children;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RestElement(com.jetbrains.rest.psi.RestElement) RestTitle(com.jetbrains.rest.psi.RestTitle) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with StructureViewTreeElement

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

the class XmlFileTreeElement method getChildrenBase.

@Override
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
    final XmlDocument document = getElement().getDocument();
    List<XmlTag> rootTags = new ArrayList<>();
    if (document != null) {
        for (PsiElement element : document.getChildren()) if (element instanceof XmlTag)
            rootTags.add((XmlTag) element);
    }
    Collection<StructureViewTreeElement> structureViewTreeElements = getStructureViewTreeElements(rootTags.toArray(new XmlTag[rootTags.size()]));
    Collection<StructureViewTreeElement> dtdStructureViewTreeElements = null;
    final XmlProlog prolog = document != null ? document.getProlog() : null;
    if (prolog != null) {
        final XmlDoctype doctype = prolog.getDoctype();
        if (doctype != null) {
            final XmlMarkupDecl xmlMarkupDecl = doctype.getMarkupDecl();
            if (xmlMarkupDecl != null) {
                dtdStructureViewTreeElements = DtdFileTreeElement.collectElements(xmlMarkupDecl);
            }
        }
    }
    if (dtdStructureViewTreeElements != null) {
        final ArrayList<StructureViewTreeElement> result = new ArrayList<>(dtdStructureViewTreeElements.size() + structureViewTreeElements.size());
        result.addAll(dtdStructureViewTreeElements);
        result.addAll(structureViewTreeElements);
        structureViewTreeElements = result;
    }
    return structureViewTreeElements;
}
Also used : ArrayList(java.util.ArrayList) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with StructureViewTreeElement

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

the class PyStructureViewElement method getChildren.

@NotNull
public StructureViewTreeElement[] getChildren() {
    final PyElement element = getValue();
    if (element == null) {
        return EMPTY_ARRAY;
    }
    final Collection<StructureViewTreeElement> children = new ArrayList<>();
    for (PyElement e : getElementChildren(element)) {
        children.add(createChild(e, getElementVisibility(e), false, elementIsField(e)));
    }
    PyPsiUtils.assertValid(element);
    if (element instanceof PyClass) {
        for (PyClass c : ((PyClass) element).getAncestorClasses(null)) {
            for (PyElement e : getElementChildren(c)) {
                final StructureViewTreeElement inherited = createChild(e, getElementVisibility(e), true, elementIsField(e));
                if (!children.contains(inherited)) {
                    children.add(inherited);
                }
            }
        }
    }
    return children.toArray(new StructureViewTreeElement[children.size()]);
}
Also used : StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) 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