mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
(by patch from IDEA-151808) Walk up to the root to determine if file is in content roots
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
package com.intellij.projectView;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.impl.ModuleManagerImpl;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.ui.Queryable;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import org.junit.Assert;
|
||||
|
||||
public class ProjectTreeStructureTest extends BaseProjectViewTestCase {
|
||||
|
||||
@@ -110,4 +117,30 @@ public class ProjectTreeStructureTest extends BaseProjectViewTestCase {
|
||||
|
||||
checkContainsMethod(myStructure.getRootElement(), myStructure);
|
||||
}
|
||||
|
||||
public void testNoDuplicateModules() {
|
||||
VirtualFile mainModuleRoot = ModuleRootManager.getInstance(myModule).getContentRoots()[0];
|
||||
|
||||
PsiTestUtil.addExcludedRoot(myModule, mainModuleRoot.findFileByRelativePath("src/com/package1/p2"));
|
||||
|
||||
Module module = createModule("nested_module");
|
||||
ModuleManagerImpl.getInstanceImpl(myProject).setModuleGroupPath(module, new String[]{"modules"});
|
||||
PsiTestUtil.addContentRoot(module, mainModuleRoot.findFileByRelativePath("src/com/package1/p2/p3"));
|
||||
|
||||
TestProjectTreeStructure structure = new TestProjectTreeStructure(myProject, myTestRootDisposable);
|
||||
structure.setShowLibraryContents(false);
|
||||
|
||||
String structureContent = PlatformTestUtil.print(structure, structure.getRootElement(), 0, null, 10, ' ', myPrintInfo).toString();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-1
@@ -190,13 +190,23 @@ public class ProjectViewDirectoryHelper {
|
||||
|
||||
for (VirtualFile root : prm.getContentRoots()) {
|
||||
VirtualFile parent = root.getParent();
|
||||
if (parent == null || !index.isInContent(parent)) {
|
||||
if (!isFileInContent(index, parent)) {
|
||||
topLevelContentRoots.add(root);
|
||||
}
|
||||
}
|
||||
return topLevelContentRoots;
|
||||
}
|
||||
|
||||
private static boolean isFileInContent(ProjectFileIndex index, VirtualFile file) {
|
||||
while (file != null) {
|
||||
if (index.isInContent(file)) {
|
||||
return true;
|
||||
}
|
||||
file = file.getParent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private PsiElement[] directoryChildrenInProject(PsiDirectory psiDirectory, final ViewSettings settings) {
|
||||
final VirtualFile dir = psiDirectory.getVirtualFile();
|
||||
if (shouldBeShown(dir, settings)) {
|
||||
|
||||
@@ -29,6 +29,7 @@ public class TestProjectTreeStructure extends AbstractProjectTreeStructure imple
|
||||
protected boolean myShowMembers = false;
|
||||
protected boolean myHideEmptyMiddlePackages;
|
||||
protected boolean myFlattenPackages;
|
||||
protected boolean myShowLibraryContents = true;
|
||||
|
||||
public TestProjectTreeStructure(Project project, Disposable parentDisposable) {
|
||||
super(project);
|
||||
@@ -70,7 +71,7 @@ public class TestProjectTreeStructure extends AbstractProjectTreeStructure imple
|
||||
|
||||
@Override
|
||||
public boolean isShowLibraryContents() {
|
||||
return true;
|
||||
return myShowLibraryContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,6 +91,10 @@ public class TestProjectTreeStructure extends AbstractProjectTreeStructure imple
|
||||
myFlattenPackages = flattenPackages;
|
||||
}
|
||||
|
||||
public void setShowLibraryContents(boolean showLibraryContents) {
|
||||
myShowLibraryContents = showLibraryContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user