Search in sources :

Example 76 with Processor

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

the class FindInProjectTask method searchInFiles.

private void searchInFiles(@NotNull Collection<VirtualFile> virtualFiles, @NotNull FindUsagesProcessPresentation processPresentation, @NotNull final Processor<UsageInfo> consumer) {
    AtomicInteger occurrenceCount = new AtomicInteger();
    AtomicInteger processedFileCount = new AtomicInteger();
    Processor<VirtualFile> processor = virtualFile -> {
        if (!virtualFile.isValid())
            return true;
        long fileLength = UsageViewManagerImpl.getFileLength(virtualFile);
        if (fileLength == -1)
            return true;
        final boolean skipProjectFile = ProjectUtil.isProjectOrWorkspaceFile(virtualFile) && !myFindModel.isSearchInProjectFiles();
        if (skipProjectFile && !Registry.is("find.search.in.project.files"))
            return true;
        if (fileLength > SINGLE_FILE_SIZE_LIMIT) {
            myLargeFiles.add(virtualFile);
            return true;
        }
        myProgress.checkCanceled();
        if (myProgress.isRunning()) {
            double fraction = (double) processedFileCount.incrementAndGet() / virtualFiles.size();
            myProgress.setFraction(fraction);
        }
        String text = FindBundle.message("find.searching.for.string.in.file.progress", myFindModel.getStringToFind(), virtualFile.getPresentableUrl());
        myProgress.setText(text);
        myProgress.setText2(FindBundle.message("find.searching.for.string.in.file.occurrences.progress", occurrenceCount));
        Pair.NonNull<PsiFile, VirtualFile> pair = ReadAction.compute(() -> findFile(virtualFile));
        if (pair == null)
            return true;
        PsiFile psiFile = pair.first;
        VirtualFile sourceVirtualFile = pair.second;
        int countInFile = FindInProjectUtil.processUsagesInFile(psiFile, sourceVirtualFile, myFindModel, info -> skipProjectFile || consumer.process(info));
        if (countInFile > 0 && skipProjectFile) {
            processPresentation.projectFileUsagesFound(() -> {
                FindModel model = myFindModel.clone();
                model.setSearchInProjectFiles(true);
                FindInProjectManager.getInstance(myProject).startFindInProject(model);
            });
            return true;
        }
        occurrenceCount.addAndGet(countInFile);
        if (countInFile > 0) {
            if (myTotalFilesSize.addAndGet(fileLength) > FILES_SIZE_LIMIT && myWarningShown.compareAndSet(false, true)) {
                String message = FindBundle.message("find.excessive.total.size.prompt", UsageViewManagerImpl.presentableSize(myTotalFilesSize.longValue()), ApplicationNamesInfo.getInstance().getProductName());
                UsageLimitUtil.showAndCancelIfAborted(myProject, message, processPresentation.getUsageViewPresentation());
            }
        }
        return true;
    };
    PsiSearchHelperImpl.processFilesConcurrentlyDespiteWriteActions(myProject, new ArrayList<>(virtualFiles), myProgress, processor);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FindInProjectManager(com.intellij.find.findInProject.FindInProjectManager) FindBundle(com.intellij.find.FindBundle) ReadAction(com.intellij.openapi.application.ReadAction) TrigramBuilder(com.intellij.openapi.util.text.TrigramBuilder) PsiManager(com.intellij.psi.PsiManager) HashMultiset(com.google.common.collect.HashMultiset) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FindModel(com.intellij.find.FindModel) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) Processors(com.intellij.util.Processors) ProjectUtil(com.intellij.openapi.project.ProjectUtil) UsageViewManagerImpl(com.intellij.usages.impl.UsageViewManagerImpl) 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) Registry(com.intellij.openapi.util.registry.Registry) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) Multiset(com.google.common.collect.Multiset) ModuleManager(com.intellij.openapi.module.ModuleManager) PsiSearchHelperImpl(com.intellij.psi.impl.search.PsiSearchHelperImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UsageInfo(com.intellij.usageView.UsageInfo) ContainerUtil(com.intellij.util.containers.ContainerUtil) com.intellij.openapi.roots(com.intellij.openapi.roots) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) FileBasedIndexImpl(com.intellij.util.indexing.FileBasedIndexImpl) CacheManager(com.intellij.psi.impl.cache.CacheManager) FindUsagesProcessPresentation(com.intellij.usages.FindUsagesProcessPresentation) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) PsiBinaryFile(com.intellij.psi.PsiBinaryFile) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter) FileType(com.intellij.openapi.fileTypes.FileType) AtomicLong(java.util.concurrent.atomic.AtomicLong) UsageLimitUtil(com.intellij.usages.UsageLimitUtil) Pair(com.intellij.openapi.util.Pair) TrigramIndex(com.intellij.find.ngrams.TrigramIndex) Condition(com.intellij.openapi.util.Condition) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FindModel(com.intellij.find.FindModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PsiFile(com.intellij.psi.PsiFile)

Example 77 with Processor

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

the class FindUsagesManager method createUsageSearcher.

/**
   * @throws PsiInvalidElementAccessException when the searcher can't be created (i.e. because element was invalidated)
   */
@NotNull
private static UsageSearcher createUsageSearcher(@NotNull final PsiElement2UsageTargetAdapter[] primaryTargets, @NotNull final PsiElement2UsageTargetAdapter[] secondaryTargets, @NotNull final FindUsagesHandler handler, @NotNull FindUsagesOptions options, final PsiFile scopeFile) throws PsiInvalidElementAccessException {
    ReadAction.run(() -> {
        PsiElement[] primaryElements = PsiElement2UsageTargetAdapter.convertToPsiElements(primaryTargets);
        PsiElement[] secondaryElements = PsiElement2UsageTargetAdapter.convertToPsiElements(secondaryTargets);
        ContainerUtil.concat(primaryElements, secondaryElements).forEach(psi -> {
            if (psi == null || !psi.isValid())
                throw new PsiInvalidElementAccessException(psi);
        });
    });
    FindUsagesOptions optionsClone = options.clone();
    return processor -> {
        PsiElement[] primaryElements = ReadAction.compute(() -> PsiElement2UsageTargetAdapter.convertToPsiElements(primaryTargets));
        PsiElement[] secondaryElements = ReadAction.compute(() -> PsiElement2UsageTargetAdapter.convertToPsiElements(secondaryTargets));
        Project project = ReadAction.compute(() -> scopeFile != null ? scopeFile.getProject() : primaryElements[0].getProject());
        dropResolveCacheRegularly(ProgressManager.getInstance().getProgressIndicator(), project);
        if (scopeFile != null) {
            optionsClone.searchScope = new LocalSearchScope(scopeFile);
        }
        final Processor<UsageInfo> usageInfoProcessor = new CommonProcessors.UniqueProcessor<>(usageInfo -> {
            Usage usage = ReadAction.compute(() -> UsageInfoToUsageConverter.convert(primaryElements, usageInfo));
            return processor.process(usage);
        });
        final Iterable<PsiElement> elements = ContainerUtil.concat(primaryElements, secondaryElements);
        optionsClone.fastTrack = new SearchRequestCollector(new SearchSession());
        if (optionsClone.searchScope instanceof GlobalSearchScope) {
            optionsClone.searchScope = optionsClone.searchScope.union(GlobalSearchScope.projectScope(project));
        }
        try {
            for (final PsiElement element : elements) {
                handler.processElementUsages(element, usageInfoProcessor, optionsClone);
                for (CustomUsageSearcher searcher : Extensions.getExtensions(CustomUsageSearcher.EP_NAME)) {
                    try {
                        searcher.processElementUsages(element, processor, optionsClone);
                    } catch (IndexNotReadyException e) {
                        DumbService.getInstance(element.getProject()).showDumbModeNotification("Find usages is not available during indexing");
                    } catch (ProcessCanceledException e) {
                        throw e;
                    } catch (Exception e) {
                        LOG.error(e);
                    }
                }
            }
            PsiSearchHelper.SERVICE.getInstance(project).processRequests(optionsClone.fastTrack, ref -> {
                UsageInfo info = ReadAction.compute(() -> {
                    if (!ref.getElement().isValid())
                        return null;
                    return new UsageInfo(ref);
                });
                return info == null || usageInfoProcessor.process(info);
            });
        } finally {
            optionsClone.fastTrack = null;
        }
    };
}
Also used : Arrays(java.util.Arrays) Document(com.intellij.openapi.editor.Document) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx) FileEditorLocation(com.intellij.openapi.fileEditor.FileEditorLocation) IdeActions(com.intellij.openapi.actionSystem.IdeActions) FindBundle(com.intellij.find.FindBundle) ReadAction(com.intellij.openapi.application.ReadAction) Task(com.intellij.openapi.progress.Task) StatusBar(com.intellij.openapi.wm.StatusBar) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) TextEditor(com.intellij.openapi.fileEditor.TextEditor) UsageViewManager(com.intellij.usageView.UsageViewManager) CommonProcessors(com.intellij.util.CommonProcessors) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) HintUtil(com.intellij.codeInsight.hint.HintUtil) DumbService(com.intellij.openapi.project.DumbService) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) Content(com.intellij.ui.content.Content) FileEditor(com.intellij.openapi.fileEditor.FileEditor) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) com.intellij.psi.search(com.intellij.psi.search) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) FindSettings(com.intellij.find.FindSettings) NotNull(org.jetbrains.annotations.NotNull) Factory(com.intellij.openapi.util.Factory) LightweightHint(com.intellij.ui.LightweightHint) NavigationItem(com.intellij.navigation.NavigationItem) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ArrayUtil(com.intellij.util.ArrayUtil) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) NonNls(org.jetbrains.annotations.NonNls) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProgressManagerImpl(com.intellij.openapi.progress.impl.ProgressManagerImpl) UsageInfo(com.intellij.usageView.UsageInfo) ContainerUtil(com.intellij.util.containers.ContainerUtil) AtomicReference(java.util.concurrent.atomic.AtomicReference) ActionManager(com.intellij.openapi.actionSystem.ActionManager) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Comparing(com.intellij.openapi.util.Comparing) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) LanguageFindUsages(com.intellij.lang.findUsages.LanguageFindUsages) Project(com.intellij.openapi.project.Project) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.usages(com.intellij.usages) Key(com.intellij.openapi.util.Key) AnAction(com.intellij.openapi.actionSystem.AnAction) Editor(com.intellij.openapi.editor.Editor) CachingConstructorInjectionComponentAdapter(com.intellij.util.pico.CachingConstructorInjectionComponentAdapter) UsageViewUtil(com.intellij.usageView.UsageViewUtil) HintManagerImpl(com.intellij.codeInsight.hint.HintManagerImpl) HintManager(com.intellij.codeInsight.hint.HintManager) javax.swing(javax.swing) Processor(com.intellij.util.Processor) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Project(com.intellij.openapi.project.Project) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) CommonProcessors(com.intellij.util.CommonProcessors) UsageInfo(com.intellij.usageView.UsageInfo) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 78 with Processor

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

