mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
FileTypeUsagesCollector — do not use Project.DIRECTORY_STORE_FOLDER
This commit is contained in:
@@ -20,7 +20,6 @@ import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.components.ApplicationComponent;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
@@ -53,7 +52,6 @@ import java.util.Set;
|
||||
* 2. corresponding source file has been deleted
|
||||
*/
|
||||
public class TranslatingCompilerFilesMonitor implements ApplicationComponent {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.TranslatingCompilerFilesMonitor");
|
||||
public static boolean ourDebugMode = false;
|
||||
|
||||
public TranslatingCompilerFilesMonitor(VirtualFileManager vfsManager, Application application) {
|
||||
|
||||
@@ -27,15 +27,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
* @author dmitrylomov
|
||||
*/
|
||||
public class ProjectCoreUtil {
|
||||
/** @deprecated use {@link Project#DIRECTORY_STORE_FOLDER} (to be removed in IDEA 17) */
|
||||
public static final String DIRECTORY_BASED_PROJECT_DIR = Project.DIRECTORY_STORE_FOLDER;
|
||||
public static volatile Project theProject;
|
||||
|
||||
public static boolean isProjectOrWorkspaceFile(@NotNull VirtualFile file) {
|
||||
return isProjectOrWorkspaceFile(file, file.getFileType());
|
||||
}
|
||||
|
||||
public static boolean isProjectOrWorkspaceFile(@NotNull VirtualFile file, @Nullable FileType fileType) {
|
||||
if (fileType instanceof InternalFileType) return true;
|
||||
if (fileType instanceof InternalFileType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
VirtualFile parent = file.isDirectory() ? file: file.getParent();
|
||||
while (parent != null) {
|
||||
if (Comparing.equal(parent.getNameSequence(), Project.DIRECTORY_STORE_FOLDER, SystemInfoRt.isFileSystemCaseSensitive)) return true;
|
||||
@@ -51,5 +53,4 @@ public class ProjectCoreUtil {
|
||||
public static Project theOnlyOpenProject() {
|
||||
return theProject;
|
||||
}
|
||||
public static volatile Project theProject;
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import com.intellij.openapi.fileEditor.UniqueVFilePathBuilder;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFilePathWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -37,11 +36,6 @@ public class ProjectUtil {
|
||||
private ProjectUtil() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getProjectLocationString(@NotNull final Project project) {
|
||||
return FileUtil.getLocationRelativeToUserHome(project.getBasePath());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String calcRelativeToProjectPath(@NotNull final VirtualFile file,
|
||||
@Nullable final Project project,
|
||||
@@ -93,7 +87,7 @@ public class ProjectUtil {
|
||||
*/
|
||||
@Nullable
|
||||
public static Project guessProjectForContentFile(@NotNull VirtualFile file, @NotNull FileType fileType) {
|
||||
if (isProjectOrWorkspaceFile(file, fileType)) {
|
||||
if (ProjectCoreUtil.isProjectOrWorkspaceFile(file, fileType)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -106,13 +100,9 @@ public class ProjectUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isProjectOrWorkspaceFile(final VirtualFile file) {
|
||||
public static boolean isProjectOrWorkspaceFile(@NotNull VirtualFile file) {
|
||||
// do not use file.getFileType() to avoid autodetection by content loading for arbitrary files
|
||||
return isProjectOrWorkspaceFile(file, FileTypeManager.getInstance().getFileTypeByFileName(file.getName()));
|
||||
}
|
||||
|
||||
public static boolean isProjectOrWorkspaceFile(@NotNull VirtualFile file, @Nullable FileType fileType) {
|
||||
return ProjectCoreUtil.isProjectOrWorkspaceFile(file, fileType);
|
||||
return ProjectCoreUtil.isProjectOrWorkspaceFile(file, FileTypeManager.getInstance().getFileTypeByFileName(file.getName()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -21,16 +21,13 @@ import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.project.ProjectKt;
|
||||
import com.intellij.psi.search.FileTypeIndex;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.NotNullFunction;
|
||||
import com.intellij.util.ThreeState;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -38,7 +35,6 @@ import java.util.Set;
|
||||
* @author Nikolay Matveev
|
||||
*/
|
||||
public class FileTypeUsagesCollector extends AbstractApplicationUsagesCollector {
|
||||
|
||||
private static final String GROUP_ID = "file-type";
|
||||
|
||||
@NotNull
|
||||
@@ -60,11 +56,10 @@ public class FileTypeUsagesCollector extends AbstractApplicationUsagesCollector
|
||||
if (project.isDisposed()) {
|
||||
throw new CollectUsagesException("Project is disposed");
|
||||
}
|
||||
final String ideaDirPath = getIdeaDirPath(project);
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
FileTypeIndex.processFiles(fileType, file -> {
|
||||
//skip files from .idea directory otherwise 99% of projects would have XML and PLAIN_TEXT file types
|
||||
if (ideaDirPath == null || FileUtil.isAncestorThreeState(ideaDirPath, file.getPath(), true) == ThreeState.NO) {
|
||||
if (!ProjectKt.getStateStore(project).isProjectFile(file)) {
|
||||
usedFileTypes.add(fileType);
|
||||
return false;
|
||||
}
|
||||
@@ -74,16 +69,4 @@ public class FileTypeUsagesCollector extends AbstractApplicationUsagesCollector
|
||||
}
|
||||
return ContainerUtil.map2Set(usedFileTypes, (NotNullFunction<FileType, UsageDescriptor>)fileType -> new UsageDescriptor(fileType.getName(), 1));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getIdeaDirPath(@NotNull Project project) {
|
||||
String projectPath = project.getBasePath();
|
||||
if (projectPath != null) {
|
||||
String ideaDirPath = projectPath + "/" + Project.DIRECTORY_STORE_FOLDER;
|
||||
if (new File(ideaDirPath).isDirectory()) {
|
||||
return ideaDirPath;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user