Search in sources :

Example 6 with SdkTypeId

use of com.intellij.openapi.projectRoots.SdkTypeId in project intellij-community by JetBrains.

the class PyBuiltinCache method getSkeletonFile.

@Nullable
private static PyFile getSkeletonFile(@NotNull final Project project, @NotNull Sdk sdk, @NotNull String name) {
    SdkTypeId sdkType = sdk.getSdkType();
    if (sdkType instanceof PythonSdkType) {
        final int index = name.indexOf(".");
        if (index != -1) {
            name = name.substring(0, index);
        }
        final List<PsiElement> results = PyResolveImportUtil.resolveQualifiedName(QualifiedName.fromComponents(name), PyResolveImportUtil.fromSdk(project, sdk));
        return as(ContainerUtil.getFirstItem(results), PyFile.class);
    }
    return null;
}
Also used : SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) PythonSdkType(com.jetbrains.python.sdk.PythonSdkType) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with SdkTypeId

use of com.intellij.openapi.projectRoots.SdkTypeId in project intellij-community by JetBrains.

the class PyTreeStructureProvider method getPythonSdk.

@Nullable
private static Sdk getPythonSdk(@NotNull AbstractTreeNode node) {
    if (node instanceof NamedLibraryElementNode) {
        final NamedLibraryElement value = ((NamedLibraryElementNode) node).getValue();
        if (value != null) {
            final LibraryOrSdkOrderEntry entry = value.getOrderEntry();
            if (entry instanceof JdkOrderEntry) {
                final Sdk sdk = ((JdkOrderEntry) entry).getJdk();
                final SdkTypeId type = sdk.getSdkType();
                if (type instanceof PythonSdkType) {
                    return sdk;
                }
            }
        }
    }
    return null;
}
Also used : NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) LibraryOrSdkOrderEntry(com.intellij.openapi.roots.LibraryOrSdkOrderEntry) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) PythonSdkType(com.jetbrains.python.sdk.PythonSdkType) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with SdkTypeId

use of com.intellij.openapi.projectRoots.SdkTypeId in project intellij-elixir by KronicDeth.

the class MixExUnitRunConfigurationProducer method setupConfigurationFromContextImpl.

private boolean setupConfigurationFromContextImpl(@NotNull MixExUnitRunConfiguration configuration, @NotNull PsiElement psiElement) {
    boolean contextApplicable = false;
    if (psiElement instanceof PsiDirectory) {
        PsiDirectory psiDirectory = (PsiDirectory) psiElement;
        Module module = ModuleUtilCore.findModuleForPsiElement(psiDirectory);
        Sdk sdk;
        if (module != null) {
            ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
            sdk = moduleRootManager.getSdk();
        } else {
            ProjectRootManager projectRootManager = ProjectRootManager.getInstance(psiDirectory.getProject());
            sdk = projectRootManager.getProjectSdk();
        }
        SdkTypeId sdkTypeId = null;
        if (sdk != null) {
            sdkTypeId = sdk.getSdkType();
        }
        if ((sdkTypeId == null || sdkTypeId.equals(ElixirSdkType.getInstance())) && ProjectRootsUtil.isInTestSource(psiDirectory.getVirtualFile(), psiDirectory.getProject())) {
            String basePath = psiElement.getProject().getBasePath();
            String workingDirectory = workingDirectory(psiElement, basePath);
            configuration.setWorkingDirectory(workingDirectory);
            PsiDirectory dir = (PsiDirectory) psiElement;
            configuration.setName(configurationName(dir, workingDirectory, basePath));
            configuration.setProgramParameters(programParameters(dir, workingDirectory));
            contextApplicable = true;
        }
    } else {
        PsiFile containingFile = psiElement.getContainingFile();
        if (!(containingFile instanceof ElixirFile || containingFile instanceof PsiDirectory))
            return false;
        if (ProjectRootsUtil.isInTestSource(containingFile)) {
            String basePath = psiElement.getProject().getBasePath();
            String workingDirectory = workingDirectory(psiElement, basePath);
            configuration.setWorkingDirectory(workingDirectory);
            int lineNumber = lineNumber(psiElement);
            configuration.setName(configurationName(containingFile, lineNumber, workingDirectory, basePath));
            configuration.setProgramParameters(programParameters(containingFile, lineNumber, workingDirectory));
            contextApplicable = true;
        }
    }
    return contextApplicable;
}
Also used : ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) ElixirFile(org.elixir_lang.psi.ElixirFile)

Aggregations

SdkTypeId (com.intellij.openapi.projectRoots.SdkTypeId)8 Sdk (com.intellij.openapi.projectRoots.Sdk)7 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)3 Nullable (org.jetbrains.annotations.Nullable)3 CantRunException (com.intellij.execution.CantRunException)2 Module (com.intellij.openapi.module.Module)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PythonSdkType (com.jetbrains.python.sdk.PythonSdkType)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ApplicationConfiguration (com.intellij.execution.application.ApplicationConfiguration)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 ParametersList (com.intellij.execution.configurations.ParametersList)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)1 NamedLibraryElementNode (com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode)1 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)1 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)1 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)1 LibraryOrSdkOrderEntry (com.intellij.openapi.roots.LibraryOrSdkOrderEntry)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1