the class FindInProjectManager method startFindInProject.

public void startFindInProject(@NotNull FindModel findModel) {
    if (findModel.getDirectoryName() != null && FindInProjectUtil.getDirectory(findModel) == null) {
        return;
    }
    com.intellij.usages.UsageViewManager manager = com.intellij.usages.UsageViewManager.getInstance(myProject);
    if (manager == null)
        return;
    final FindManager findManager = FindManager.getInstance(myProject);
    findManager.getFindInProjectModel().copyFrom(findModel);
    final FindModel findModelCopy = findModel.clone();
    final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(FindSettings.getInstance().isShowResultsInSeparateView(), findModelCopy);
    final boolean showPanelIfOnlyOneUsage = !FindSettings.getInstance().isSkipResultsWithOneUsage();
    final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, presentation);
    ConfigurableUsageTarget usageTarget = new FindInProjectUtil.StringUsageTarget(myProject, findModel);
    ((FindManagerImpl) FindManager.getInstance(myProject)).getFindUsagesManager().addToHistory(usageTarget);
    manager.searchAndShowUsages(new UsageTarget[] { usageTarget }, () -> processor -> {
        myIsFindInProgress = true;
        try {
            Processor<UsageInfo> consumer = info -> {
                Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
                usage.getPresentation().getIcon();
                return processor.process(usage);
            };
            FindInProjectUtil.findUsages(findModelCopy, myProject, consumer, processPresentation);
        } finally {
            myIsFindInProgress = false;
        }
    }, processPresentation, presentation, null);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) FindManagerImpl(com.intellij.find.impl.FindManagerImpl) com.intellij.usages(com.intellij.usages) Content(com.intellij.ui.content.Content) UsageInfo(com.intellij.usageView.UsageInfo) FindInProjectUtil(com.intellij.find.impl.FindInProjectUtil) FindManager(com.intellij.find.FindManager) ReplaceInProjectManager(com.intellij.find.replaceInProject.ReplaceInProjectManager) PlatformDataKeys(com.intellij.openapi.actionSystem.PlatformDataKeys) ServiceManager(com.intellij.openapi.components.ServiceManager) Processor(com.intellij.util.Processor) FindModel(com.intellij.find.FindModel) Project(com.intellij.openapi.project.Project) FindSettings(com.intellij.find.FindSettings) NotNull(org.jetbrains.annotations.NotNull) UsageViewManager(com.intellij.usageView.UsageViewManager) FindModel(com.intellij.find.FindModel) FindManager(com.intellij.find.FindManager) com.intellij.usages(com.intellij.usages) UsageInfo(com.intellij.usageView.UsageInfo)

