Search in sources :

Example 91 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class PythonSdkUpdater method filterRootPaths.

/**
   * Filters valid paths from an initial set of Python paths and returns them as virtual files.
   */
@NotNull
public static List<VirtualFile> filterRootPaths(@NotNull Sdk sdk, @NotNull List<String> paths, @Nullable Project project) {
    final PythonSdkAdditionalData pythonAdditionalData = PyUtil.as(sdk.getSdkAdditionalData(), PythonSdkAdditionalData.class);
    final Collection<VirtualFile> excludedPaths = pythonAdditionalData != null ? pythonAdditionalData.getExcludedPathFiles() : Collections.emptyList();
    final Set<VirtualFile> moduleRoots = new HashSet<>();
    if (project != null) {
        final Module[] modules = ModuleManager.getInstance(project).getModules();
        for (Module module : modules) {
            moduleRoots.addAll(PyUtil.getSourceRoots(module));
        }
    }
    final List<VirtualFile> results = Lists.newArrayList();
    for (String path : paths) {
        if (path != null && !FileUtilRt.extensionEquals(path, "egg-info")) {
            final VirtualFile virtualFile = StandardFileSystems.local().refreshAndFindFileByPath(path);
            if (virtualFile != null) {
                final VirtualFile rootFile = PythonSdkType.getSdkRootVirtualFile(virtualFile);
                if (!excludedPaths.contains(rootFile) && !moduleRoots.contains(rootFile)) {
                    results.add(rootFile);
                    continue;
                }
            }
        }
        LOG.info("Bogus sys.path entry " + path);
    }
    return results;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 92 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class PythonDocTestConfigurationProducer method isAvailable.

protected boolean isAvailable(@NotNull final Location location) {
    final Module module = location.getModule();
    if (!isPythonModule(module))
        return false;
    final PsiElement element = location.getPsiElement();
    if (element instanceof PsiFile) {
        final PyDocTestVisitor visitor = new PyDocTestVisitor();
        element.accept(visitor);
        return visitor.hasTests;
    } else
        return true;
}
Also used : PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 93 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class PythonNoseTestConfigurationProducer method isAvailable.

protected boolean isAvailable(@NotNull final Location location) {
    final PsiElement element = location.getPsiElement();
    Module module = location.getModule();
    if (module == null) {
        final Module[] modules = ModuleManager.getInstance(location.getProject()).getModules();
        if (modules.length == 0)
            return false;
        module = modules[0];
    }
    final Sdk sdk = PythonSdkType.findPythonSdk(module);
    return (PythonTestConfigurationsModel.PYTHONS_NOSETEST_NAME.equals(TestRunnerService.getInstance(module).getProjectConfiguration()) && sdk != null);
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 94 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class PyTestConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(AbstractPythonLegacyTestRunConfiguration<PyTestRunConfiguration> configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final PsiElement element = sourceElement.get();
    final Module module = ModuleUtilCore.findModuleForPsiElement(element);
    if (!(configuration instanceof PyTestRunConfiguration)) {
        return false;
    }
    if (module == null) {
        return false;
    }
    if (!(TestRunnerService.getInstance(module).getProjectConfiguration().equals(PythonTestConfigurationsModel.PY_TEST_NAME))) {
        return false;
    }
    final PsiFileSystemItem file = element instanceof PsiDirectory ? (PsiDirectory) element : element.getContainingFile();
    if (file == null) {
        return false;
    }
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) {
        return false;
    }
    if (file instanceof PyFile || file instanceof PsiDirectory) {
        final List<PyStatement> testCases = PyTestUtil.getPyTestCasesFromFile(file, TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()));
        if (testCases.isEmpty()) {
            return false;
        }
    } else {
        return false;
    }
    final Sdk sdk = PythonSdkType.findPythonSdk(context.getModule());
    if (sdk == null) {
        return false;
    }
    configuration.setUseModuleSdk(true);
    configuration.setModule(ModuleUtilCore.findModuleForPsiElement(element));
    ((PyTestRunConfiguration) configuration).setTestToRun(virtualFile.getPath());
    final String keywords = getKeywords(element, sdk);
    if (keywords != null) {
        ((PyTestRunConfiguration) configuration).useKeyword(true);
        ((PyTestRunConfiguration) configuration).setKeywords(keywords);
        configuration.setName("py.test in " + keywords);
    } else {
        configuration.setName("py.test in " + file.getName());
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PyStatement(com.jetbrains.python.psi.PyStatement) PsiDirectory(com.intellij.psi.PsiDirectory) PyFile(com.jetbrains.python.psi.PyFile) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PsiElement(com.intellij.psi.PsiElement)

Example 95 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class ConfigFilesTreeBuilder method buildTree.

public Set<PsiFile> buildTree(DefaultMutableTreeNode root, ConfigFileSearcher... searchers) {
    final Set<PsiFile> psiFiles = new com.intellij.util.containers.HashSet<>();
    final MultiMap<Module, PsiFile> files = new MultiMap<>();
    final MultiMap<VirtualFile, PsiFile> jars = new MultiMap<>();
    final MultiMap<VirtualFile, PsiFile> virtualFiles = new MultiMap<>();
    for (ConfigFileSearcher searcher : searchers) {
        files.putAllValues(searcher.getFilesByModules());
        jars.putAllValues(searcher.getJars());
        virtualFiles.putAllValues(searcher.getVirtualFiles());
    }
    psiFiles.addAll(buildModuleNodes(files, jars, root));
    for (Map.Entry<VirtualFile, Collection<PsiFile>> entry : virtualFiles.entrySet()) {
        DefaultMutableTreeNode node = createFileNode(entry.getKey());
        List<PsiFile> list = new ArrayList<>(entry.getValue());
        Collections.sort(list, FILE_COMPARATOR);
        for (PsiFile file : list) {
            node.add(createFileNode(file));
        }
        root.add(node);
    }
    return psiFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MultiMap(com.intellij.util.containers.MultiMap) java.util(java.util) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) MultiMap(com.intellij.util.containers.MultiMap)

Aggregations

Module (com.intellij.openapi.module.Module)1893 VirtualFile (com.intellij.openapi.vfs.VirtualFile)585 Project (com.intellij.openapi.project.Project)379 NotNull (org.jetbrains.annotations.NotNull)330 Nullable (org.jetbrains.annotations.Nullable)267 File (java.io.File)185 PsiFile (com.intellij.psi.PsiFile)147 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)134 ArrayList (java.util.ArrayList)118 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)112 Sdk (com.intellij.openapi.projectRoots.Sdk)95 PsiElement (com.intellij.psi.PsiElement)89 PsiDirectory (com.intellij.psi.PsiDirectory)77 ModuleManager (com.intellij.openapi.module.ModuleManager)65 PsiClass (com.intellij.psi.PsiClass)65 IOException (java.io.IOException)61 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)57 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)57 List (java.util.List)57 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)51