Search in sources :

Example 6 with ModuleLibraryOrderEntryImpl

use of com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl in project intellij-community by JetBrains.

the class PyBuiltinCache method findSdkForNonModuleFile.

@Nullable
public static Sdk findSdkForNonModuleFile(PsiFileSystemItem psiFile) {
    Project project = psiFile.getProject();
    Sdk sdk = null;
    final VirtualFile vfile = psiFile instanceof PsiFile ? ((PsiFile) psiFile).getOriginalFile().getVirtualFile() : psiFile.getVirtualFile();
    if (vfile != null) {
        // reality
        final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
        sdk = projectRootManager.getProjectSdk();
        if (sdk == null) {
            final List<OrderEntry> orderEntries = projectRootManager.getFileIndex().getOrderEntriesForFile(vfile);
            for (OrderEntry orderEntry : orderEntries) {
                if (orderEntry instanceof JdkOrderEntry) {
                    sdk = ((JdkOrderEntry) orderEntry).getJdk();
                } else if (orderEntry instanceof ModuleLibraryOrderEntryImpl) {
                    sdk = PythonSdkType.findPythonSdk(orderEntry.getOwnerModule());
                }
            }
        }
    }
    return sdk;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OrderEntry(com.intellij.openapi.roots.OrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ModuleLibraryOrderEntryImpl (com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl)6 OrderEntry (com.intellij.openapi.roots.OrderEntry)5 AccessToken (com.intellij.openapi.application.AccessToken)3 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)3 Library (com.intellij.openapi.roots.libraries.Library)3 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)2 LibrariesContainer (com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)1 ModuleRootModel (com.intellij.openapi.roots.ModuleRootModel)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1 LibraryImpl (com.intellij.openapi.roots.impl.libraries.LibraryImpl)1 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)1 DefaultDialogWrapper (com.microsoft.intellij.ui.components.DefaultDialogWrapper)1 Nullable (org.jetbrains.annotations.Nullable)1