Example 79 with Processor

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

the class RefResolveServiceImpl method processBatch.

private void processBatch(@NotNull final ProgressIndicator indicator, @NotNull Set<VirtualFile> files) {
    assert !myApplication.isDispatchThread();
    final int resolvedInPreviousBatch = this.resolvedInPreviousBatch;
    final int totalSize = files.size() + resolvedInPreviousBatch;
    final ConcurrentIntObjectMap<int[]> fileToForwardIds = ContainerUtil.createConcurrentIntObjectMap();
    final Set<VirtualFile> toProcess = Collections.synchronizedSet(files);
    indicator.setIndeterminate(false);
    ProgressIndicatorUtils.forceWriteActionPriority(indicator, (Disposable) indicator);
    long start = System.currentTimeMillis();
    Processor<VirtualFile> processor = file -> {
        double fraction = 1 - toProcess.size() * 1.0 / totalSize;
        indicator.setFraction(fraction);
        try {
            if (!file.isDirectory() && toResolve(file, myProject)) {
                int fileId = getAbsId(file);
                int i = totalSize - toProcess.size();
                indicator.setText(i + "/" + totalSize + ": Resolving " + file.getPresentableUrl());
                int[] forwardIds = processFile(file, fileId, indicator);
                if (forwardIds == null) {
                    return false;
                }
                fileToForwardIds.put(fileId, forwardIds);
            }
            toProcess.remove(file);
            return true;
        } catch (RuntimeException e) {
            indicator.checkCanceled();
        }
        return true;
    };
    boolean success = true;
    try {
        success = processFilesConcurrently(files, indicator, processor);
    } finally {
        this.resolvedInPreviousBatch = toProcess.isEmpty() ? 0 : totalSize - toProcess.size();
        queue(toProcess, "re-added after fail. success=" + success);
        storeIds(fileToForwardIds);
        long end = System.currentTimeMillis();
        log("Resolved batch of " + (totalSize - toProcess.size()) + " from " + totalSize + " files in " + ((end - start) / 1000) + "sec. (Gap: " + storage.gap + ")");
        synchronized (filesToResolve) {
            upToDate = filesToResolve.isEmpty();
            log("upToDate = " + upToDate);
            if (upToDate) {
                for (Listener listener : myListeners) {
                    listener.allFilesResolved();
                }
            }
        }
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) PowerSaveMode(com.intellij.ide.PowerSaveMode) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) Future(java.util.concurrent.Future) Task(com.intellij.openapi.progress.Task) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Disposer(com.intellij.openapi.util.Disposer) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) DateFormat(java.text.DateFormat) ProgressManager(com.intellij.openapi.progress.ProgressManager) com.intellij.openapi.project(com.intellij.openapi.project) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PersistentFS(com.intellij.openapi.vfs.newvfs.persistent.PersistentFS) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) Function(com.intellij.util.Function) Processor(com.intellij.util.Processor) ConcurrentBitSet(com.intellij.util.containers.ConcurrentBitSet) gnu.trove(gnu.trove) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) PathManager(com.intellij.openapi.application.PathManager) ApplicationUtil(com.intellij.openapi.application.ex.ApplicationUtil) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FutureTask(java.util.concurrent.FutureTask) ProgressManagerImpl(com.intellij.openapi.progress.impl.ProgressManagerImpl) Callable(java.util.concurrent.Callable) ProgressIndicatorUtils(com.intellij.openapi.progress.util.ProgressIndicatorUtils) ContainerUtil(com.intellij.util.containers.ContainerUtil) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) FSRecords(com.intellij.openapi.vfs.newvfs.persistent.FSRecords) StartupManager(com.intellij.openapi.startup.StartupManager) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) StringUtil(com.intellij.openapi.util.text.StringUtil) FileWriter(java.io.FileWriter) IOException(java.io.IOException) ConcurrentIntObjectMap(com.intellij.util.containers.ConcurrentIntObjectMap) Disposable(com.intellij.openapi.Disposable) File(java.io.File) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExceptionUtil(com.intellij.util.ExceptionUtil) ApplicationAdapter(com.intellij.openapi.application.ApplicationAdapter) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) com.intellij.openapi.vfs(com.intellij.openapi.vfs) MessageBus(com.intellij.util.messages.MessageBus) HeavyProcessLatch(com.intellij.util.io.storage.HeavyProcessLatch) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener)

