avoid using getModuleFile, prefer path

This commit is contained in:
Vladimir Krivosheev
2015-09-03 12:32:43 +02:00
parent 710f03c333
commit 72dcde6aca
10 changed files with 60 additions and 40 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderEntry;
@@ -100,7 +101,7 @@ public class ProjectStructureSelectInTarget extends SelectInTargetBase implement
@Nullable
private static Module findModuleByModuleFile(@NotNull Project project, @NotNull VirtualFile file) {
for (Module module : ModuleManager.getInstance(project).getModules()) {
if (file.equals(module.getModuleFile())) {
if (ModuleUtilCore.isModuleFile(module, file)) {
return module;
}
}
@@ -38,6 +38,7 @@ import com.intellij.testFramework.fixtures.TempDirTestFixture;
import com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl;
import com.intellij.util.Consumer;
import com.intellij.util.ObjectUtils;
import com.intellij.util.ThrowableRunnable;
import com.intellij.util.concurrency.Semaphore;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
@@ -203,26 +204,19 @@ public class CompilerTester {
semaphore.down();
final ErrorReportingCallback callback = new ErrorReportingCallback(semaphore);
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
EdtTestUtil.runInEdtAndWait(new ThrowableRunnable<Throwable>() {
@Override
public void run() {
try {
getProject().save();
CompilerTestUtil.saveApplicationSettings();
for (Module module : myModules) {
VirtualFile moduleFile = module.getModuleFile();
assert moduleFile != null;
File ioFile = VfsUtilCore.virtualToIoFile(moduleFile);
if (!ioFile.exists()) {
getProject().save();
assert ioFile.exists() : "File does not exist: " + ioFile.getPath();
}
public void run() throws Throwable {
getProject().save();
CompilerTestUtil.saveApplicationSettings();
for (Module module : myModules) {
File ioFile = new File(module.getModuleFilePath());
if (!ioFile.exists()) {
getProject().save();
assert ioFile.exists() : "File does not exist: " + ioFile.getPath();
}
runnable.consume(callback);
}
catch (Exception e) {
throw new RuntimeException(e);
}
runnable.consume(callback);
}
});
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.util.PathUtil;
import org.jetbrains.annotations.NonNls;
import java.io.File;
@@ -100,6 +101,6 @@ import java.io.File;
}
protected String getRootFiles() {
return " " + myModule.getModuleFile().getName() + "\n";
return " " + PathUtil.getFileName(myModule.getModuleFilePath()) + "\n";
}
}
@@ -102,12 +102,9 @@ open class ProjectStoreImpl(override val project: ProjectImpl, private val pathM
storageManager.clearStorages()
}
override fun getProjectBaseDir(): VirtualFile? {
val path = getProjectBasePath() ?: return null
return LocalFileSystem.getInstance().findFileByPath(path)
}
override fun getProjectBaseDir() = LocalFileSystem.getInstance().findFileByPath(getProjectBasePath())
override fun getProjectBasePath(): String? {
override fun getProjectBasePath(): String {
val path = PathUtilRt.getParentPath(getProjectFilePath())
return if (scheme == StorageScheme.DEFAULT) path else PathUtilRt.getParentPath(path)
}
@@ -159,10 +156,7 @@ open class ProjectStoreImpl(override val project: ProjectImpl, private val pathM
override fun getPresentableUrl(): String? {
if (presentableUrl == null) {
val url = if (scheme == StorageScheme.DIRECTORY_BASED) getProjectBasePath() else getProjectFilePath()
if (url != null) {
presentableUrl = FileUtil.toSystemDependentName(url)
}
presentableUrl = FileUtil.toSystemDependentName(if (scheme == StorageScheme.DIRECTORY_BASED) getProjectBasePath() else getProjectFilePath())
}
return presentableUrl
}
@@ -48,11 +48,10 @@ public interface Module extends ComponentManager, AreaInstance, Disposable {
VirtualFile getModuleFile();
/**
* Returns the path to the module .iml file.
*
* @return the path to the .iml file.
* System-independent path to the .iml file.
*/
@NotNull String getModuleFilePath();
@NotNull
String getModuleFilePath();
/**
* Returns the project to which this module belongs.
@@ -54,7 +54,7 @@ public interface Project extends ComponentManager, AreaInstance {
VirtualFile getBaseDir();
/**
* Returns a system-dependent path to a project base directory (see {@linkplain #getBaseDir()}).<br/>
* Returns a system-independent path to a project base directory (see {@linkplain #getBaseDir()}).<br/>
* Returns <code>null</code> for default project.
*
* @return a path to a project base directory, or <code>null</code> for default project
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
import com.intellij.openapi.fileTypes.FileTypeRegistry;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.FileIndexFacade;
import com.intellij.openapi.util.text.StringUtil;
@@ -133,7 +134,7 @@ public abstract class AbstractConvertLineSeparatorsAction extends AnAction {
return false;
}
Module module = FileIndexFacade.getInstance(project).getModuleForFile(file);
return module == null || !file.equals(module.getModuleFile());
return module == null || !ModuleUtilCore.isModuleFile(module, file);
}
public static void changeLineSeparators(@NotNull final Project project,
@@ -29,6 +29,9 @@ public interface IProjectStore extends IComponentStore {
VirtualFile getProjectBaseDir();
@Nullable
/**
* System-independent path.
*/
String getProjectBasePath();
@NotNull
@@ -47,12 +50,18 @@ public interface IProjectStore extends IComponentStore {
VirtualFile getProjectFile();
@NotNull
/**
* System-independent path.
*/
String getProjectFilePath();
@Nullable
VirtualFile getWorkspaceFile();
@Nullable
/**
* System-independent path.
*/
String getWorkspaceFilePath();
void loadProjectFromTemplate(@NotNull Project project);
@@ -30,6 +30,7 @@ import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.NotNullLazyKey;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vfs.*;
import com.intellij.util.NotNullFunction;
@@ -162,9 +163,14 @@ public class NonProjectFileWritingAccessProvider extends WritingAccessProvider {
}
IProjectStore store = (IProjectStore)ComponentsPackage.getStateStore(project);
if (file.equals(store.getWorkspaceFile()) || file.equals(store.getProjectFile())) return true;
for (Module each : ModuleManager.getInstance(project).getModules()) {
if (file.equals(each.getModuleFile())) return true;
String filePath = file.getPath();
if (FileUtil.namesEqual(filePath, store.getWorkspaceFilePath()) || FileUtil.namesEqual(filePath, store.getProjectFilePath())) {
return true;
}
for (Module module : ModuleManager.getInstance(project).getModules()) {
if (FileUtil.namesEqual(filePath, module.getModuleFilePath())) {
return true;
}
}
}
@@ -20,10 +20,12 @@ import com.intellij.openapi.application.Result;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileSystemItem;
import com.intellij.util.PathUtilRt;
import com.intellij.util.containers.HashSet;
import com.intellij.util.graph.Graph;
import org.jetbrains.annotations.NotNull;
@@ -214,6 +216,19 @@ public class ModuleUtilCore {
}
}
public static boolean isModuleFile(@NotNull Module module, @NotNull VirtualFile file) {
return FileUtil.namesEqual(file.getPath(), module.getModuleFilePath());
}
public static boolean isModuleDir(@NotNull Module module, @NotNull VirtualFile dir) {
return FileUtil.namesEqual(dir.getPath(), getModuleDirPath(module));
}
@NotNull
public static String getModuleDirPath(@NotNull Module module) {
return PathUtilRt.getParentPath(module.getModuleFilePath());
}
public interface ModuleVisitor {
/**
*