Search in sources :

Example 21 with OrderEntry

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

the class SourceNavigationHelper method filterByOrderEntries.

@NotNull
private static List<KtNamedDeclaration> filterByOrderEntries(@NotNull KtNamedDeclaration declaration, @NotNull Collection<KtNamedDeclaration> candidates) {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(declaration.getProject()).getFileIndex();
    final List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(declaration.getContainingFile().getVirtualFile());
    return CollectionsKt.filter(candidates, new Function1<KtNamedDeclaration, Boolean>() {

        @Override
        public Boolean invoke(KtNamedDeclaration candidate) {
            List<OrderEntry> candidateOrderEntries = fileIndex.getOrderEntriesForFile(candidate.getContainingFile().getVirtualFile());
            return ContainerUtil.intersects(orderEntries, candidateOrderEntries);
        }
    });
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with OrderEntry

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

the class FrameworksCompatibilityUtils method suggestRemoveIncompatibleFramework.

public static void suggestRemoveIncompatibleFramework(@NotNull ModifiableRootModel rootModel, @NotNull Set<? extends LibraryKind> frameworkLibraryKinds, @NotNull FrameworkType frameworkType) {
    List<OrderEntry> existingEntries = new ArrayList<OrderEntry>();
    for (OrderEntry entry : rootModel.getOrderEntries()) {
        if (!(entry instanceof LibraryOrderEntry))
            continue;
        Library library = ((LibraryOrderEntry) entry).getLibrary();
        if (library == null)
            continue;
        for (LibraryKind kind : frameworkLibraryKinds) {
            if (LibraryPresentationManager.getInstance().isLibraryOfKind(Arrays.asList(library.getFiles(OrderRootType.CLASSES)), kind)) {
                existingEntries.add(entry);
            }
        }
    }
    removeWithConfirm(rootModel, existingEntries, String.format("Current module is already configured with '%s' framework.\nDo you want to remove it?", frameworkType.getPresentableName()), "Framework Conflict");
}
Also used : LibraryKind(com.intellij.openapi.roots.libraries.LibraryKind) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) ArrayList(java.util.ArrayList) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library)

Example 23 with OrderEntry

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

the class FrameworksCompatibilityUtils method suggestRemoveOldJsLibrary.

public static void suggestRemoveOldJsLibrary(@NotNull ModifiableRootModel rootModel) {
    List<OrderEntry> oldJsLibraries = new ArrayList<OrderEntry>();
    for (OrderEntry entry : rootModel.getOrderEntries()) {
        if (!(entry instanceof LibraryOrderEntry))
            continue;
        Library library = ((LibraryOrderEntry) entry).getLibrary();
        if (library == null)
            continue;
        if (JSLibraryStdPresentationProvider.detectOld(library)) {
            oldJsLibraries.add(entry);
        }
    }
    removeWithConfirm(rootModel, oldJsLibraries, "Current module is configured with old js library.\nDo you want to remove it?", "Old JS Library");
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) ArrayList(java.util.ArrayList) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library)

Example 24 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsPanel method configureAzureSDK.

private void configureAzureSDK() {
    final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
    for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
        if (orderEntry instanceof ModuleLibraryOrderEntryImpl && AzureLibrary.APP_INSIGHTS.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
            return;
        }
    }
    final LibrariesContainer.LibraryLevel level = LibrariesContainer.LibraryLevel.MODULE;
    AccessToken token = WriteAction.start();
    try {
        Library newLibrary = LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(AzureLibrary.APP_INSIGHTS.getName(), level, new ArrayList<OrderRoot>());
        for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
            if (orderEntry instanceof ModuleLibraryOrderEntryImpl && AzureLibrary.APP_INSIGHTS.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
                ((ModuleLibraryOrderEntryImpl) orderEntry).setExported(true);
                break;
            }
        }
        Library.ModifiableModel newLibraryModel = newLibrary.getModifiableModel();
        AddLibraryUtility.addLibraryFiles(new File(PluginHelper.getAzureLibLocation()), newLibraryModel, AzureLibrary.APP_INSIGHTS.getFiles());
        newLibraryModel.commit();
        modifiableModel.commit();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        token.finish();
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) AccessToken(com.intellij.openapi.application.AccessToken) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) LibrariesContainer(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Library(com.intellij.openapi.roots.libraries.Library) File(java.io.File)

Example 25 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project azure-tools-for-java by Microsoft.

the class LibrariesConfigurationDialog method editLibrary.

private void editLibrary() {
    AzureLibrary azureLibrary = (AzureLibrary) librariesList.getSelectedValue();
    final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
    OrderEntry libraryOrderEntry = null;
    for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
        if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
            libraryOrderEntry = orderEntry;
            break;
        }
    }
    if (libraryOrderEntry != null) {
        LibraryPropertiesPanel libraryPropertiesPanel = new LibraryPropertiesPanel(module, azureLibrary, true, ((ModuleLibraryOrderEntryImpl) libraryOrderEntry).isExported());
        DefaultDialogWrapper libraryProperties = new DefaultDialogWrapper(module.getProject(), libraryPropertiesPanel);
        libraryProperties.show();
        if (libraryProperties.isOK()) {
            AccessToken token = WriteAction.start();
            try {
                ((ModuleLibraryOrderEntryImpl) libraryOrderEntry).setExported(libraryPropertiesPanel.isExported());
                modifiableModel.commit();
            } finally {
                token.finish();
            }
            LocalFileSystem.getInstance().findFileByPath(PluginUtil.getModulePath(module)).refresh(true, true);
        }
    } else {
        PluginUtil.displayInfoDialog("Library not found", "Library was not found");
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) AccessToken(com.intellij.openapi.application.AccessToken) DefaultDialogWrapper(com.microsoft.intellij.ui.components.DefaultDialogWrapper) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl)

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