Search in sources :

Example 1 with Consumer

use of com.intellij.util.Consumer in project intellij-elixir by KronicDeth.

the class Submitter method successCallback.

@NotNull
private static Consumer<Boolean> successCallback(@Nullable final Project project, @NotNull final Consumer<SubmittedReportInfo> consumer) {
    return new Consumer<Boolean>() {

        @Override
        public void consume(Boolean opened) {
            String url = null;
            String linkText = null;
            //noinspection ConstantConditions
            final SubmittedReportInfo reportInfo = new SubmittedReportInfo(url, linkText, SubmittedReportInfo.SubmissionStatus.NEW_ISSUE);
            consumer.consume(reportInfo);
            // pseudo-named-arguments
            NotificationListener notificationListener = null;
            //noinspection ConstantConditions
            ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, "Submitted", NotificationType.INFORMATION, notificationListener).setImportant(false).notify(project);
        }
    };
}
Also used : Consumer(com.intellij.util.Consumer) SubmittedReportInfo(com.intellij.openapi.diagnostic.SubmittedReportInfo) NotificationListener(com.intellij.notification.NotificationListener) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Consumer

use of com.intellij.util.Consumer in project intellij-community by JetBrains.

the class BaseSpellChecker method doLoadDictionaryAsync.

private void doLoadDictionaryAsync(Loader loader, Consumer<Dictionary> consumer) {
    StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> {
        LOG.debug("Loading " + loader.getName());
        Application app = ApplicationManager.getApplication();
        app.executeOnPooledThread(() -> {
            if (app.isDisposed())
                return;
            CompressedDictionary dictionary = CompressedDictionary.create(loader, transform);
            LOG.debug(loader.getName() + " loaded!");
            consumer.consume(dictionary);
            while (!myDictionariesToLoad.isEmpty()) {
                if (app.isDisposed())
                    return;
                Pair<Loader, Consumer<Dictionary>> nextDictionary = myDictionariesToLoad.remove(0);
                Loader nextDictionaryLoader = nextDictionary.getFirst();
                dictionary = CompressedDictionary.create(nextDictionaryLoader, transform);
                LOG.debug(nextDictionaryLoader.getName() + " loaded!");
                nextDictionary.getSecond().consume(dictionary);
            }
            LOG.debug("Loading finished, restarting daemon...");
            myLoadingDictionaries.set(false);
            UIUtil.invokeLaterIfNeeded(() -> {
                if (app.isDisposed())
                    return;
                for (final Project project : ProjectManager.getInstance().getOpenProjects()) {
                    if (project.isInitialized() && project.isOpen() && !project.isDefault()) {
                        DaemonCodeAnalyzer instance = DaemonCodeAnalyzer.getInstance(project);
                        if (instance != null)
                            instance.restart();
                    }
                }
            });
        });
    });
}
Also used : Project(com.intellij.openapi.project.Project) Consumer(com.intellij.util.Consumer) CompressedDictionary(com.intellij.spellchecker.compress.CompressedDictionary) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) Loader(com.intellij.spellchecker.dictionary.Loader) Application(com.intellij.openapi.application.Application)

Example 3 with Consumer

use of com.intellij.util.Consumer in project intellij-community by JetBrains.

the class MvcModuleStructureUtil method addJarDirectory.

