Search in sources :

Example 61 with Processor

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

the class QueryExecutorBase method execute.

@Override
public final boolean execute(@NotNull final Params queryParameters, @NotNull final Processor<Result> consumer) {
    final AtomicBoolean toContinue = new AtomicBoolean(true);
    final Processor<Result> wrapper = result -> {
        if (!toContinue.get()) {
            return false;
        }
        if (!consumer.process(result)) {
            toContinue.set(false);
            return false;
        }
        return true;
    };
    if (myRequireReadAction && !ApplicationManager.getApplication().isReadAccessAllowed()) {
        Runnable runnable = () -> processQuery(queryParameters, wrapper);
        if (!DumbService.isDumbAware(this)) {
            Project project = queryParameters instanceof DumbAwareSearchParameters ? ((DumbAwareSearchParameters) queryParameters).getProject() : null;
            if (project != null) {
                DumbService.getInstance(project).runReadActionInSmartMode(runnable);
                return toContinue.get();
            }
        }
        ApplicationManager.getApplication().runReadAction(runnable);
    } else {
        processQuery(queryParameters, wrapper);
    }
    return toContinue.get();
}
Also used : DumbService(com.intellij.openapi.project.DumbService) QueryExecutor(com.intellij.util.QueryExecutor) Processor(com.intellij.util.Processor) Project(com.intellij.openapi.project.Project) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Computable(com.intellij.openapi.util.Computable) NotNull(org.jetbrains.annotations.NotNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Project(com.intellij.openapi.project.Project)

Example 62 with Processor

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

the class ChangeMethodSignatureFromUsageFix method performChange.

public static List<ParameterInfoImpl> performChange(final Project project, final Editor editor, final PsiFile file, final PsiMethod method, final int minUsagesNumber, final ParameterInfoImpl[] newParametersInfo, final boolean changeAllUsages, final boolean allowDelegation) {
    if (!FileModificationService.getInstance().prepareFileForWrite(method.getContainingFile()))
        return null;
    final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
    final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(method, false);
    //on failure or cancel (e.g. cancel of super methods dialog)
    if (handler == null)
        return null;
    final JavaMethodFindUsagesOptions options = new JavaMethodFindUsagesOptions(project);
    options.isImplementingMethods = true;
    options.isOverridingMethods = true;
    options.isUsages = true;
    options.isSearchForTextOccurrences = false;
    final int[] usagesFound = new int[1];
    Runnable runnable = () -> {
        Processor<UsageInfo> processor = t -> ++usagesFound[0] < minUsagesNumber;
        handler.processElementUsages(method, processor, options);
    };
    String progressTitle = QuickFixBundle.message("searching.for.usages.progress.title");
    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, progressTitle, true, project))
        return null;
    if (ApplicationManager.getApplication().isUnitTestMode() || usagesFound[0] < minUsagesNumber) {
        ChangeSignatureProcessor processor = new ChangeSignatureProcessor(project, method, false, null, method.getName(), method.getReturnType(), newParametersInfo) {

            @Override
            @NotNull
            protected UsageInfo[] findUsages() {
                return changeAllUsages ? super.findUsages() : UsageInfo.EMPTY_ARRAY;
            }

            @Override
            protected void performRefactoring(@NotNull UsageInfo[] usages) {
                CommandProcessor.getInstance().setCurrentCommandName(getCommandName());
                super.performRefactoring(usages);
            }
        };
        processor.run();
        ApplicationManager.getApplication().runWriteAction(() -> UndoUtil.markPsiFileForUndo(file));
        return Arrays.asList(newParametersInfo);
    } else {
        final List<ParameterInfoImpl> parameterInfos = newParametersInfo != null ? new ArrayList<>(Arrays.asList(newParametersInfo)) : new ArrayList<>();
        final PsiReferenceExpression refExpr = JavaTargetElementEvaluator.findReferenceExpression(editor);
        JavaChangeSignatureDialog dialog = JavaChangeSignatureDialog.createAndPreselectNew(project, method, parameterInfos, allowDelegation, refExpr);
        dialog.setParameterInfos(parameterInfos);
        dialog.show();
        return dialog.isOK() ? dialog.getParameters() : null;
    }
}
Also used : FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) ChangeSignatureProcessor(com.intellij.refactoring.changeSignature.ChangeSignatureProcessor) CommandProcessor(com.intellij.openapi.command.CommandProcessor) Processor(com.intellij.util.Processor) JavaMethodFindUsagesOptions(com.intellij.find.findUsages.JavaMethodFindUsagesOptions) ParameterInfoImpl(com.intellij.refactoring.changeSignature.ParameterInfoImpl) NotNull(org.jetbrains.annotations.NotNull) FindManagerImpl(com.intellij.find.impl.FindManagerImpl) JavaChangeSignatureDialog(com.intellij.refactoring.changeSignature.JavaChangeSignatureDialog) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager) UsageInfo(com.intellij.usageView.UsageInfo) ChangeSignatureProcessor(com.intellij.refactoring.changeSignature.ChangeSignatureProcessor)

