Search in sources :

Example 21 with Module

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

the class PydevConsoleRunner method findPythonSdkAndModule.

@NotNull
static Pair<Sdk, Module> findPythonSdkAndModule(@NotNull Project project, @Nullable Module contextModule) {
    Sdk sdk = null;
    Module module = null;
    PyConsoleOptions.PyConsoleSettings settings = PyConsoleOptions.getInstance(project).getPythonConsoleSettings();
    String sdkHome = settings.getSdkHome();
    if (sdkHome != null) {
        sdk = PythonSdkType.findSdkByPath(sdkHome);
        if (settings.getModuleName() != null) {
            module = ModuleManager.getInstance(project).findModuleByName(settings.getModuleName());
        } else {
            module = contextModule;
            if (module == null && ModuleManager.getInstance(project).getModules().length > 0) {
                module = ModuleManager.getInstance(project).getModules()[0];
            }
        }
    }
    if (sdk == null && settings.isUseModuleSdk()) {
        if (contextModule != null) {
            module = contextModule;
        } else if (settings.getModuleName() != null) {
            module = ModuleManager.getInstance(project).findModuleByName(settings.getModuleName());
        }
        if (module != null) {
            if (PythonSdkType.findPythonSdk(module) != null) {
                sdk = PythonSdkType.findPythonSdk(module);
            }
        }
    } else if (contextModule != null) {
        if (module == null) {
            module = contextModule;
        }
        if (sdk == null) {
            sdk = PythonSdkType.findPythonSdk(module);
        }
    }
    if (sdk == null) {
        for (Module m : ModuleManager.getInstance(project).getModules()) {
            if (PythonSdkType.findPythonSdk(m) != null) {
                sdk = PythonSdkType.findPythonSdk(m);
                module = m;
                break;
            }
        }
    }
    if (sdk == null) {
        if (PythonSdkType.getAllSdks().size() > 0) {
            //noinspection UnusedAssignment
            //take any python sdk
            sdk = PythonSdkType.getAllSdks().get(0);
        }
    }
    return Pair.create(sdk, module);
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with Module

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

the class Py3UnresolvedReferencesInspectionTest method doMultiFileTest.

private void doMultiFileTest(@NotNull final String filename, @NotNull List<String> sourceRoots) {
    runWithLanguageLevel(LanguageLevel.PYTHON36, () -> {
        final String testName = getTestName(false);
        myFixture.copyDirectoryToProject(TEST_DIRECTORY + testName, "");
        final Module module = myFixture.getModule();
        for (String root : sourceRoots) {
            PsiTestUtil.addSourceRoot(module, myFixture.findFileInTempDir(root));
        }
        try {
            myFixture.configureFromTempProjectFile(filename);
            myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
            myFixture.checkHighlighting(true, false, false);
        } finally {
            for (String root : sourceRoots) {
                PsiTestUtil.removeSourceRoot(module, myFixture.findFileInTempDir(root));
            }
        }
    });
}
Also used : Module(com.intellij.openapi.module.Module)

Example 23 with Module

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

the class HtmlFileReferenceHelper method getContexts.

@NotNull
@Override
public Collection<PsiFileSystemItem> getContexts(Project project, @NotNull VirtualFile vFile) {
    final PsiFile file = PsiManager.getInstance(project).findFile(vFile);
    final Module module = file != null ? ModuleUtilCore.findModuleForPsiElement(file) : null;
    if (module == null || !(file instanceof XmlFile))
        return Collections.emptyList();
    final String basePath = HtmlUtil.getHrefBase((XmlFile) file);
    if (basePath != null && !HtmlUtil.hasHtmlPrefix(basePath)) {
        for (VirtualFile virtualFile : getBaseRoots(module)) {
            final VirtualFile base = virtualFile.findFileByRelativePath(basePath);
            final PsiDirectory result = base != null ? PsiManager.getInstance(project).findDirectory(base) : null;
            if (result != null) {
                return Collections.<PsiFileSystemItem>singletonList(result);
            }
        }
    }
    return Collections.emptyList();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with Module

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

the class TargetPlatformDetector method getPlatform.

public static TargetPlatform getPlatform(@NotNull PsiFile file) {
    VirtualFile virtualFile = file.getOriginalFile().getVirtualFile();
    if (virtualFile == null) {
        return getDefaultPlatform(file);
    }
    Module moduleForFile = ProjectFileIndex.SERVICE.getInstance(file.getProject()).getModuleForFile(virtualFile);
    if (moduleForFile == null) {
        return getDefaultPlatform(file);
    }
    return getPlatform(moduleForFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Module(com.intellij.openapi.module.Module)

Example 25 with Module

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

the class KotlinTestNgConfigurationProducer method configure.

private boolean configure(TestNGConfiguration configuration, Location location, ConfigurationContext context, Project project, @Nullable PsiClass delegate, @Nullable PsiMethod method) {
    if (delegate == null) {
        return false;
    }
    setupConfigurationModule(context, configuration);
    Module originalModule = configuration.getConfigurationModule().getModule();
    configuration.setClassConfiguration(delegate);
    if (method != null) {
        configuration.setMethodConfiguration(PsiLocation.fromPsiElement(project, method));
    }
    configuration.restoreOriginalModule(originalModule);
    configuration.setName(configuration.getName());
    JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, location);
    return true;
}
Also used : Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)1911 VirtualFile (com.intellij.openapi.vfs.VirtualFile)585 Project (com.intellij.openapi.project.Project)381 NotNull (org.jetbrains.annotations.NotNull)331 Nullable (org.jetbrains.annotations.Nullable)268 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