Search in sources :

Example 6 with TreeElement

use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-elixir by KronicDeth.

the class File method getChildren.

/*
     * Public Instance Methods
     */
@NotNull
@Override
public TreeElement[] getChildren() {
    Call[] calls = PsiTreeUtil.getChildrenOfType(navigationItem, Call.class);
    TreeElement[] children;
    if (calls != null) {
        List<TreeElement> treeElementList = new ArrayList<TreeElement>(calls.length);
        for (Call call : calls) {
            if (Implementation.is(call)) {
                treeElementList.add(new Implementation(call));
            } else if (Module.is(call)) {
                treeElementList.add(new Module(call));
            } else if (Protocol.is(call)) {
                treeElementList.add(new Protocol(call));
            } else if (Quote.is(call)) {
                treeElementList.add(new Quote(call));
            } else if (Unknown.is(call)) {
                // should always be last because it will match all macro calls
                treeElementList.add(new Unknown(call));
            }
        }
        children = treeElementList.toArray(new TreeElement[treeElementList.size()]);
    } else {
        children = new TreeElement[0];
    }
    return children;
}
Also used : Call(org.elixir_lang.psi.call.Call) Unknown(org.elixir_lang.structure_view.element.modular.Unknown) ArrayList(java.util.ArrayList) Module(org.elixir_lang.structure_view.element.modular.Module) Protocol(org.elixir_lang.structure_view.element.modular.Protocol) Implementation(org.elixir_lang.structure_view.element.modular.Implementation) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with TreeElement

use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-elixir by KronicDeth.

the class Overridable method getChildren.

/**
     * Returns the list of children of the tree element.
     *
     * @return the list of children.
     */
@NotNull
@Override
public TreeElement[] getChildren() {
    QuotableKeywordList keywordArguments = ElixirPsiImplUtil.keywordArguments(navigationItem);
    TreeElement[] children;
    if (keywordArguments != null) {
        List<QuotableKeywordPair> quotableKeywordPairList = keywordArguments.quotableKeywordPairList();
        List<TreeElement> treeElementList = new ArrayList<TreeElement>(quotableKeywordPairList.size());
        for (QuotableKeywordPair quotableKeywordPair : quotableKeywordPairList) {
            Quotable keywordKey = quotableKeywordPair.getKeywordKey();
            OtpErlangObject quotedKeywordKey = keywordKey.quote();
            String name;
            if (quotedKeywordKey instanceof OtpErlangAtom) {
                OtpErlangAtom keywordKeyAtom = (OtpErlangAtom) quotedKeywordKey;
                name = keywordKeyAtom.atomValue();
            } else {
                name = keywordKey.getText();
            }
            Quotable keywordValue = quotableKeywordPair.getKeywordValue();
            OtpErlangObject quotedKeywordValue = keywordValue.quote();
            Integer arity = null;
            if (quotedKeywordValue instanceof OtpErlangLong) {
                OtpErlangLong keywordValueErlangLong = (OtpErlangLong) quotedKeywordValue;
                try {
                    arity = keywordValueErlangLong.intValue();
                } catch (OtpErlangRangeException e) {
                    arity = null;
                }
            }
            boolean overridable = true;
            //noinspection ConstantConditions
            treeElementList.add(new CallReference(modular, quotableKeywordPair, Timed.Time.RUN, overridable, name, arity));
        }
        children = treeElementList.toArray(new TreeElement[treeElementList.size()]);
    } else {
        children = new TreeElement[0];
    }
    return children;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) ArrayList(java.util.ArrayList) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) Quotable(org.elixir_lang.psi.Quotable) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) QuotableKeywordList(org.elixir_lang.psi.QuotableKeywordList) QuotableKeywordPair(org.elixir_lang.psi.QuotableKeywordPair) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with TreeElement

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

the class ResourceBundleEditorRenderer method customize.