Example 63 with Processor

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

the class PsiSearchHelperImpl method collectFiles.

private void collectFiles(@NotNull MultiMap<Set<IdIndexEntry>, RequestWithProcessor> singles, @NotNull ProgressIndicator progress, @NotNull final MultiMap<VirtualFile, RequestWithProcessor> intersectionResult, @NotNull final MultiMap<VirtualFile, RequestWithProcessor> restResult) {
    for (Map.Entry<Set<IdIndexEntry>, Collection<RequestWithProcessor>> entry : singles.entrySet()) {
        final Set<IdIndexEntry> keys = entry.getKey();
        if (keys.isEmpty()) {
            continue;
        }
        final Collection<RequestWithProcessor> processors = entry.getValue();
        final GlobalSearchScope commonScope = uniteScopes(processors);
        final Set<VirtualFile> intersectionWithContainerNameFiles = intersectionWithContainerNameFiles(commonScope, processors, keys);
        List<VirtualFile> result = new ArrayList<>();
        Processor<VirtualFile> processor = Processors.cancelableCollectProcessor(result);
        processFilesContainingAllKeys(myManager.getProject(), commonScope, null, keys, processor);
        for (final VirtualFile file : result) {
            progress.checkCanceled();
            for (final IdIndexEntry indexEntry : keys) {
                DumbService.getInstance(myManager.getProject()).runReadActionInSmartMode(() -> FileBasedIndex.getInstance().processValues(IdIndex.NAME, indexEntry, file, (file1, value) -> {
                    int mask = value.intValue();
                    for (RequestWithProcessor single : processors) {
                        final PsiSearchRequest request = single.request;
                        if ((mask & request.searchContext) != 0 && request.searchScope.contains(file1)) {
                            MultiMap<VirtualFile, RequestWithProcessor> result1 = intersectionWithContainerNameFiles == null || !intersectionWithContainerNameFiles.contains(file1) ? restResult : intersectionResult;
                            result1.putValue(file1, single);
                        }
                    }
                    return true;
                }, commonScope));
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.openapi.util(com.intellij.openapi.util) java.util(java.util) CommentUtilCore(com.intellij.util.codeInsight.CommentUtilCore) JobLauncher(com.intellij.concurrency.JobLauncher) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ApplicationUtil(com.intellij.openapi.application.ex.ApplicationUtil) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UsageInfo(com.intellij.usageView.UsageInfo) THashSet(gnu.trove.THashSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) ReadAction(com.intellij.openapi.application.ReadAction) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) StringSearcher(com.intellij.util.text.StringSearcher) ReadActionProcessor(com.intellij.openapi.application.ReadActionProcessor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) TooManyUsagesStatus(com.intellij.openapi.progress.util.TooManyUsagesStatus) SmartList(com.intellij.util.SmartList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(com.intellij.psi.impl.cache.CacheManager) Project(com.intellij.openapi.project.Project) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) DumbService(com.intellij.openapi.project.DumbService) StringUtil(com.intellij.openapi.util.text.StringUtil) Processors(com.intellij.util.Processors) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry) ProgressIndicatorProvider(com.intellij.openapi.progress.ProgressIndicatorProvider) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) AsyncFuture(com.intellij.concurrency.AsyncFuture) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) com.intellij.psi.search(com.intellij.psi.search) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IdIndex(com.intellij.psi.impl.cache.impl.id.IdIndex) com.intellij.psi(com.intellij.psi) UsageInfoFactory(com.intellij.usageView.UsageInfoFactory) AsyncUtil(com.intellij.concurrency.AsyncUtil) NotNull(org.jetbrains.annotations.NotNull) THashSet(gnu.trove.THashSet) MultiMap(com.intellij.util.containers.MultiMap) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry) THashMap(gnu.trove.THashMap) MultiMap(com.intellij.util.containers.MultiMap)

