allow to check if DirectoryIndexImpl and RootIndex return same results

This commit is contained in:
peter
2013-10-24 19:20:41 +02:00
parent 71e03bb935
commit d3834f35ae
2 changed files with 34 additions and 36 deletions
@@ -405,6 +405,8 @@ public class DirectoryIndexTest extends IdeaTestCase {
checkInfoNull(projectOutput);
checkInfoNull(module2Output);
checkInfoNull(module2TestOutput);
assertTrue(myIndex.isProjectExcludeRoot(excluded));
excluded.delete(this);
projectOutput.delete(this);
@@ -422,6 +424,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
};
VirtualFileManager.getInstance().addVirtualFileListener(l, getTestRootDisposable());
excluded = myModule1Dir.createChildDirectory(this, excluded.getName());
//todo assertTrue(myIndex.isProjectExcludeRoot(excluded));
projectOutput = myModule1Dir.createChildDirectory(this, projectOutput.getName());
module2Output = myModule1Dir.createChildDirectory(this, module2Output.getName());
module2TestOutput = myModule2Dir.createChildDirectory(this, module2TestOutput.getName());
@@ -432,6 +435,8 @@ public class DirectoryIndexTest extends IdeaTestCase {
checkInfoNull(module2TestOutput);
assertEquals(created.toString(), 4, created.size());
assertTrue(myIndex.isProjectExcludeRoot(excluded));
}
public void testExcludesShouldBeRecognizedRightOnRefresh() throws Exception {
@@ -344,10 +344,6 @@ public class DirectoryIndexImpl extends DirectoryIndex {
@Override
public void before(@NotNull List<? extends VFileEvent> events) {
if (ourUseRootIndex) {
return;
}
myBatchChangePlanned = false;
int directoriesRemoved = 0;
int directoriesCreated = 0;
@@ -392,10 +388,7 @@ public class DirectoryIndexImpl extends DirectoryIndex {
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
if (ourUseRootIndex) {
myRootIndex = null;
return;
}
myRootIndex = null;
if (myBatchChangePlanned) {
myBatchChangePlanned = false;
@@ -492,7 +485,6 @@ public class DirectoryIndexImpl extends DirectoryIndex {
RootIndex rootIndex = getRootIndex();
if (rootIndex != null) {
rootIndex.checkConsistency();
return;
}
doCheckConsistency(false);
@@ -549,10 +541,7 @@ public class DirectoryIndexImpl extends DirectoryIndex {
}
private void doInitialize() {
if (ourUseRootIndex) {
myRootIndex = null;
return;
}
myRootIndex = null;
IndexState newState = new IndexState();
newState.doInitialize(false);
@@ -585,25 +574,28 @@ public class DirectoryIndexImpl extends DirectoryIndex {
checkAvailability();
dispatchPendingEvents();
RootIndex rootIndex = getRootIndex();
if (rootIndex != null) {
return rootIndex.getInfoForDirectory(dir);
}
if (!(dir instanceof NewVirtualFile)) return null;
return myState.getInfo(((NewVirtualFile)dir).getId());
RootIndex rootIndex = getRootIndex();
DirectoryInfo riInfo = rootIndex != null ? rootIndex.getInfoForDirectory(dir) : null;
return assertConsistentResult(dir, riInfo, myState.getInfo(((NewVirtualFile)dir).getId()));
}
private static <T> T assertConsistentResult(@Nullable VirtualFile dir, @Nullable T rootIndexResult, T standardResult) {
//noinspection ConstantConditions
if (ourUseRootIndex && !Comparing.equal(rootIndexResult, standardResult)) {
LOG.error("DirectoryIndex differs from RootIndex at " + dir + "\nriInfo=" + rootIndexResult + "\nstandardResult=" + standardResult);
}
return standardResult;
}
@Override
@Nullable
public JpsModuleSourceRootType<?> getSourceRootType(@NotNull DirectoryInfo info) {
RootIndex rootIndex = getRootIndex();
if (rootIndex != null) {
return rootIndex.getSourceRootType(info);
}
if (info.isInModuleSource()) {
return myState.getRootTypeById(info.getSourceRootTypeId());
RootIndex rootIndex = getRootIndex();
JpsModuleSourceRootType<?> riType = rootIndex != null ? rootIndex.getSourceRootType(info) : null;
return assertConsistentResult(null, riType, myState.getRootTypeById(info.getSourceRootTypeId()));
}
return null;
}
@@ -611,12 +603,16 @@ public class DirectoryIndexImpl extends DirectoryIndex {
@Override
public boolean isProjectExcludeRoot(@NotNull VirtualFile dir) {
checkAvailability();
RootIndex rootIndex = getRootIndex();
if (rootIndex != null) {
return rootIndex.isProjectExcludeRoot(dir);
}
if (!(dir instanceof NewVirtualFile)) return false;
return dir instanceof NewVirtualFile && myState.myProjectExcludeRoots.contains(((NewVirtualFile)dir).getId());
//noinspection UnnecessaryLocalVariable
boolean standardResult = myState.myProjectExcludeRoots.contains(((NewVirtualFile)dir).getId());
/* todo
RootIndex rootIndex = getRootIndex();
Boolean riResult = rootIndex != null ? rootIndex.isProjectExcludeRoot(dir) : null;
return assertConsistentResult(dir, riResult, standardResult);
*/
return standardResult;
}
private VirtualFile findFileById(int dir) {
@@ -627,13 +623,10 @@ public class DirectoryIndexImpl extends DirectoryIndex {
public String getPackageName(@NotNull VirtualFile dir) {
checkAvailability();
if (!(dir instanceof NewVirtualFile)) return null;
RootIndex rootIndex = getRootIndex();
if (rootIndex != null) {
return rootIndex.getPackageName(dir);
}
return myState.getPackageNameForDirectory((NewVirtualFile)dir);
String riResult = rootIndex != null ? rootIndex.getPackageName(dir) : null;
return assertConsistentResult(dir, riResult, myState.getPackageNameForDirectory((NewVirtualFile)dir));
}
private static String decodePackageName(@NotNull int[] interned) {