Don't use misleading optimization (NewVirtualFile.getCachedChildren) in project open processors as it actually useless most time (since inheritors use findChild api) and can return wrong answer in some cases (e.g. in headless mode)

This commit is contained in:
Vladislav.Soroka
2017-03-22 12:12:53 +03:00
parent d80fcfe01d
commit 2afa5caefe
2 changed files with 4 additions and 14 deletions
@@ -37,7 +37,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -45,8 +45,6 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
/**
* @author anna
@@ -82,12 +80,9 @@ public abstract class ProjectOpenProcessorBase<T extends ProjectImportBuilder> e
return false;
}
private static Collection<VirtualFile> getFileChildren(VirtualFile file) {
if (file instanceof NewVirtualFile) {
return ((NewVirtualFile)file).getCachedChildren();
}
return Arrays.asList(file.getChildren());
@NotNull
private static VirtualFile[] getFileChildren(VirtualFile file) {
return ObjectUtils.chooseNotNull(file.getChildren(), VirtualFile.EMPTY_ARRAY);
}
protected static boolean canOpenFile(VirtualFile file, String[] supported) {
@@ -63,11 +63,6 @@ public class GradleProjectOpenProcessor extends ProjectOpenProcessorBase<GradleP
}
}
}
else {
for (String supported : getSupportedExtensions()) {
if (file.findChild(supported) != null) return true;
}
}
return super.canOpenProject(file);
}