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;
}
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;
}
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;
}
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;
}
Aggregations