@Nullable
public static Consumer<ModifiableRootModel> addJarDirectory(VirtualFile root, Module module, final String libName) {
    final VirtualFile libDir = root.findFileByRelativePath("lib");
    if (libDir == null || !libDir.isDirectory() || ProjectRootManager.getInstance(module.getProject()).getFileIndex().isExcluded(libDir)) {
        return null;
    }
    final Library library = findUserLibrary(module, libName);
    if (library != null && library.isJarDirectory(libDir.getUrl())) {
        return null;
    }
    return model -> {
        Library.ModifiableModel libModel = modifyDefaultLibrary(model, libName);
        libModel.addJarDirectory(libDir, false);
        libModel.commit();
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) java.util(java.util) Application(com.intellij.openapi.application.Application) ArrayUtil(com.intellij.util.ArrayUtil) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) PsiManager(com.intellij.psi.PsiManager) com.intellij.openapi.roots(com.intellij.openapi.roots) Library(com.intellij.openapi.roots.libraries.Library) Comparing(com.intellij.openapi.util.Comparing) SmartList(com.intellij.util.SmartList) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) MultiMap(com.intellij.util.containers.MultiMap) CommonProcessors(com.intellij.util.CommonProcessors) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) LibraryUtil(com.intellij.openapi.roots.libraries.LibraryUtil) ModifiableModelCommitter(com.intellij.openapi.roots.impl.ModifiableModelCommitter) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) Key(com.intellij.openapi.util.Key) IOException(java.io.IOException) FacetManager(com.intellij.facet.FacetManager) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) ModuleDeleteProvider(com.intellij.openapi.roots.ui.configuration.actions.ModuleDeleteProvider) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) Library(com.intellij.openapi.roots.libraries.Library) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with Consumer

use of com.intellij.util.Consumer in project intellij-community by JetBrains.

the class GroovySmartCompletionContributor method addExpectedClassMembers.

static void addExpectedClassMembers(CompletionParameters params, final CompletionResultSet result) {
    for (final TypeConstraint info : getExpectedTypeInfos(params)) {
        Consumer<LookupElement> consumer = element -> result.addElement(element);
        PsiType type = info.getType();
        PsiType defType = info.getDefaultType();
        boolean searchInheritors = params.getInvocationCount() > 1;
        if (type instanceof PsiClassType) {
            new GroovyMembersGetter((PsiClassType) type, params).processMembers(searchInheritors, consumer);
        }
        if (!defType.equals(type) && defType instanceof PsiClassType) {
            new GroovyMembersGetter((PsiClassType) defType, params).processMembers(searchInheritors, consumer);
        }
    }
}
Also used : TypeConversionUtil(com.intellij.psi.util.TypeConversionUtil) Arrays(java.util.Arrays) IElementType(com.intellij.psi.tree.IElementType) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) GrReferenceElement(org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) AfterNewClassInsertHandler(org.jetbrains.plugins.groovy.lang.completion.handlers.AfterNewClassInsertHandler) TailType(com.intellij.codeInsight.TailType) PlatformPatterns(com.intellij.patterns.PlatformPatterns) TObjectHashingStrategy(gnu.trove.TObjectHashingStrategy) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) ScrollType(com.intellij.openapi.editor.ScrollType) SmartList(com.intellij.util.SmartList) TypeInferenceHelper(org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper) FeatureUsageTracker(com.intellij.featureStatistics.FeatureUsageTracker) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement) GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) PsiTypeLookupItem(com.intellij.codeInsight.lookup.PsiTypeLookupItem) GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GroovyTokenTypes(org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes) ProcessingContext(com.intellij.util.ProcessingContext) GrAnnotationNameValuePair(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair) GroovyConfigUtils(org.jetbrains.plugins.groovy.config.GroovyConfigUtils) TypeConstraint(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.TypeConstraint) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ChooseTypeExpression(org.jetbrains.plugins.groovy.template.expressions.ChooseTypeExpression) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) StandardPatterns(com.intellij.patterns.StandardPatterns) GrVariableDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration) CodeStyleSettingsManager(com.intellij.psi.codeStyle.CodeStyleSettingsManager) Editor(com.intellij.openapi.editor.Editor) ElementPattern(com.intellij.patterns.ElementPattern) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) com.intellij.codeInsight.completion(com.intellij.codeInsight.completion) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions) com.intellij.psi(com.intellij.psi) GroovyExpectedTypesProvider(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.GroovyExpectedTypesProvider) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) PsiUtil(org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil) TypeConstraint(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.TypeConstraint) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 5 with Consumer

use of com.intellij.util.Consumer in project intellij-community by JetBrains.