private boolean customize(Object value) {
    final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
    if (!(userObject instanceof TreeElementWrapper)) {
        return false;
    }
    final TreeElement treeElement = ((TreeElementWrapper) userObject).getValue();
    if (treeElement == null) {
        return false;
    }
    final ItemPresentation presentation = treeElement.getPresentation();
    if (presentation instanceof TextAttributesPresentation) {
        final TextAttributesPresentation textAttributesPresentation = (TextAttributesPresentation) presentation;
        final String text = textAttributesPresentation.getPresentableText();
        if (text != null) {
            final SimpleTextAttributes attr = SimpleTextAttributes.fromTextAttributes(textAttributesPresentation.getTextAttributes(getColorsScheme()));
            append(text, new SimpleTextAttributes(attr.getBgColor(), attr.getFgColor(), attr.getWaveColor(), attr.getStyle() | SimpleTextAttributes.STYLE_OPAQUE));
            return true;
        }
    }
    return false;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeElementWrapper(com.intellij.ide.util.treeView.smartTree.TreeElementWrapper) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) ItemPresentation(com.intellij.navigation.ItemPresentation) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement)

Example 9 with TreeElement

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

the class ResourceBundleEditor method setStructureViewSelection.

private void setStructureViewSelection(@NotNull final String propertyName) {
    if (myStructureViewComponent.isDisposed()) {
        return;
    }
    JTree tree = myStructureViewComponent.getTree();
    if (tree == null) {
        return;
    }
    Object root = tree.getModel().getRoot();
    if (AbstractTreeUi.isLoadingChildrenFor(root)) {
        boolean isEditorVisible = false;
        for (FileEditor editor : FileEditorManager.getInstance(myProject).getSelectedEditors()) {
            if (editor == this) {
                isEditorVisible = true;
                break;
            }
        }
        if (!isEditorVisible) {
            myPropertyToSelectWhenVisible = propertyName;
            return;
        }
        mySelectionChangeAlarm.cancelAllRequests();
        mySelectionChangeAlarm.addRequest(() -> {
            mySelectionChangeAlarm.cancelAllRequests();
            setStructureViewSelection(propertyName);
        }, 500);
        return;
    }
    Stack<TreeElement> toCheck = ContainerUtilRt.newStack();
    toCheck.push(myStructureViewComponent.getTreeModel().getRoot());
    while (!toCheck.isEmpty()) {
        TreeElement element = toCheck.pop();
        PsiElement value = element instanceof ResourceBundlePropertyStructureViewElement ? ((ResourceBundlePropertyStructureViewElement) element).getProperty().getPsiElement() : null;
        if (value != null) {
            final IProperty property = PropertiesImplUtil.getProperty(value);
            if (propertyName.equals(property.getUnescapedKey())) {
                myStructureViewComponent.select(property, true);
                selectionChanged();
                return;
            }
        } else {
            for (TreeElement treeElement : element.getChildren()) {
                toCheck.push(treeElement);
            }
        }
    }
}
Also used : IProperty(com.intellij.lang.properties.IProperty) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement)

Example 10 with TreeElement

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

the class PsiHelper method addNavigationElements.

private static void addNavigationElements(@NotNull TreeElement root, @NotNull TIntArrayList navigationOffsets, boolean start) {
    if (root instanceof PsiTreeElementBase) {
        PsiElement element = ((PsiTreeElementBase) root).getValue();
        int offset;
        if (start) {
            offset = element.getTextRange().getStartOffset();
            if (element.getLanguage().getID().equals("JAVA")) {
                // HACK: for Java classes and methods, we want to jump to the opening brace
                int textOffset = element.getTextOffset();
                int braceIndex = element.getText().indexOf('{', textOffset - offset);
                if (braceIndex >= 0) {
                    offset += braceIndex;
                }
            }
        } else {
            offset = element.getTextRange().getEndOffset() - 1;
        }
        if (!navigationOffsets.contains(offset)) {
            navigationOffsets.add(offset);
        }
    }
    for (TreeElement child : root.getChildren()) {
        addNavigationElements(child, navigationOffsets, start);
    }
}
Also used : PsiTreeElementBase(com.intellij.ide.structureView.impl.common.PsiTreeElementBase) PsiElement(com.intellij.psi.PsiElement) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement)

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