mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use VFS visitor in place of recursion (test framework)
This commit is contained in:
@@ -27,9 +27,13 @@ import com.intellij.openapi.project.impl.ProjectImpl;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.impl.ModuleRootManagerImpl;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
@@ -115,23 +119,23 @@ public abstract class ModuleTestCase extends IdeaTestCase {
|
||||
return loadModule(new File(modulePath));
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
protected ModuleImpl loadAllModulesUnder(VirtualFile rootDir) throws Exception {
|
||||
ModuleImpl module = null;
|
||||
final VirtualFile[] children = rootDir.getChildren();
|
||||
for (VirtualFile child : children) {
|
||||
if (child.isDirectory()) {
|
||||
final ModuleImpl childModule = loadAllModulesUnder(child);
|
||||
if (module == null) module = childModule;
|
||||
protected Module loadAllModulesUnder(@NotNull VirtualFile rootDir) throws Exception {
|
||||
final Ref<Module> result = Ref.create();
|
||||
|
||||
VfsUtilCore.visitChildrenRecursively(rootDir, new VirtualFileVisitor() {
|
||||
@Override
|
||||
public boolean visitFile(@NotNull VirtualFile file) {
|
||||
if (!file.isDirectory() && file.getName().endsWith(ModuleFileType.DOT_DEFAULT_EXTENSION)) {
|
||||
ModuleImpl module = (ModuleImpl)loadModule(new File(file.getPath()));
|
||||
readJdomExternalizables(module);
|
||||
result.setIfNull(module);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (child.getName().endsWith(ModuleFileType.DOT_DEFAULT_EXTENSION)) {
|
||||
String modulePath = child.getPath();
|
||||
module = (ModuleImpl)loadModule(new File(modulePath));
|
||||
readJdomExternalizables(module);
|
||||
}
|
||||
}
|
||||
return module;
|
||||
});
|
||||
|
||||
return result.get();
|
||||
}
|
||||
|
||||
protected void readJdomExternalizables(final ModuleImpl module) {
|
||||
|
||||
@@ -68,10 +68,7 @@ import com.intellij.openapi.util.EmptyRunnable;
|
||||
import com.intellij.openapi.util.ShutDownTracker;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingManager;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingManagerImpl;
|
||||
import com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl;
|
||||
@@ -245,14 +242,15 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
|
||||
@Override
|
||||
public void iterateIndexableFilesIn(@NotNull final VirtualFile file, @NotNull final ContentIterator iterator) {
|
||||
if (file.isDirectory()) {
|
||||
for (VirtualFile child : file.getChildren()) {
|
||||
iterateIndexableFilesIn(child, iterator);
|
||||
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
|
||||
@Override
|
||||
public boolean visitFile(@NotNull VirtualFile file) {
|
||||
if (!file.isDirectory()) {
|
||||
iterator.processFile(file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
iterator.processFile(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, null);
|
||||
|
||||
|
||||
@@ -41,6 +41,14 @@ public class Ref<T> {
|
||||
myValue = value;
|
||||
}
|
||||
|
||||
public boolean setIfNull(@Nullable T value) {
|
||||
if (myValue == null) {
|
||||
myValue = value;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static <T> Ref<T> create() {
|
||||
return new Ref<T>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user