Search in sources :

Example 26 with Module

use of com.intellij.openapi.module.Module in project kotlin by JetBrains.

the class AbstractJavaAgainstKotlinCheckerTest method createMainModule.

@Override
protected Module createMainModule() throws IOException {
    Module module = super.createMainModule();
    String configFileText = getConfigFileText();
    if (configFileText == null) {
        return module;
    }
    if (InTextDirectivesUtils.isDirectiveDefined(configFileText, "// WITH_RUNTIME")) {
        ConfigLibraryUtil.configureKotlinRuntime(module);
    }
    List<String> languageLevelLines = InTextDirectivesUtils.findLinesWithPrefixesRemoved(configFileText, "// LANGUAGE_LEVEL");
    if (languageLevelLines.size() > 1) {
        throw new AssertionError("Language level specified multiple times: " + languageLevelLines);
    }
    if (languageLevelLines.size() == 1) {
        LanguageLevel level = LanguageLevel.parse(languageLevelLines.iterator().next());
        if (level != null) {
            IdeaTestUtil.setModuleLanguageLevel(module, level);
        }
    }
    return module;
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) Module(com.intellij.openapi.module.Module)

Example 27 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class MavenActionUtil method getMavenProjects.

public static List<MavenProject> getMavenProjects(DataContext context) {
    Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null)
        return Collections.emptyList();
    VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context);
    if (virtualFiles == null || virtualFiles.length == 0)
        return Collections.emptyList();
    MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
    if (!projectsManager.isMavenizedProject())
        return Collections.emptyList();
    Set<MavenProject> res = new LinkedHashSet<>();
    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (VirtualFile file : virtualFiles) {
        MavenProject mavenProject;
        if (file.isDirectory()) {
            VirtualFile contentRoot = fileIndex.getContentRootForFile(file);
            if (!file.equals(contentRoot))
                return Collections.emptyList();
            Module module = fileIndex.getModuleForFile(file);
            if (module == null || !projectsManager.isMavenizedModule(module))
                return Collections.emptyList();
            mavenProject = projectsManager.findProject(module);
        } else {
            mavenProject = projectsManager.findProject(file);
        }
        if (mavenProject == null)
            return Collections.emptyList();
        res.add(mavenProject);
    }
    return new ArrayList<>(res);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module)

Example 28 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class RepositoryLibrarySynchronizer method collectLibraries.

private static Collection<Library> collectLibraries(@NotNull final Project project, @NotNull final Predicate<Library> predicate) {
    final HashSet<Library> result = new HashSet<>();
    ApplicationManager.getApplication().runReadAction(() -> {
        for (final Module module : ModuleManager.getInstance(project).getModules()) {
            OrderEnumerator.orderEntries(module).withoutSdk().forEachLibrary(library -> {
                if (predicate.apply(library)) {
                    result.add(library);
                }
                return true;
            });
        }
        for (Library library : ProjectLibraryTable.getInstance(project).getLibraries()) {
            if (predicate.apply(library)) {
                result.add(library);
            }
        }
    });
    return result;
}
Also used : Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) HashSet(com.intellij.util.containers.HashSet)

Example 29 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class MavenTestCase method createModule.

protected Module createModule(final String name, final ModuleType type) throws IOException {
    return new WriteCommandAction<Module>(myProject) {

        @Override
        protected void run(@NotNull Result<Module> moduleResult) throws Throwable {
            VirtualFile f = createProjectSubFile(name + "/" + name + ".iml");
            Module module = ModuleManager.getInstance(myProject).newModule(f.getPath(), type.getId());
            PsiTestUtil.addContentRoot(module, f.getParent());
            moduleResult.setResult(module);
        }
    }.execute().getResultObject();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 30 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class FormSourceCodeGenerator method generate.

public void generate(final VirtualFile formFile) {
    myNeedLoadLabelText = false;
    myNeedLoadButtonText = false;
    final Module module = ModuleUtil.findModuleForFile(formFile, myProject);
    if (module == null) {
        return;
    }
    // ensure that new instances of generators are used for every run
    ourContainerLayoutCodeGenerators.clear();
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_INTELLIJ, new GridLayoutSourceGenerator());
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_GRIDBAG, new GridBagLayoutSourceGenerator());
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_BORDER, new BorderLayoutSourceGenerator());
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_FLOW, new FlowLayoutSourceGenerator());
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_CARD, new CardLayoutSourceGenerator());
    ourContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_FORM, new FormLayoutSourceGenerator());
    myErrors.clear();
    final PsiPropertiesProvider propertiesProvider = new PsiPropertiesProvider(module);
    final Document doc = FileDocumentManager.getInstance().getDocument(formFile);
    final LwRootContainer rootContainer;
    try {
        rootContainer = Utils.getRootContainer(doc.getText(), propertiesProvider);
    } catch (AlienFormFileException ignored) {
        // ignoring this file
        return;
    } catch (Exception e) {
        myErrors.add(new FormErrorInfo(null, UIDesignerBundle.message("error.cannot.process.form.file", e)));
        return;
    }
    if (rootContainer.getClassToBind() == null) {
        // form skipped - no class to bind
        return;
    }
    ErrorAnalyzer.analyzeErrors(module, formFile, null, rootContainer, null);
    FormEditingUtil.iterate(rootContainer, new FormEditingUtil.ComponentVisitor<LwComponent>() {

        public boolean visit(final LwComponent iComponent) {
            final ErrorInfo errorInfo = ErrorAnalyzer.getErrorForComponent(iComponent);
            if (errorInfo != null) {
                String message;
                if (iComponent.getBinding() != null) {
                    message = UIDesignerBundle.message("error.for.component", iComponent.getBinding(), errorInfo.myDescription);
                } else {
                    message = errorInfo.myDescription;
                }
                myErrors.add(new FormErrorInfo(iComponent.getId(), message));
            }
            return true;
        }
    });
    if (myErrors.size() != 0) {
        return;
    }
    try {
        _generate(rootContainer, module);
    } catch (ClassToBindNotFoundException e) {
    // ignore
    } catch (CodeGenerationException e) {
        myErrors.add(new FormErrorInfo(e.getComponentId(), e.getMessage()));
    } catch (IncorrectOperationException e) {
        myErrors.add(new FormErrorInfo(null, e.getMessage()));
    }
}
Also used : Document(com.intellij.openapi.editor.Document) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)1911 VirtualFile (com.intellij.openapi.vfs.VirtualFile)585 Project (com.intellij.openapi.project.Project)381 NotNull (org.jetbrains.annotations.NotNull)331 Nullable (org.jetbrains.annotations.Nullable)268 File (java.io.File)185 PsiFile (com.intellij.psi.PsiFile)147 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)134 ArrayList (java.util.ArrayList)118 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)112 Sdk (com.intellij.openapi.projectRoots.Sdk)95 PsiElement (com.intellij.psi.PsiElement)89 PsiDirectory (com.intellij.psi.PsiDirectory)77 ModuleManager (com.intellij.openapi.module.ModuleManager)65 PsiClass (com.intellij.psi.PsiClass)65 IOException (java.io.IOException)61 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)57 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)57 List (java.util.List)57 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)51