Example 80 with Processor

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

the class Struts2GlobalVariableProvider method getGlobalVariables.

@NotNull
public List<? extends FtlVariable> getGlobalVariables(final FtlFile file) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module == null) {
        return Collections.emptyList();
    }
    if (StrutsFacet.getInstance(module) == null) {
        return Collections.emptyList();
    }
    final List<FtlVariable> result = new ArrayList<>();
    result.add(new MyFtlLightVariable("stack", file, (FtlType) null));
    result.add(new MyFtlLightVariable("response", file, WebCommonClassNames.HTTP_SERVLET_RESPONSE));
    result.add(new MyFtlLightVariable("res", file, WebCommonClassNames.HTTP_SERVLET_RESPONSE));
    result.add(new MyFtlLightVariable("request", file, WebCommonClassNames.HTTP_SERVLET_REQUEST));
    result.add(new MyFtlLightVariable("req", file, WebCommonClassNames.HTTP_SERVLET_REQUEST));
    result.add(new MyFtlLightVariable("session", file, WebCommonClassNames.HTTP_SESSION));
    result.add(new MyFtlLightVariable("application", file, WebCommonClassNames.SERVLET_CONTEXT));
    result.add(new MyFtlLightVariable("base", file, CommonClassNames.JAVA_LANG_STRING));
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_STRUTS_UI_URI, StrutsConstants.TAGLIB_STRUTS_UI_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_RICHTEXT_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_RICHTEXT_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_CHART_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_CHART_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_TREE_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_TREE_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_GRID_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_GRID_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_MOBILE_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_MOBILE_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_BOOTSTRAP_PLUGIN_URI, StrutsConstants.TAGLIB_BOOTSTRAP_PLUGIN_PREFIX);
    final Processor<Action> processor = action -> {
        final PsiClass actionClass = action.searchActionClass();
        if (actionClass != null) {
            for (final Result result1 : action.getResults()) {
                final ResultType resultType = result1.getEffectiveResultType();
                if (resultType != null && FreeMarkerStrutsResultContributor.FREEMARKER.equals(resultType.getName().getStringValue())) {
                    final PathReference reference = result1.getValue();
                    final PsiElement target = reference == null ? null : reference.resolve();
                    if (target != null && (file.getManager().areElementsEquivalent(file, target) || file.getManager().areElementsEquivalent(file.getOriginalFile(), target))) {
                        final PsiClassType actionType = PsiTypesUtil.getClassType(actionClass);
                        final FtlPsiType ftlPsiType = FtlPsiType.wrap(actionType);
                        result.add(new MyFtlLightVariable("", action.getXmlTag(), ftlPsiType));
                        result.add(new MyFtlLightVariable("action", action.getXmlTag(), ftlPsiType));
                        return false;
                    }
                }
            }
        }
        return true;
    };
    for (final StrutsModel model : StrutsManager.getInstance(file.getProject()).getAllModels(module)) {
        model.processActions(processor);
    }
    return result;
}
Also used : PsiTypesUtil(com.intellij.psi.util.PsiTypesUtil) PathReference(com.intellij.openapi.paths.PathReference) XmlFile(com.intellij.psi.xml.XmlFile) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) NonNls(org.jetbrains.annotations.NonNls) Action(com.intellij.struts2.dom.struts.action.Action) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) FtlPsiType(com.intellij.freemarker.psi.variables.FtlPsiType) Result(com.intellij.struts2.dom.struts.action.Result) FtlFile(com.intellij.freemarker.psi.files.FtlFile) ArrayList(java.util.ArrayList) StrutsFacet(com.intellij.struts2.facet.StrutsFacet) FtlXmlNamespaceType(com.intellij.freemarker.psi.files.FtlXmlNamespaceType) FtlGlobalVariableProvider(com.intellij.freemarker.psi.files.FtlGlobalVariableProvider) XmlDocument(com.intellij.psi.xml.XmlDocument) FtlLightVariable(com.intellij.freemarker.psi.variables.FtlLightVariable) Module(com.intellij.openapi.module.Module) StrutsConstants(com.intellij.struts2.StrutsConstants) FtlVariable(com.intellij.freemarker.psi.variables.FtlVariable) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) StrutsIcons(com.intellij.struts2.StrutsIcons) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) WebCommonClassNames(com.intellij.javaee.web.WebCommonClassNames) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Processor(com.intellij.util.Processor) FtlType(com.intellij.freemarker.psi.FtlType) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) JspManager(com.intellij.psi.impl.source.jsp.JspManager) javax.swing(javax.swing) PathReference(com.intellij.openapi.paths.PathReference) Action(com.intellij.struts2.dom.struts.action.Action) ArrayList(java.util.ArrayList) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Result(com.intellij.struts2.dom.struts.action.Result) FtlVariable(com.intellij.freemarker.psi.variables.FtlVariable) FtlPsiType(com.intellij.freemarker.psi.variables.FtlPsiType) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) FtlType(com.intellij.freemarker.psi.FtlType) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

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