Search in sources :

Example 6 with OrderEntry

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

the class GradleScriptType method patchResolveScopeInner.

public GlobalSearchScope patchResolveScopeInner(@Nullable Module module, @NotNull GlobalSearchScope baseScope) {
    if (module == null)
        return GlobalSearchScope.EMPTY_SCOPE;
    if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
        return baseScope;
    GlobalSearchScope result = GlobalSearchScope.EMPTY_SCOPE;
    final Project project = module.getProject();
    for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
        if (entry instanceof JdkOrderEntry) {
            GlobalSearchScope scopeForSdk = LibraryScopeCache.getInstance(project).getScopeForSdk((JdkOrderEntry) entry);
            result = result.uniteWith(scopeForSdk);
        }
    }
    String modulePath = ExternalSystemApiUtil.getExternalProjectPath(module);
    if (modulePath == null)
        return result;
    final Collection<VirtualFile> files = GradleBuildClasspathManager.getInstance(project).getModuleClasspathEntries(modulePath);
    result = new ExternalModuleBuildGlobalSearchScope(project, result.uniteWith(new NonClasspathDirectoriesScope(files)), modulePath);
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonClasspathDirectoriesScope(com.intellij.psi.search.NonClasspathDirectoriesScope) Project(com.intellij.openapi.project.Project) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ExternalModuleBuildGlobalSearchScope(com.intellij.openapi.externalSystem.psi.search.ExternalModuleBuildGlobalSearchScope) ExternalModuleBuildGlobalSearchScope(com.intellij.openapi.externalSystem.psi.search.ExternalModuleBuildGlobalSearchScope)

Example 7 with OrderEntry

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

the class ModuleDependencyDataService method importData.

@Override
protected Map<OrderEntry, OrderAware> importData(@NotNull final Collection<DataNode<ModuleDependencyData>> toImport, @NotNull final Module module, @NotNull final IdeModifiableModelsProvider modelsProvider) {
    final Map<Pair<String, DependencyScope>, ModuleOrderEntry> /* dependency module scope */
    toRemove = ContainerUtilRt.newHashMap();
    final Map<OrderEntry, OrderAware> orderEntryDataMap = ContainerUtil.newLinkedHashMap();
    for (OrderEntry entry : modelsProvider.getOrderEntries(module)) {
        if (entry instanceof ModuleOrderEntry) {
            ModuleOrderEntry e = (ModuleOrderEntry) entry;
            toRemove.put(Pair.create(e.getModuleName(), e.getScope()), e);
        }
    }
    final Set<ModuleDependencyData> processed = ContainerUtil.newHashSet();
    final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
    for (DataNode<ModuleDependencyData> dependencyNode : toImport) {
        final ModuleDependencyData dependencyData = dependencyNode.getData();
        if (processed.contains(dependencyData))
            continue;
        processed.add(dependencyData);
        toRemove.remove(Pair.create(dependencyData.getInternalName(), dependencyData.getScope()));
        final ModuleData moduleData = dependencyData.getTarget();
        Module ideDependencyModule = modelsProvider.findIdeModule(moduleData);
        ModuleOrderEntry orderEntry;
        if (module.equals(ideDependencyModule)) {
            // skip recursive module dependency check
            continue;
        } else {
            if (ideDependencyModule == null) {
                LOG.warn(String.format("Can't import module dependency for '%s' module. Reason: target module (%s) is not found at the ide", module.getName(), dependencyData));
            }
            orderEntry = modelsProvider.findIdeModuleDependency(dependencyData, module);
            if (orderEntry == null) {
                orderEntry = ReadAction.compute(() -> ideDependencyModule == null ? modifiableRootModel.addInvalidModuleEntry(moduleData.getInternalName()) : modifiableRootModel.addModuleOrderEntry(ideDependencyModule));
            }
        }
        orderEntry.setScope(dependencyData.getScope());
        orderEntry.setExported(dependencyData.isExported());
        final boolean productionOnTestDependency = dependencyData.isProductionOnTestDependency();
        if (orderEntry instanceof ModuleOrderEntryImpl) {
            ((ModuleOrderEntryImpl) orderEntry).setProductionOnTestDependency(productionOnTestDependency);
        } else if (productionOnTestDependency) {
            LOG.warn("Unable to set productionOnTestDependency for entry: " + orderEntry);
        }
        orderEntryDataMap.put(orderEntry, dependencyData);
    }
    if (!toRemove.isEmpty()) {
        removeData(toRemove.values(), module, modelsProvider);
    }
    return orderEntryDataMap;
}
Also used : ModuleOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleOrderEntryImpl) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) OrderAware(com.intellij.openapi.externalSystem.model.project.OrderAware) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) Module(com.intellij.openapi.module.Module) ModuleDependencyData(com.intellij.openapi.externalSystem.model.project.ModuleDependencyData) Pair(com.intellij.openapi.util.Pair)

