Search in sources :

Example 1 with BasePsiNode

use of com.intellij.ide.projectView.impl.nodes.BasePsiNode in project intellij-community by JetBrains.

the class FormMergerTreeStructureProvider method findFormsIn.

private static Collection<BasePsiNode<? extends PsiElement>> findFormsIn(Collection<AbstractTreeNode> children, List<PsiFile> forms) {
    if (children.isEmpty() || forms.isEmpty())
        return Collections.emptyList();
    ArrayList<BasePsiNode<? extends PsiElement>> result = new ArrayList<>();
    HashSet<PsiFile> psiFiles = new HashSet<>(forms);
    for (final AbstractTreeNode child : children) {
        if (child instanceof BasePsiNode) {
            //noinspection unchecked
            BasePsiNode<? extends PsiElement> treeNode = (BasePsiNode<? extends PsiElement>) child;
            //noinspection SuspiciousMethodCalls
            if (psiFiles.contains(treeNode.getValue()))
                result.add(treeNode);
        }
    }
    return result;
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) BasePsiNode(com.intellij.ide.projectView.impl.nodes.BasePsiNode)

Example 2 with BasePsiNode

use of com.intellij.ide.projectView.impl.nodes.BasePsiNode in project intellij-community by JetBrains.

the class FormMergerTreeStructureProvider method modify.

@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    if (parent.getValue() instanceof Form)
        return children;
    // Optimization. Check if there are any forms at all.
    boolean formsFound = false;
    for (AbstractTreeNode node : children) {
        if (node.getValue() instanceof PsiFile) {
            PsiFile file = (PsiFile) node.getValue();
            if (file.getFileType() == StdFileTypes.GUI_DESIGNER_FORM) {
                formsFound = true;
                break;
            }
        }
    }
    if (!formsFound)
        return children;
    Collection<AbstractTreeNode> result = new LinkedHashSet<>(children);
    ProjectViewNode[] copy = children.toArray(new ProjectViewNode[children.size()]);
    for (ProjectViewNode element : copy) {
        PsiClass psiClass = null;
        if (element.getValue() instanceof PsiClass) {
            psiClass = (PsiClass) element.getValue();
        } else if (element.getValue() instanceof PsiClassOwner) {
            final PsiClass[] psiClasses = ((PsiClassOwner) element.getValue()).getClasses();
            if (psiClasses.length == 1) {
                psiClass = psiClasses[0];
            }
        }
        if (psiClass == null)
            continue;
        String qName = psiClass.getQualifiedName();
        if (qName == null)
            continue;
        List<PsiFile> forms;
        try {
            forms = FormClassIndex.findFormsBoundToClass(myProject, qName);
        } catch (ProcessCanceledException e) {
            continue;
        }
        Collection<BasePsiNode<? extends PsiElement>> formNodes = findFormsIn(children, forms);
        if (!formNodes.isEmpty()) {
            Collection<PsiFile> formFiles = convertToFiles(formNodes);
            Collection<BasePsiNode<? extends PsiElement>> subNodes = new ArrayList<>();
            //noinspection unchecked
            subNodes.add((BasePsiNode<? extends PsiElement>) element);
            subNodes.addAll(formNodes);
            result.add(new FormNode(myProject, new Form(psiClass, formFiles), settings, subNodes));
            result.remove(element);
            result.removeAll(formNodes);
        }
    }
    return result;
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) BasePsiNode(com.intellij.ide.projectView.impl.nodes.BasePsiNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with BasePsiNode

use of com.intellij.ide.projectView.impl.nodes.BasePsiNode in project intellij-community by JetBrains.

the class FormNode method getChildren.

private static Collection<BasePsiNode<? extends PsiElement>> getChildren(final Project project, final Form form, final ViewSettings settings) {
    final Set<BasePsiNode<? extends PsiElement>> children = new LinkedHashSet<>();
    children.add(new ClassTreeNode(project, form.getClassToBind(), settings));
    for (PsiFile formBoundToClass : form.getFormFiles()) {
        children.add(new PsiFileNode(project, formBoundToClass, settings));
    }
    return children;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) PsiFile(com.intellij.psi.PsiFile) BasePsiNode(com.intellij.ide.projectView.impl.nodes.BasePsiNode) PsiElement(com.intellij.psi.PsiElement) ClassTreeNode(com.intellij.ide.projectView.impl.nodes.ClassTreeNode)

Example 4 with BasePsiNode

use of com.intellij.ide.projectView.impl.nodes.BasePsiNode in project intellij-community by JetBrains.

the class ProjectViewTestUtil method getFiles.

public static VirtualFile[] getFiles(AbstractTreeNode kid, Function<AbstractTreeNode, VirtualFile[]> converterFunction) {
    if (kid instanceof BasePsiNode) {
        Object value = kid.getValue();
        VirtualFile virtualFile = PsiUtilCore.getVirtualFile((PsiElement) value);
        return new VirtualFile[] { virtualFile };
    }
    if (converterFunction != null) {
        final VirtualFile[] result = converterFunction.fun(kid);
        if (result != null) {
            return result;
        }
    }
    return VirtualFile.EMPTY_ARRAY;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BasePsiNode(com.intellij.ide.projectView.impl.nodes.BasePsiNode)

Aggregations

BasePsiNode (com.intellij.ide.projectView.impl.nodes.BasePsiNode)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)1 ClassTreeNode (com.intellij.ide.projectView.impl.nodes.ClassTreeNode)1 PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 LinkedHashSet (java.util.LinkedHashSet)1 NotNull (org.jetbrains.annotations.NotNull)1