Example 64 with Processor

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

the class MavenDomProjectProcessorUtils method searchManagedPluginUsages.

@NotNull
public static Collection<MavenDomPlugin> searchManagedPluginUsages(@NotNull final MavenDomProjectModel model, @Nullable final String groupId, @NotNull final String artifactId) {
    Project project = model.getManager().getProject();
    final Set<MavenDomPlugin> usages = new HashSet<>();
    Processor<MavenDomProjectModel> collectProcessor = mavenDomProjectModel -> {
        for (MavenDomPlugin domPlugin : mavenDomProjectModel.getBuild().getPlugins().getPlugins()) {
            if (MavenPluginDomUtil.isPlugin(domPlugin, groupId, artifactId)) {
                usages.add(domPlugin);
            }
        }
        return false;
    };
    processChildrenRecursively(model, collectProcessor, project, new HashSet<>(), true);
    return usages;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) org.jetbrains.idea.maven.dom.model(org.jetbrains.idea.maven.dom.model) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContainerUtil(com.intellij.util.containers.ContainerUtil) org.jetbrains.idea.maven.project(org.jetbrains.idea.maven.project) SmartList(com.intellij.util.SmartList) MavenId(org.jetbrains.idea.maven.model.MavenId) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) HashSet(com.intellij.util.containers.hash.HashSet) DomUtil(com.intellij.util.xml.DomUtil) XmlTag(com.intellij.psi.xml.XmlTag) GenericDomValue(com.intellij.util.xml.GenericDomValue) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) Set(java.util.Set) MavenUtil(org.jetbrains.idea.maven.utils.MavenUtil) Nullable(org.jetbrains.annotations.Nullable) Function(com.intellij.util.Function) Processor(com.intellij.util.Processor) GenericDomValueReference(com.intellij.util.xml.impl.GenericDomValueReference) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Collections(java.util.Collections) Project(com.intellij.openapi.project.Project) HashSet(com.intellij.util.containers.hash.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with Processor

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

the class CreateComponentAction method actionPerformed.

protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
    Processor<ComponentItem> processor = selectedValue -> {
        if (selectedValue != null) {
            myLastCreatedComponent = selectedValue;
            editor.getMainProcessor().startInsertProcessor(selectedValue, getCreateLocation(editor, selection));
        }
        return true;
    };
    PaletteListPopupStep step = new PaletteListPopupStep(editor, myLastCreatedComponent, processor, UIDesignerBundle.message("create.component.title"));
    final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
    if (selection.size() > 0) {
        FormEditingUtil.showPopupUnderComponent(listPopup, selection.get(0));
    } else {
        listPopup.showInCenterOf(editor.getRootContainer().getDelegee());
    }
}
Also used : UIDesignerBundle(com.intellij.uiDesigner.UIDesignerBundle) com.intellij.uiDesigner.designSurface(com.intellij.uiDesigner.designSurface) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) java.awt(java.awt) ListPopup(com.intellij.openapi.ui.popup.ListPopup) List(java.util.List) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) Processor(com.intellij.util.Processor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) ListPopup(com.intellij.openapi.ui.popup.ListPopup)

Aggregations

Processor (com.intellij.util.Processor)83 NotNull (org.jetbrains.annotations.NotNull)65 Project (com.intellij.openapi.project.Project)49 Nullable (org.jetbrains.annotations.Nullable)49 ContainerUtil (com.intellij.util.containers.ContainerUtil)42 com.intellij.psi (com.intellij.psi)31 List (java.util.List)28 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 StringUtil (com.intellij.openapi.util.text.StringUtil)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 java.util (java.util)25 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)24 ProgressManager (com.intellij.openapi.progress.ProgressManager)21 Logger (com.intellij.openapi.diagnostic.Logger)20 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)20 NonNls (org.jetbrains.annotations.NonNls)18 Ref (com.intellij.openapi.util.Ref)16 Collection (java.util.Collection)16 SmartList (com.intellij.util.SmartList)14 Document (com.intellij.openapi.editor.Document)13