Java Code Examples for com.intellij.openapi.module.Module#getModuleFile()

The following examples show how to use com.intellij.openapi.module.Module#getModuleFile() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: arma-intellij-plugin   File: ArmaPlugin.java    License: MIT License 6 votes vote down vote up
/**
 * @return the path to Arma IntelliJ Plugin's temp directory for the given module,
 * or null if the .iml directory couldn't be located
 */
@Nullable
public static String getPathToTempDirectory(@NotNull Module module) {
	final String tempFolder = "/armaplugin-temp";

	//find a place to save parse data
	VirtualFile imlVirtFile = module.getModuleFile();
	if (imlVirtFile == null) {
		String projectBasePath = module.getProject().getBasePath();
		if (projectBasePath == null) {
			return null;
		}
		return projectBasePath + tempFolder;
	}
	VirtualFile imlDir = imlVirtFile.getParent();
	if (imlDir == null) {
		return null;
	}
	return imlDir.getPath() + tempFolder;
}
 
Example 2
public static Result checkFile(Module module, String filePath, boolean directory) {
    Result ret = Result.ok;
    if(filePath == null || filePath.length() == 0) {
        ret = Result.fileEmpty;
    } else {
        VirtualFile moduleFile = module.getModuleFile();
        VirtualFile file = moduleFile.getFileSystem().findFileByPath(filePath);
        if(file == null) {
            ret = Result.fileNotFound;
        } else if(directory) {
            if(!file.isDirectory()) {
                ret = Result.notDirectory;
            }
        } else {
            if(!file.isDirectory()) {
                ret = Result.notFile;
            }
        }
    }
    return ret;
}
 
Example 3
Source Project: arma-intellij-plugin   File: ArmaPlugin.java    License: MIT License 6 votes vote down vote up
/**
 * @return the path to Arma IntelliJ Plugin's temp directory for the given module,
 * or null if the .iml directory couldn't be located
 */
@Nullable
public static String getPathToTempDirectory(@NotNull Module module) {
	final String tempFolder = "/armaplugin-temp";

	//find a place to save parse data
	VirtualFile imlVirtFile = module.getModuleFile();
	if (imlVirtFile == null) {
		String projectBasePath = module.getProject().getBasePath();
		if (projectBasePath == null) {
			return null;
		}
		return projectBasePath + tempFolder;
	}
	VirtualFile imlDir = imlVirtFile.getParent();
	if (imlDir == null) {
		return null;
	}
	return imlDir.getPath() + tempFolder;
}
 
Example 4
Source Project: reasonml-idea-plugin   File: Platform.java    License: MIT License 5 votes vote down vote up
@Nullable
public static VirtualFile findFileByRelativePath(@NotNull Project project, @NotNull String path) {
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        VirtualFile moduleFile = module.getModuleFile();
        VirtualFile baseDir = moduleFile == null ? null : moduleFile.getParent();
        VirtualFile file = baseDir == null ? null : baseDir.findFileByRelativePath(path);
        if (file != null) {
            return file;
        }
    }
    return null;
}
 
Example 5
Source Project: netbeans-mmd-plugin   File: IdeaUtils.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public static VirtualFile findPotentialRootFolderForModule(@Nullable final Module module) {
  VirtualFile moduleRoot = module == null ? null : module.getModuleFile();
  if (moduleRoot != null) {
    moduleRoot = moduleRoot.isDirectory() ? moduleRoot : moduleRoot.getParent();
    if (moduleRoot.getName().equals(".idea")) {
      moduleRoot = moduleRoot.getParent();
    }
  }
  return moduleRoot;
}
 
Example 6
Source Project: intellij-haskforce   File: GhcMod.java    License: Apache License 2.0 5 votes vote down vote up
/** Infers the absolute path given a relative one and its enclosing module. */
@Nullable
private static String inferAbsolutePath(@NotNull Module module, @NotNull String path) {
    File file = new File(path);
    if (file.exists()) return file.getAbsolutePath();
    final VirtualFile moduleFile = module.getModuleFile();
    if (moduleFile == null) return null;
    final String inferredPath = FileUtil.join(moduleFile.getParent().getCanonicalPath(), path);
    if (new File(inferredPath).exists()) return inferredPath;
    return null;
}
 
Example 7
Source Project: intellij-haskforce   File: ExecUtil.java    License: Apache License 2.0 5 votes vote down vote up
@NotNull
public static String guessWorkDir(@NotNull Module module) {
    final VirtualFile moduleFile = module.getModuleFile();
    final VirtualFile moduleDir = moduleFile == null ? null : moduleFile.getParent();
    if (moduleDir != null) return moduleDir.getPath();
    return getProjectPath(module.getProject());
}
 
Example 8
Source Project: intellij-haxe   File: HaxeCompiler.java    License: Apache License 2.0 5 votes vote down vote up
private static int findProcessingItemIndexByModule(ProcessingItem[] items, RunConfigurationModule moduleConfiguration) {
  final Module module = moduleConfiguration.getModule();
  if (module == null || module.getModuleFile() == null) {
    return -1;
  }
  for (int i = 0; i < items.length; ++i) {
    if (module.getModuleFile().equals(items[i].getFile())) {
      return i;
    }
  }
  return -1;
}
 
Example 9
@Override
public VirtualFile getModuleDirForFile(VirtualFile virtualFile, Project project) {
	Module moduleForFile = ModuleUtil.findModuleForFile(virtualFile, project);
	if (moduleForFile != null) {
		VirtualFile moduleFile = moduleForFile.getModuleFile();
		if (moduleFile != null) {
			return moduleFile.getParent();
		}
	}
	return null;
}
 
Example 10
Source Project: CppTools   File: CppCompiler.java    License: Apache License 2.0 5 votes vote down vote up
@NotNull
public ProcessingItem[] getProcessingItems(final CompileContext compileContext) {
  final List<ProcessingItem> processingItems = new ArrayList<ProcessingItem>();
  boolean doneSave = false;

  Module[] affectedModules = ApplicationManager.getApplication().runReadAction(new Computable<Module[]>() {
    public Module[] compute() {
      return compileContext.getCompileScope().getAffectedModules();
    }
  });

  for(Module module: affectedModules) {
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (ModuleType.get(module) == CppModuleType.getInstance() ||
       (sdk != null && sdk.getSdkType() == CppSdkType.getInstance())) {
      processingItems.add(new MyProcessingItem(module));

      if (!doneSave) {
        BuildState.saveDocuments();
        doneSave = true;
      }

      VirtualFile moduleFile = module.getModuleFile();
      if (moduleFile == null) {
        BuildState.saveAll();
      }
    }
  }
  return processingItems.toArray(new ProcessingItem[processingItems.size()]);
}