more fixes to align RootIndex and DirectoryIndexImpl

This commit is contained in:
peter
2013-10-24 19:20:41 +02:00
parent bf52d777bb
commit 71e03bb935
2 changed files with 30 additions and 2 deletions
@@ -214,6 +214,8 @@ public class DirectoryIndexTest extends IdeaTestCase {
checkInfoNull(myExcludedLibClsDir);
checkInfoNull(myExcludedLibSrcDir);
assertEquals(myModule1Dir, checkInfoNotNull(myLibClsDir).getContentRoot());
checkInfo(myModule3Dir, myModule3, false, false, null, null);
}
@@ -495,6 +497,11 @@ public class DirectoryIndexTest extends IdeaTestCase {
checkInfo(myModule1Dir, myModule, true, false, "", null, myModule);
checkInfo(mySrcDir1, myModule, true, false, "", JavaSourceRootType.SOURCE, myModule);
checkInfo(myLibDir, myModule, true, false, "lib", null, myModule);
checkInfo(myLibClsDir, myModule, true, false, "", null, myModule2);
checkInfo(myLibSrcDir, myModule, true, true, "", null, myModule);
checkInfo(myResDir, myModule, true, false, "", JavaResourceRootType.RESOURCE, myModule);
}
@@ -509,7 +516,8 @@ public class DirectoryIndexTest extends IdeaTestCase {
@Nullable Module module,
boolean isInLibrary,
boolean isInLibrarySource,
@Nullable String packageName, final JpsModuleSourceRootType<?> moduleSourceRootType,
@Nullable String packageName,
@Nullable final JpsModuleSourceRootType<?> moduleSourceRootType,
Module... modulesOfOrderEntries) {
DirectoryInfo info = checkInfoNotNull(dir);
assertEquals(module, info.getModule());
@@ -180,9 +180,12 @@ class RootIndex {
for (Map.Entry<VirtualFile, DirectoryInfo> entry : myRoots.entrySet()) {
DirectoryInfo info = entry.getValue();
Module module = info.getModule();
VirtualFile contentRoot = info.getContentRoot();
VirtualFile libraryClassRoot = info.getLibraryClassRoot();
boolean inModuleSource = info.isInModuleSource();
boolean inLibrarySource = info.isInLibrarySource();
OrderEntry[] orderEntries = info.getOrderEntries();
boolean nested = false;
@@ -191,12 +194,20 @@ class RootIndex {
DirectoryInfo eachInfo = myRoots.get(eachFile);
if (eachInfo != null) {
nested = true;
if (eachInfo.getLibraryClassRoot() != null && libraryClassRoot == null && !info.isInModuleSource()) {
orderEntries = eachInfo.getOrderEntries();
}
if (module == null) {
module = eachInfo.getModule();
}
if (libraryClassRoot == null) {
libraryClassRoot = eachInfo.getLibraryClassRoot();
}
if (contentRoot == null) {
contentRoot = eachInfo.getContentRoot();
}
inModuleSource |= eachInfo.isInModuleSource();
inLibrarySource |= eachInfo.isInLibrarySource();
}
@@ -208,7 +219,8 @@ class RootIndex {
}
if (nested) {
int sourceRootTypeData = DirectoryInfo.createSourceRootTypeData(inModuleSource, inLibrarySource, info.getSourceRootTypeId());
entry.setValue(info.with(module, info.getContentRoot(), info.getSourceRoot(), libraryClassRoot, sourceRootTypeData, info.getOrderEntries()));
if (orderEntries.length == 0) orderEntries = null;
entry.setValue(info.with(module, contentRoot, info.getSourceRoot(), libraryClassRoot, sourceRootTypeData, orderEntries));
}
}
}
@@ -293,7 +305,15 @@ class RootIndex {
myPackagePrefixRoots.get(packagePrefix).add(root);
}
@Nullable
public DirectoryInfo getInfoForDirectory(@NotNull final VirtualFile dir) {
if (!dir.isValid()) {
return null;
}
if (!dir.isDirectory()) {
return myRoots.get(dir);
}
int count = 0;
for (VirtualFile root = dir; root != null; root = root.getParent()) {
if (++count > 1000) {