Example 8 with OrderEntry

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

the class DocumentationManager method navigateByLink.

void navigateByLink(final DocumentationComponent component, final String url) {
    component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    final PsiElement psiElement = component.getElement();
    if (psiElement == null) {
        return;
    }
    final PsiManager manager = PsiManager.getInstance(getProject(psiElement));
    if (url.startsWith("open")) {
        final PsiFile containingFile = psiElement.getContainingFile();
        OrderEntry libraryEntry = null;
        if (containingFile != null) {
            final VirtualFile virtualFile = containingFile.getVirtualFile();
            libraryEntry = LibraryUtil.findLibraryEntry(virtualFile, myProject);
        } else if (psiElement instanceof PsiDirectoryContainer) {
            PsiDirectory[] directories = ((PsiDirectoryContainer) psiElement).getDirectories();
            for (PsiDirectory directory : directories) {
                final VirtualFile virtualFile = directory.getVirtualFile();
                libraryEntry = LibraryUtil.findLibraryEntry(virtualFile, myProject);
                if (libraryEntry != null) {
                    break;
                }
            }
        }
        if (libraryEntry != null) {
            ProjectSettingsService.getInstance(myProject).openLibraryOrSdkSettings(libraryEntry);
        }
    } else if (url.startsWith(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL)) {
        String refText = url.substring(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL.length());
        int separatorPos = refText.lastIndexOf(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL_REF_SEPARATOR);
        String ref = null;
        if (separatorPos >= 0) {
            ref = refText.substring(separatorPos + DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL_REF_SEPARATOR.length());
            refText = refText.substring(0, separatorPos);
        }
        DocumentationProvider provider = getProviderFromElement(psiElement);
        PsiElement targetElement = provider.getDocumentationElementForLink(manager, refText, psiElement);
        if (targetElement == null) {
            for (DocumentationProvider documentationProvider : Extensions.getExtensions(DocumentationProvider.EP_NAME)) {
                targetElement = documentationProvider.getDocumentationElementForLink(manager, refText, psiElement);
                if (targetElement != null) {
                    break;
                }
            }
        }
        if (targetElement == null) {
            for (Language language : Language.getRegisteredLanguages()) {
                DocumentationProvider documentationProvider = LanguageDocumentation.INSTANCE.forLanguage(language);
                if (documentationProvider != null) {
                    targetElement = documentationProvider.getDocumentationElementForLink(manager, refText, psiElement);
                    if (targetElement != null) {
                        break;
                    }
                }
            }
        }
        if (targetElement != null) {
            fetchDocInfo(getDefaultCollector(targetElement, null, ref), component);
        }
    } else {
        final DocumentationProvider provider = getProviderFromElement(psiElement);
        boolean processed = false;
        if (provider instanceof CompositeDocumentationProvider) {
            for (DocumentationProvider p : ((CompositeDocumentationProvider) provider).getAllProviders()) {
                if (!(p instanceof ExternalDocumentationHandler))
                    continue;
                final ExternalDocumentationHandler externalHandler = (ExternalDocumentationHandler) p;
                if (externalHandler.canFetchDocumentationLink(url)) {
                    fetchDocInfo(new DocumentationCollector() {

                        @Override
                        public String getDocumentation() throws Exception {
                            return externalHandler.fetchExternalDocumentation(url, psiElement);
                        }

                        @Override
                        public PsiElement getElement() {
                            return psiElement;
                        }

                        @Nullable
                        @Override
                        public String getEffectiveExternalUrl() {
                            return url;
                        }

                        @Nullable
                        @Override
                        public String getRef() {
                            return null;
                        }
                    }, component);
                    processed = true;
                } else if (externalHandler.handleExternalLink(manager, url, psiElement)) {
                    processed = true;
                    break;
                }
            }
        }
        if (!processed) {
            fetchDocInfo(new DocumentationCollector() {

                @Override
                public String getDocumentation() throws Exception {
                    if (BrowserUtil.isAbsoluteURL(url)) {
                        BrowserUtil.browse(url);
                        return "";
                    } else {
                        return CodeInsightBundle.message("javadoc.error.resolving.url", url);
                    }
                }

                @Override
                public PsiElement getElement() {
                    return psiElement;
                }

                @Nullable
                @Override
                public String getEffectiveExternalUrl() {
                    return url;
                }

                @Nullable
                @Override
                public String getRef() {
                    return null;
                }
            }, component);
        }
    }
    component.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderEntry(com.intellij.openapi.roots.OrderEntry) Language(com.intellij.lang.Language)

Example 9 with OrderEntry

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

the class LibraryEditingUtil method getNotAddedSuitableLibrariesCondition.

public static Predicate<Library> getNotAddedSuitableLibrariesCondition(final ModuleRootModel rootModel, final FacetsProvider facetsProvider) {
    final OrderEntry[] orderEntries = rootModel.getOrderEntries();
    final Set<Library> result = new HashSet<>(orderEntries.length);
    for (OrderEntry orderEntry : orderEntries) {
        if (orderEntry instanceof LibraryOrderEntry && orderEntry.isValid()) {
            final LibraryImpl library = (LibraryImpl) ((LibraryOrderEntry) orderEntry).getLibrary();
            if (library != null) {
                final Library source = library.getSource();
                result.add(source != null ? source : library);
            }
        }
    }
    return new Predicate<Library>() {

        @Override
        public boolean apply(Library library) {
            if (result.contains(library))
                return false;
            if (library instanceof LibraryImpl) {
                final Library source = ((LibraryImpl) library).getSource();
                if (source != null && result.contains(source))
                    return false;
            }
            PersistentLibraryKind<?> kind = ((LibraryEx) library).getKind();
            if (kind != null) {
                LibraryType type = LibraryType.findByKind(kind);
                if (type != null && !type.isSuitableModule(rootModel.getModule(), facetsProvider)) {
                    return false;
                }
            }
            return true;
        }
    };
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) LibraryImpl(com.intellij.openapi.roots.impl.libraries.LibraryImpl) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Predicate(com.intellij.util.containers.Predicate)

Example 10 with OrderEntry

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

the class ModuleSourceItemGroup method collectDependentModules.

private static void collectDependentModules(final Module module, Set<Module> modules, ArtifactEditorContext context) {
    if (!modules.add(module))
        return;
    for (OrderEntry entry : context.getModulesProvider().getRootModel(module).getOrderEntries()) {
        if (entry instanceof ModuleOrderEntry) {
            final ModuleOrderEntry moduleEntry = (ModuleOrderEntry) entry;
            final Module dependency = moduleEntry.getModule();
            final DependencyScope scope = moduleEntry.getScope();
            if (dependency != null && scope.isForProductionRuntime()) {
                collectDependentModules(dependency, modules, context);
            }
        }
    }
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) DependencyScope(com.intellij.openapi.roots.DependencyScope) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) Module(com.intellij.openapi.module.Module)

Aggregations

OrderEntry (com.intellij.openapi.roots.OrderEntry)54 Module (com.intellij.openapi.module.Module)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)18 Project (com.intellij.openapi.project.Project)14 Library (com.intellij.openapi.roots.libraries.Library)12 ArrayList (java.util.ArrayList)11 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)10 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)10 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)8 ModuleOrderEntry (com.intellij.openapi.roots.ModuleOrderEntry)8 Nullable (org.jetbrains.annotations.Nullable)8 NotNull (org.jetbrains.annotations.NotNull)7 ModuleLibraryOrderEntryImpl (com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl)5 List (java.util.List)5 Sdk (com.intellij.openapi.projectRoots.Sdk)4 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)4 AccessToken (com.intellij.openapi.application.AccessToken)3 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)3 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3