mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
project view: don't show duplicated nodes for content roots located under excluded roots (IDEA-162102)
This commit is contained in:
@@ -142,20 +142,44 @@ public class ProjectTreeStructureTest extends BaseProjectViewTestCase {
|
||||
ModuleManagerImpl.getInstanceImpl(myProject).setModuleGroupPath(module, new String[]{"modules"});
|
||||
PsiTestUtil.addContentRoot(module, mainModuleRoot.findFileByRelativePath("src/com/package1/p2/p3"));
|
||||
|
||||
TestProjectTreeStructure structure = new TestProjectTreeStructure(myProject, getTestRootDisposable());
|
||||
structure.setShowLibraryContents(false);
|
||||
myStructure.setShowLibraryContents(false);
|
||||
myStructure.hideExcludedFiles();
|
||||
|
||||
String structureContent = PlatformTestUtil.print(structure, structure.getRootElement(), 0, null, 10, ' ', myPrintInfo).toString();
|
||||
assertStructureEqual("Project\n" +
|
||||
" nested_module.iml\n" +
|
||||
" noDuplicateModules\n" +
|
||||
" src\n" +
|
||||
" com\n" +
|
||||
" package1\n" +
|
||||
" Test.java\n" +
|
||||
" testNoDuplicateModules.iml\n");
|
||||
}
|
||||
|
||||
Assert.assertFalse(structureContent.contains("modules"));
|
||||
assertEquals("Project\n" +
|
||||
" noDuplicateModules\n" +
|
||||
" src\n" +
|
||||
" com\n" +
|
||||
" package1\n" +
|
||||
" Test.java\n" +
|
||||
" nested_module.iml\n" +
|
||||
" testNoDuplicateModules.iml\n",
|
||||
structureContent);
|
||||
public void testContentRootUnderExcluded() {
|
||||
VirtualFile mainModuleRoot = ModuleRootManager.getInstance(myModule).getContentRoots()[0];
|
||||
|
||||
PsiTestUtil.addExcludedRoot(myModule, mainModuleRoot.findFileByRelativePath("exc"));
|
||||
|
||||
PsiTestUtil.addContentRoot(myModule, mainModuleRoot.findFileByRelativePath("exc/gen"));
|
||||
|
||||
myStructure.setShowLibraryContents(false);
|
||||
|
||||
assertStructureEqual("Project\n" +
|
||||
" contentRootUnderExcluded\n" +
|
||||
" B.txt\n" +
|
||||
" exc\n" +
|
||||
" excluded.txt\n" +
|
||||
" gen\n" +
|
||||
" A.java\n" +
|
||||
" testContentRootUnderExcluded.iml\n");
|
||||
|
||||
myStructure.hideExcludedFiles();
|
||||
assertStructureEqual("Project\n" +
|
||||
" Module\n" +
|
||||
" contentRootUnderExcluded\n" +
|
||||
" B.txt\n" +
|
||||
" gen\n" +
|
||||
" A.java\n" +
|
||||
" testContentRootUnderExcluded.iml\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,9 +65,17 @@ public abstract class BaseProjectViewTestCase extends TestSourceBasedTestCase {
|
||||
return myStructure;
|
||||
}
|
||||
|
||||
private void assertStructureEqual(PsiDirectory root, String expected, int maxRowCount, AbstractTreeStructure structure) {
|
||||
private void assertStructureEqual(PsiDirectory root, String expected, int maxRowCount, AbstractProjectTreeStructure structure) {
|
||||
assertNotNull(root);
|
||||
PsiDirectoryNode rootNode = new PsiDirectoryNode(myProject, root, (ViewSettings)structure);
|
||||
PsiDirectoryNode rootNode = new PsiDirectoryNode(myProject, root, structure);
|
||||
assertStructureEqual(expected, maxRowCount, rootNode);
|
||||
}
|
||||
|
||||
protected void assertStructureEqual(String expected) {
|
||||
assertStructureEqual(expected, -1, myStructure.getRootElement());
|
||||
}
|
||||
|
||||
private void assertStructureEqual(String expected, int maxRowCount, Object rootNode) {
|
||||
ProjectViewTestUtil.assertStructureEqual(myStructure, expected, maxRowCount, PlatformTestUtil.createComparator(myPrintInfo), rootNode, myPrintInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.PsiElementProcessor;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.FontUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -212,6 +213,19 @@ public class ProjectViewDirectoryHelper {
|
||||
return topLevelContentRoots;
|
||||
}
|
||||
|
||||
public List<VirtualFile> getTopLevelModuleRoots(Module module, ViewSettings settings) {
|
||||
return ContainerUtil.filter(ModuleRootManager.getInstance(module).getContentRoots(), root -> {
|
||||
if (!shouldBeShown(root, settings)) return false;
|
||||
VirtualFile parent = root.getParent();
|
||||
if (parent == null) return true;
|
||||
DirectoryInfo info = myIndex.getInfoForFile(parent);
|
||||
if (!module.equals(info.getModule())) return true;
|
||||
//show inner content root separately only if it won't be shown under outer content root
|
||||
return info.isExcluded() && !shouldShowExcludedFiles(settings);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static boolean isFileInContent(ProjectFileIndex index, VirtualFile file) {
|
||||
while (file != null) {
|
||||
if (index.isInContent(file)) {
|
||||
@@ -260,12 +274,11 @@ public class ProjectViewDirectoryHelper {
|
||||
|
||||
private boolean shouldBeShown(VirtualFile dir, ViewSettings settings) {
|
||||
DirectoryInfo directoryInfo = myIndex.getInfoForFile(dir);
|
||||
if (directoryInfo.isInProject()) return true;
|
||||
return directoryInfo.isInProject() || shouldShowExcludedFiles(settings) && directoryInfo.isExcluded();
|
||||
}
|
||||
|
||||
if (!Registry.is("ide.hide.excluded.files") && settings instanceof ProjectViewSettings && ((ProjectViewSettings)settings).isShowExcludedFiles()) {
|
||||
return directoryInfo.isExcluded();
|
||||
}
|
||||
return false;
|
||||
private static boolean shouldShowExcludedFiles(ViewSettings settings) {
|
||||
return !Registry.is("ide.hide.excluded.files") && settings instanceof ProjectViewSettings && ((ProjectViewSettings)settings).isShowExcludedFiles();
|
||||
}
|
||||
|
||||
// used only for non-flatten packages mode
|
||||
|
||||
@@ -46,15 +46,11 @@ public class ProjectViewModuleNode extends AbstractModuleNode {
|
||||
if (module == null || module.isDisposed()) { // module has been disposed
|
||||
return Collections.emptyList();
|
||||
}
|
||||
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
ModuleFileIndex moduleFileIndex = rootManager.getFileIndex();
|
||||
|
||||
final VirtualFile[] contentRoots = rootManager.getContentRoots();
|
||||
final List<AbstractTreeNode> children = new ArrayList<>(contentRoots.length + 1);
|
||||
final List<VirtualFile> contentRoots = ProjectViewDirectoryHelper.getInstance(myProject).getTopLevelModuleRoots(module, getSettings());
|
||||
final List<AbstractTreeNode> children = new ArrayList<>(contentRoots.size());
|
||||
final PsiManager psiManager = PsiManager.getInstance(module.getProject());
|
||||
for (final VirtualFile contentRoot : contentRoots) {
|
||||
if (!moduleFileIndex.isInContent(contentRoot)) continue;
|
||||
|
||||
if (contentRoot.isDirectory()) {
|
||||
PsiDirectory directory = psiManager.findDirectory(contentRoot);
|
||||
if (directory != null) {
|
||||
@@ -68,12 +64,6 @@ public class ProjectViewModuleNode extends AbstractModuleNode {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (getSettings().isShowLibraryContents()) {
|
||||
children.add(new LibraryGroupNode(getProject(), new LibraryGroupElement(getValue()), getSettings()));
|
||||
}
|
||||
*/
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -125,9 +124,9 @@ public class ProjectViewProjectNode extends AbstractProjectNode {
|
||||
@Override
|
||||
protected AbstractTreeNode createModuleGroup(final Module module)
|
||||
throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||
final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
|
||||
if (roots.length == 1) {
|
||||
final PsiDirectory psi = PsiManager.getInstance(myProject).findDirectory(roots[0]);
|
||||
List<VirtualFile> roots = ProjectViewDirectoryHelper.getInstance(myProject).getTopLevelModuleRoots(module, getSettings());
|
||||
if (roots.size() == 1) {
|
||||
final PsiDirectory psi = PsiManager.getInstance(myProject).findDirectory(roots.get(0));
|
||||
if (psi != null) {
|
||||
return new PsiDirectoryNode(myProject, psi, getSettings());
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.projectView;
|
||||
|
||||
import com.intellij.ide.projectView.ProjectViewSettings;
|
||||
import com.intellij.ide.projectView.impl.AbstractProjectTreeStructure;
|
||||
import com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane;
|
||||
import com.intellij.openapi.Disposable;
|
||||
@@ -25,7 +26,8 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.testFramework.ProjectViewTestUtil;
|
||||
import org.junit.Assert;
|
||||
|
||||
public class TestProjectTreeStructure extends AbstractProjectTreeStructure implements Disposable {
|
||||
public class TestProjectTreeStructure extends AbstractProjectTreeStructure implements Disposable, ProjectViewSettings {
|
||||
private boolean myShowExcludedFiles = true;
|
||||
protected boolean myShowMembers = false;
|
||||
protected boolean myHideEmptyMiddlePackages;
|
||||
protected boolean myFlattenPackages;
|
||||
@@ -74,6 +76,11 @@ public class TestProjectTreeStructure extends AbstractProjectTreeStructure imple
|
||||
return myShowLibraryContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowExcludedFiles() {
|
||||
return myShowExcludedFiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowModules() {
|
||||
return true;
|
||||
@@ -91,6 +98,10 @@ public class TestProjectTreeStructure extends AbstractProjectTreeStructure imple
|
||||
myFlattenPackages = flattenPackages;
|
||||
}
|
||||
|
||||
public void hideExcludedFiles() {
|
||||
myShowExcludedFiles = false;
|
||||
}
|
||||
|
||||
public void setShowLibraryContents(boolean showLibraryContents) {
|
||||
myShowLibraryContents = showLibraryContents;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user