Search in sources :

Example 6 with JdkOrderEntry

use of com.intellij.openapi.roots.JdkOrderEntry in project android by JetBrains.

the class AndroidSdkResolveScopeProvider method getResolveScope.

@Nullable
@Override
public GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project) {
    if (!ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID))
        return null;
    ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    JdkOrderEntry entry = ContainerUtil.findInstance(index.getOrderEntriesForFile(file), JdkOrderEntry.class);
    final Sdk sdk = entry == null ? null : entry.getJdk();
    if (sdk == null || !(sdk.getSdkType() instanceof AndroidSdkType)) {
        return null;
    }
    return new MyJdkScope(project, entry, index.isInLibrarySource(file));
}
Also used : JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) AndroidSdkType(org.jetbrains.android.sdk.AndroidSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with JdkOrderEntry

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

the class ProjectUtilCore method displayUrlRelativeToProject.

public static String displayUrlRelativeToProject(@NotNull VirtualFile file, @NotNull String url, @NotNull Project project, boolean includeFilePath, boolean keepModuleAlwaysOnTheLeft) {
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir != null && includeFilePath) {
        //noinspection ConstantConditions
        final String projectHomeUrl = baseDir.getPresentableUrl();
        if (url.startsWith(projectHomeUrl)) {
            url = "..." + url.substring(projectHomeUrl.length());
        }
    }
    if (SystemInfo.isMac && file.getFileSystem() instanceof LocalFileProvider) {
        final VirtualFile fileForJar = ((LocalFileProvider) file.getFileSystem()).getLocalVirtualFileFor(file);
        if (fileForJar != null) {
            final OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(file, project);
            if (libraryEntry != null) {
                if (libraryEntry instanceof JdkOrderEntry) {
                    url = url + " - [" + ((JdkOrderEntry) libraryEntry).getJdkName() + "]";
                } else {
                    url = url + " - [" + libraryEntry.getPresentableName() + "]";
                }
            } else {
                url = url + " - [" + fileForJar.getName() + "]";
            }
        }
    }
    final Module module = ModuleUtilCore.findModuleForFile(file, project);
    if (module == null)
        return url;
    return !keepModuleAlwaysOnTheLeft && SystemInfo.isMac ? url + " - [" + module.getName() + "]" : "[" + module.getName() + "] - " + url;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderEntry(com.intellij.openapi.roots.OrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) LocalFileProvider(com.intellij.openapi.vfs.LocalFileProvider) Module(com.intellij.openapi.module.Module)

Example 8 with JdkOrderEntry

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

the class MagicConstantInspection method checkAnnotationsJarAttached.

private static void checkAnnotationsJarAttached(@NotNull PsiFile file, @NotNull ProblemsHolder holder) {
    final Project project = file.getProject();
    if (!holder.isOnTheFly()) {
        final Boolean found = project.getUserData(NO_ANNOTATIONS_FOUND);
        if (found != null)
            return;
    }
    PsiClass event = JavaPsiFacade.getInstance(project).findClass("java.awt.event.InputEvent", GlobalSearchScope.allScope(project));
    // no jdk to attach
    if (event == null)
        return;
    PsiMethod[] methods = event.findMethodsByName("getModifiers", false);
    // no jdk to attach
    if (methods.length != 1)
        return;
    PsiMethod getModifiers = methods[0];
    PsiAnnotation annotation = ExternalAnnotationsManager.getInstance(project).findExternalAnnotation(getModifiers, MagicConstant.class.getName());
    if (annotation != null)
        return;
    final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(getModifiers);
    // no jdk to attach
    if (virtualFile == null)
        return;
    final List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(virtualFile);
    Sdk jdk = null;
    for (OrderEntry orderEntry : entries) {
        if (orderEntry instanceof JdkOrderEntry) {
            jdk = ((JdkOrderEntry) orderEntry).getJdk();
            if (jdk != null)
                break;
        }
    }
    // no jdk to attach
    if (jdk == null)
        return;
    if (!holder.isOnTheFly()) {
        project.putUserData(NO_ANNOTATIONS_FOUND, Boolean.TRUE);
    }
    final Sdk finalJdk = jdk;
    String path = finalJdk.getHomePath();
    String text = "No IDEA annotations attached to the JDK " + finalJdk.getName() + (path == null ? "" : " (" + FileUtil.toSystemDependentName(path) + ")") + ", some issues will not be found";
    holder.registerProblem(file, text, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new LocalQuickFix() {

        @NotNull
        @Override
        public String getFamilyName() {
            return "Attach annotations";
        }

        @Nullable
        @Override
        public PsiElement getElementToMakeWritable(@NotNull PsiFile file) {
            return null;
        }

        @Override
        public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
            SdkModificator modificator = finalJdk.getSdkModificator();
            JavaSdkImpl.attachJdkAnnotations(modificator);
            modificator.commitChanges();
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MagicConstant(org.intellij.lang.annotations.MagicConstant) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) Sdk(com.intellij.openapi.projectRoots.Sdk) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with JdkOrderEntry

use of com.intellij.openapi.roots.JdkOrderEntry 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)

Example 10 with JdkOrderEntry

use of com.intellij.openapi.roots.JdkOrderEntry 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)

Aggregations

JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)12 OrderEntry (com.intellij.openapi.roots.OrderEntry)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 Project (com.intellij.openapi.project.Project)6 Nullable (org.jetbrains.annotations.Nullable)6 Sdk (com.intellij.openapi.projectRoots.Sdk)5 Module (com.intellij.openapi.module.Module)4 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)2 NamedLibraryElementNode (com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode)2 LibraryOrSdkOrderEntry (com.intellij.openapi.roots.LibraryOrSdkOrderEntry)2 PsiDocComment (com.intellij.psi.javadoc.PsiDocComment)2 NotNull (org.jetbrains.annotations.NotNull)2 AppEngineStandardFacet (com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardFacet)1 CloudSdkInternals (com.google.cloud.tools.intellij.appengine.sdk.CloudSdkInternals)1 AppEngineFacet (com.intellij.appengine.facet.AppEngineFacet)1 AppEngineSdk (com.intellij.appengine.sdk.AppEngineSdk)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1