Search in sources :

Example 46 with ModuleRootManager

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

the class ConflictSetTest method setUpModuleDependencies.

private void setUpModuleDependencies() {
    // Make module depend on myLibModule.
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(myModule);
    ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
    try {
        rootModel.addModuleOrderEntry(myLibModule);
    } finally {
        rootModel.commit();
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager)

Example 47 with ModuleRootManager

use of com.intellij.openapi.roots.ModuleRootManager in project intellij-plugins by JetBrains.

the class CodeContext method createCodeContextFromLibraries.

private static CodeContext createCodeContextFromLibraries(final String namespace, final Module module, final FlexBuildConfiguration bc) {
    final Map<String, CodeContext> contextsOfModule = new THashMap<>();
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    // If fixed - then method usage at getStdCodeContext() must be changed to make sure that all namespaces handled at that point.
    for (DependencyEntry entry : bc.getDependencies().getEntries()) {
        if (entry.getDependencyType().getLinkageType() == LinkageType.LoadInRuntime)
            continue;
        if (entry instanceof BuildConfigurationEntry) {
            final FlexBuildConfiguration bcDependency = ((BuildConfigurationEntry) entry).findBuildConfiguration();
            if (bcDependency != null && bcDependency.getOutputType() == OutputType.Library) {
                addComponentsFromManifests(module, contextsOfModule, bcDependency, true);
            }
        } else if (entry instanceof ModuleLibraryEntry) {
            final LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, rootManager);
            if (orderEntry != null) {
                for (VirtualFile file : orderEntry.getRootFiles(OrderRootType.CLASSES)) {
                    handleFileDependency(module, contextsOfModule, file);
                }
            }
        } else if (entry instanceof SharedLibraryEntry) {
            final Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
            if (library != null) {
                for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
                    handleFileDependency(module, contextsOfModule, file);
                }
            }
        }
    }
    addComponentsFromManifests(module, contextsOfModule, bc, false);
    final CodeContextHolder contextHolder = CodeContextHolder.getInstance(module.getProject());
    for (Map.Entry<String, CodeContext> entry : contextsOfModule.entrySet()) {
        contextHolder.putCodeContext(entry.getKey(), module, entry.getValue());
    }
    CodeContext codeContext = contextsOfModule.get(namespace);
    if (codeContext == null) {
        codeContext = CodeContextHolder.EMPTY;
    }
    return codeContext;
}
Also used : ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) THashMap(gnu.trove.THashMap) Library(com.intellij.openapi.roots.libraries.Library) THashMap(gnu.trove.THashMap) Map(java.util.Map)

Aggregations

ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)47 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 Module (com.intellij.openapi.module.Module)19 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)13 ContentEntry (com.intellij.openapi.roots.ContentEntry)11 Sdk (com.intellij.openapi.projectRoots.Sdk)10 File (java.io.File)7 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)6 SourceFolder (com.intellij.openapi.roots.SourceFolder)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 OrderEntry (com.intellij.openapi.roots.OrderEntry)2 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)2 ProjectRootManagerEx (com.intellij.openapi.roots.ex.ProjectRootManagerEx)2 FilePaths.findParentContentEntry (com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 CodeInsightTestCase (com.intellij.codeInsight.CodeInsightTestCase)1