use of com.intellij.ide.projectView.impl.nodes.PsiFileNode in project folding-plugin by dmytrodanylyk.
the class DirectoryNode method getChildren.
@NotNull
@Override
public List<AbstractTreeNode> getChildren() {
if (PropertiesComponent.getInstance().getBoolean(SettingConfigurable.PREFIX_HIDE, false)) {
final ArrayList<AbstractTreeNode> abstractTreeNodes = new ArrayList<>();
for (AbstractTreeNode fileNode : mChildNodeList) {
PsiFile psiFile = (PsiFile) fileNode.getValue();
final ViewSettings settings = ((PsiFileNode) fileNode).getSettings();
String shortName = psiFile.getName().substring(mName.length());
final int beginIndex = shortName.indexOf(ProjectStructureProvider.COMPOSE_BY_CHAR);
if (beginIndex != -1) {
shortName = shortName.substring(beginIndex + 1);
}
abstractTreeNodes.add(new FoldingNode(fileNode.getProject(), psiFile, settings, shortName));
}
return abstractTreeNodes;
} else {
return mChildNodeList;
}
}
use of com.intellij.ide.projectView.impl.nodes.PsiFileNode in project intellij-community by JetBrains.
the class NestingTreeStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (!(parent instanceof PsiDirectoryNode))
return children;
final Collection<NestingRule> rules = getNestingRules();
if (rules.isEmpty())
return children;
final MultiMap<PsiFileNode, PsiFileNode> parentToChildren = calcParentToChildren(children, rules);
if (parentToChildren.isEmpty())
return children;
// initial ArrayList size may be not exact, not a big problem
final Collection<AbstractTreeNode> newChildren = new ArrayList<>(children.size() - parentToChildren.size());
final Set<PsiFileNode> childrenToMoveDown = new THashSet<>(parentToChildren.values());
for (AbstractTreeNode node : children) {
if (!(node instanceof PsiFileNode)) {
newChildren.add(node);
continue;
}
if (childrenToMoveDown.contains(node)) {
continue;
}
final Collection<PsiFileNode> childrenOfThisFile = parentToChildren.get((PsiFileNode) node);
if (childrenOfThisFile.isEmpty()) {
newChildren.add(node);
continue;
}
newChildren.add(new NestingTreeNode((PsiFileNode) node, childrenOfThisFile));
}
return newChildren;
}
use of com.intellij.ide.projectView.impl.nodes.PsiFileNode in project intellij-community by JetBrains.
the class NestingTreeStructureProvider method calcParentToChildren.
/*
This is a graph theory problem. PsiFileNodes are graph nodes.
Edges go from parent file to child file according to NestingRules, for example foo.js->foo.min.js.
Parent may have several children. Child may have several parents.
There may be cycles with 3 or more nodes, but cycle with 2 nodes (A->B and B->A) is impossible because parentFileSuffix != childFileSuffix
For each child its outbound edges are removed. For example in case of a cycle all edges that form it are removed. In case of A->B->C only A->B remains.
As a result we get a number of separated parent-to-many-children sub-graphs, and use them to nest child files under parent file in Project View.
One child still may have more than one parent. For real use cases it is not expected to happen, but anyway it's not a big problem, it will be shown as a subnode more than once.
*/
@NotNull
private static MultiMap<PsiFileNode, PsiFileNode> calcParentToChildren(@NotNull final Collection<AbstractTreeNode> nodes, @NotNull final Collection<NestingRule> rules) {
// result that will contain number of separated parent-to-many-children sub-graphs
MultiMap<PsiFileNode, PsiFileNode> parentToChildren = null;
// helps to remove all outbound edges of a node that has inbound edge itself
Set<PsiFileNode> allChildNodes = null;
// temporary map for building edges
Map<Pair<String, NestingRule>, Edge<PsiFileNode>> baseNameAndRuleToEdge = null;
for (AbstractTreeNode node : nodes) {
if (!(node instanceof PsiFileNode))
continue;
final PsiFile file = ((PsiFileNode) node).getValue();
if (file == null)
continue;
for (NestingRule rule : rules) {
final String fileName = file.getName();
final Couple<Boolean> c = checkMatchingAsParentOrChild(rule, fileName);
final boolean matchesParent = c.first;
final boolean matchesChild = c.second;
if (!matchesChild && !matchesParent)
continue;
if (baseNameAndRuleToEdge == null) {
baseNameAndRuleToEdge = new THashMap<>();
parentToChildren = new MultiMap<>();
allChildNodes = new THashSet<>();
}
if (matchesParent) {
final String baseName = fileName.substring(0, fileName.length() - rule.myParentFileSuffix.length());
final Edge<PsiFileNode> edge = getOrCreateEdge(baseNameAndRuleToEdge, baseName, rule);
edge.from = (PsiFileNode) node;
updateInfoIfEdgeComplete(parentToChildren, allChildNodes, edge);
}
if (matchesChild) {
final String baseName = fileName.substring(0, fileName.length() - rule.myChildFileSuffix.length());
final Edge<PsiFileNode> edge = getOrCreateEdge(baseNameAndRuleToEdge, baseName, rule);
edge.to = (PsiFileNode) node;
updateInfoIfEdgeComplete(parentToChildren, allChildNodes, edge);
}
}
}
return parentToChildren == null ? MultiMap.empty() : parentToChildren;
}
use of com.intellij.ide.projectView.impl.nodes.PsiFileNode in project intellij-community by JetBrains.
the class ResourceBundleNode method extractPropertiesFileFromNode.
@Nullable
private static PropertiesFile extractPropertiesFileFromNode(TreeNode node) {
if (!(node instanceof DefaultMutableTreeNode))
return null;
final Object userObject = ((DefaultMutableTreeNode) node).getUserObject();
if (!(userObject instanceof PsiFileNode))
return null;
final PsiFile file = ((PsiFileNode) userObject).getValue();
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
if (propertiesFile == null || !file.getManager().isInProject(file) || !file.isValid())
return null;
return propertiesFile;
}
use of com.intellij.ide.projectView.impl.nodes.PsiFileNode in project intellij-community by JetBrains.
the class PyTreeStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
final Project project = parent.getProject();
final Sdk sdk = getPythonSdk(parent);
if (sdk != null && project != null) {
final Collection<AbstractTreeNode> newChildren = hideSkeletons(children);
final PySkeletonsNode skeletonsNode = PySkeletonsNode.create(project, sdk, settings);
if (skeletonsNode != null) {
newChildren.add(skeletonsNode);
}
final PyUserSkeletonsNode userSkeletonsNode = PyUserSkeletonsNode.create(project, settings);
if (userSkeletonsNode != null) {
newChildren.add(userSkeletonsNode);
}
final PyRemoteLibrariesNode remoteLibrariesNode = PyRemoteLibrariesNode.create(project, sdk, settings);
if (remoteLibrariesNode != null) {
newChildren.add(remoteLibrariesNode);
}
final PyTypeShedNode typeShedNode = PyTypeShedNode.Companion.create(project, sdk, settings);
if (typeShedNode != null) {
newChildren.add(typeShedNode);
}
return newChildren;
}
if (settings.isShowMembers()) {
List<AbstractTreeNode> newChildren = new ArrayList<>();
for (AbstractTreeNode child : children) {
if (child instanceof PsiFileNode && ((PsiFileNode) child).getValue() instanceof PyFile) {
newChildren.add(new PyFileNode(project, ((PsiFileNode) child).getValue(), settings));
} else {
newChildren.add(child);
}
}
return newChildren;
}
return children;
}
Aggregations