Search in sources :

Example 96 with Module

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

the class ConfigFilesTreeBuilder method buildModuleNodes.

public Set<PsiFile> buildModuleNodes(final MultiMap<Module, PsiFile> files, final MultiMap<VirtualFile, PsiFile> jars, DefaultMutableTreeNode root) {
    final HashSet<PsiFile> psiFiles = new HashSet<>();
    final List<Module> modules = new ArrayList<>(files.keySet());
    Collections.sort(modules, ModulesAlphaComparator.INSTANCE);
    for (Module module : modules) {
        DefaultMutableTreeNode moduleNode = createFileNode(module);
        root.add(moduleNode);
        if (files.containsKey(module)) {
            List<PsiFile> moduleFiles = new ArrayList<>(files.get(module));
            MultiMap<FileType, PsiFile> filesByType = new MultiMap<>();
            for (PsiFile file : moduleFiles) {
                filesByType.putValue(file.getFileType(), file);
            }
            if (hasNonEmptyGroups(filesByType)) {
                for (Map.Entry<FileType, Collection<PsiFile>> entry : filesByType.entrySet()) {
                    DefaultMutableTreeNode fileTypeNode = createFileNode(entry.getKey());
                    moduleNode.add(fileTypeNode);
                    addChildrenFiles(psiFiles, fileTypeNode, new ArrayList<>(entry.getValue()));
                }
            } else {
                addChildrenFiles(psiFiles, moduleNode, moduleFiles);
            }
        }
    }
    List<VirtualFile> sortedJars = new ArrayList<>(jars.keySet());
    Collections.sort(sortedJars, (o1, o2) -> StringUtil.naturalCompare(o1.getName(), o2.getName()));
    for (VirtualFile file : sortedJars) {
        if (!file.isValid())
            continue;
        final List<PsiFile> list = new ArrayList<>(jars.get(file));
        final PsiFile jar = list.get(0).getManager().findFile(file);
        if (jar != null) {
            final DefaultMutableTreeNode jarNode = createFileNode(jar);
            root.add(jarNode);
            Collections.sort(list, FILE_COMPARATOR);
            for (PsiFile psiFile : list) {
                jarNode.add(createFileNode(psiFile));
                psiFiles.add(psiFile);
            }
        }
    }
    return psiFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MultiMap(com.intellij.util.containers.MultiMap) FileType(com.intellij.openapi.fileTypes.FileType) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) MultiMap(com.intellij.util.containers.MultiMap)

Example 97 with Module

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

the class DefaultGroovyScriptRunner method ensureRunnerConfigured.

@Override
public void ensureRunnerConfigured(@NotNull GroovyScriptRunConfiguration configuration) throws RuntimeConfigurationException {
    Module module = configuration.getModule();
    if (module == null) {
        throw new RuntimeConfigurationException("Module is not specified");
    }
    if (LibrariesUtil.getGroovyHomePath(module) == null) {
        RuntimeConfigurationException e = new RuntimeConfigurationException("Groovy is not configured for module '" + module.getName() + "'");
        e.setQuickFix(() -> ModulesConfigurator.showDialog(module.getProject(), module.getName(), ClasspathEditor.NAME));
        throw e;
    }
}
Also used : RuntimeConfigurationException(com.intellij.execution.configurations.RuntimeConfigurationException) Module(com.intellij.openapi.module.Module)

Example 98 with Module

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

the class GroovyScriptRunConfiguration method getValidModules.

@Override
public Collection<Module> getValidModules() {
    Module[] modules = ModuleManager.getInstance(getProject()).getModules();
    final GroovyScriptRunner scriptRunner = getScriptRunner();
    if (scriptRunner == null) {
        return Arrays.asList(modules);
    }
    ArrayList<Module> res = new ArrayList<>();
    for (Module module : modules) {
        if (scriptRunner.isValidModule(module)) {
            res.add(module);
        }
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) Module(com.intellij.openapi.module.Module)

Example 99 with Module

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

the class TestPackage method createSearchingForTestsTask.

@Override
public SearchForTestsTask createSearchingForTestsTask() {
    final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
    return new SearchForTestsTask(getConfiguration().getProject(), myServerSocket) {

        private final THashSet<PsiClass> myClasses = new THashSet<>();

        @Override
        protected void search() {
            myClasses.clear();
            final SourceScope sourceScope = getSourceScope();
            final Module module = getConfiguration().getConfigurationModule().getModule();
            if (sourceScope != null && !ReadAction.compute(() -> isJUnit5(module, sourceScope, myProject))) {
                try {
                    final TestClassFilter classFilter = getClassFilter(data);
                    LOG.assertTrue(classFilter.getBase() != null);
                    ConfigurationUtil.findAllTestClasses(classFilter, module, myClasses);
                } catch (CantRunException ignored) {
                }
            }
        }

        @Override
        protected void onFound() {
            try {
                addClassesListToJavaParameters(myClasses, psiClass -> psiClass != null ? JavaExecutionUtil.getRuntimeQualifiedName(psiClass) : null, getPackageName(data), createTempFiles(), getJavaParameters());
            } catch (ExecutionException ignored) {
            }
        }
    };
}
Also used : SourceScope(com.intellij.execution.testframework.SourceScope) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask) Module(com.intellij.openapi.module.Module) THashSet(gnu.trove.THashSet)

Example 100 with Module

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

the class JUnitConfiguration method bePatternConfiguration.

public void bePatternConfiguration(List<PsiClass> classes, PsiMethod method) {
    myData.TEST_OBJECT = TEST_PATTERN;
    final LinkedHashSet<String> patterns = new LinkedHashSet<>();
    final String methodSufiix;
    if (method != null) {
        myData.METHOD_NAME = Data.getMethodPresentation(method);
        methodSufiix = "," + myData.METHOD_NAME;
    } else {
        methodSufiix = "";
    }
    for (PsiClass pattern : classes) {
        patterns.add(JavaExecutionUtil.getRuntimeQualifiedName(pattern) + methodSufiix);
    }
    myData.setPatterns(patterns);
    final Module module = RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).findModule(this, getConfigurationModule().getModule(), patterns);
    if (module == null) {
        myData.setScope(TestSearchScope.WHOLE_PROJECT);
        setModule(null);
    } else {
        setModule(module);
    }
    setGeneratedName();
}
Also used : Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)1893 VirtualFile (com.intellij.openapi.vfs.VirtualFile)585 Project (com.intellij.openapi.project.Project)379 NotNull (org.jetbrains.annotations.NotNull)330 Nullable (org.jetbrains.annotations.Nullable)267 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