the class MavenAttachSourcesProvider method getActions.

@Override
@NotNull
public Collection<AttachSourcesAction> getActions(final List<LibraryOrderEntry> orderEntries, final PsiFile psiFile) {
    Collection<MavenProject> projects = getMavenProjects(psiFile);
    if (projects.isEmpty())
        return Collections.emptyList();
    if (findArtifacts(projects, orderEntries).isEmpty())
        return Collections.emptyList();
    return Collections.singleton(new AttachSourcesAction() {

        @Override
        public String getName() {
            return ProjectBundle.message("maven.action.download.sources");
        }

        @Override
        public String getBusyText() {
            return ProjectBundle.message("maven.action.download.sources.busy.text");
        }

        @Override
        public ActionCallback perform(List<LibraryOrderEntry> orderEntries) {
            // may have been changed by this time...
            Collection<MavenProject> mavenProjects = getMavenProjects(psiFile);
            if (mavenProjects.isEmpty()) {
                return ActionCallback.REJECTED;
            }
            MavenProjectsManager manager = MavenProjectsManager.getInstance(psiFile.getProject());
            Collection<MavenArtifact> artifacts = findArtifacts(mavenProjects, orderEntries);
            if (artifacts.isEmpty())
                return ActionCallback.REJECTED;
            final AsyncResult<MavenArtifactDownloader.DownloadResult> result = new AsyncResult<>();
            manager.scheduleArtifactsDownloading(mavenProjects, artifacts, true, false, result);
            final ActionCallback resultWrapper = new ActionCallback();
            result.doWhenDone(new Consumer<MavenArtifactDownloader.DownloadResult>() {

                @Override
                public void consume(MavenArtifactDownloader.DownloadResult downloadResult) {
                    if (!downloadResult.unresolvedSources.isEmpty()) {
                        final StringBuilder message = new StringBuilder();
                        message.append("<html>Sources not found for:");
                        int count = 0;
                        for (MavenId each : downloadResult.unresolvedSources) {
                            if (count++ > 5) {
                                message.append("<br>and more...");
                                break;
                            }
                            message.append("<br>").append(each.getDisplayString());
                        }
                        message.append("</html>");
                        Notifications.Bus.notify(new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "Cannot download sources", message.toString(), NotificationType.WARNING), psiFile.getProject());
                    }
                    if (downloadResult.resolvedSources.isEmpty()) {
                        resultWrapper.setRejected();
                    } else {
                        resultWrapper.setDone();
                    }
                }
            });
            return resultWrapper;
        }
    });
}
Also used : MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) ActionCallback(com.intellij.openapi.util.ActionCallback) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Notification(com.intellij.notification.Notification) MavenArtifactDownloader(org.jetbrains.idea.maven.project.MavenArtifactDownloader) MavenId(org.jetbrains.idea.maven.model.MavenId) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Consumer(com.intellij.util.Consumer) Collection(java.util.Collection) AsyncResult(com.intellij.openapi.util.AsyncResult) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Consumer (com.intellij.util.Consumer)59 NotNull (org.jetbrains.annotations.NotNull)41 Project (com.intellij.openapi.project.Project)37 Nullable (org.jetbrains.annotations.Nullable)33 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 List (java.util.List)22 ApplicationManager (com.intellij.openapi.application.ApplicationManager)17 StringUtil (com.intellij.openapi.util.text.StringUtil)17 javax.swing (javax.swing)16 ContainerUtil (com.intellij.util.containers.ContainerUtil)15 Logger (com.intellij.openapi.diagnostic.Logger)14 Module (com.intellij.openapi.module.Module)12 java.awt (java.awt)12 Pair (com.intellij.openapi.util.Pair)11 java.util (java.util)11 File (java.io.File)10 Collection (java.util.Collection)10 PsiElement (com.intellij.psi.PsiElement)9 PsiFile (com.intellij.psi.PsiFile)9 DataContext (com.intellij.openapi.actionSystem.DataContext)8