Search in sources :

Example 21 with TreeElement

use of com.intellij.ide.util.treeView.smartTree.TreeElement 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 22 with TreeElement

use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-community by JetBrains.

the class JsonStructureViewTest method testSimpleStructure.

// Moved from JavaScript
public void testSimpleStructure() {
    myFixture.configureByFile("structureView/" + getTestName(false) + ".json");
    final StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(myFixture.getFile());
    assertNotNull(builder);
    StructureViewComponent component = null;
    try {
        final FileEditor editor = FileEditorManager.getInstance(getProject()).getSelectedEditor(myFixture.getFile().getVirtualFile());
        component = (StructureViewComponent) builder.createStructureView(editor, myFixture.getProject());
        final StructureViewModel model = component.getTreeModel();
        TreeElement[] children = model.getRoot().getChildren();
        assertEquals(2, children.length);
        assertEquals("aaa", children[0].getPresentation().getPresentableText());
        assertEquals(PlatformIcons.PROPERTY_ICON, children[0].getPresentation().getIcon(false));
        assertEquals("bbb", children[1].getPresentation().getPresentableText());
        assertEquals(AllIcons.Json.Property_braces, children[1].getPresentation().getIcon(false));
        children = children[1].getChildren();
        assertEquals(1, children.length);
        assertEquals("ccc", children[0].getPresentation().getPresentableText());
        assertEquals(PlatformIcons.PROPERTY_ICON, children[0].getPresentation().getIcon(false));
    } finally {
        if (component != null) {
            Disposer.dispose(component);
        }
    }
}
Also used : LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement)

Example 23 with TreeElement

use of com.intellij.ide.util.treeView.smartTree.TreeElement 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 24 with TreeElement

use of com.intellij.ide.util.treeView.smartTree.TreeElement 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)

Aggregations

TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)24 NotNull (org.jetbrains.annotations.NotNull)10 ArrayList (java.util.ArrayList)7 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)5 Pair (com.intellij.openapi.util.Pair)4 PsiElement (com.intellij.psi.PsiElement)4 Call (org.elixir_lang.psi.call.Call)4 Module (org.elixir_lang.structure_view.element.modular.Module)3 Module.addClausesToCallDefinition (org.elixir_lang.structure_view.element.modular.Module.addClausesToCallDefinition)3 Nullable (org.jetbrains.annotations.Nullable)3 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)2 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)2 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)2 LanguageStructureViewBuilder (com.intellij.lang.LanguageStructureViewBuilder)2 IProperty (com.intellij.lang.properties.IProperty)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 ElixirPsiImplUtil.enclosingMacroCall (org.elixir_lang.psi.impl.ElixirPsiImplUtil.enclosingMacroCall)2 Contract (org.jetbrains.annotations.Contract)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1