Java Code Examples for com.intellij.util.Processor#process()
The following examples show how to use
com.intellij.util.Processor#process() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseKindProcessor.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @Override public void process(@Nonnull CSharpResolveOptions options, @Nonnull DotNetGenericExtractor defaultExtractor, @Nullable PsiElement forceQualifierElement, @Nonnull Processor<ResolveResult> processor) { PsiElement element = options.getElement(); DotNetTypeDeclaration thisTypeDeclaration = PsiTreeUtil.getParentOfType(element, DotNetTypeDeclaration.class); if(thisTypeDeclaration != null) { Pair<DotNetTypeDeclaration, DotNetGenericExtractor> pair = CSharpTypeDeclarationImplUtil.resolveBaseType(thisTypeDeclaration, element); if(pair != null) { processor.process(new CSharpResolveResultWithExtractor(pair.getFirst(), pair.getSecond())); } } }
Example 2
Source File: RootNamespaceKindProcessor.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @Override public void process(@Nonnull CSharpResolveOptions options, @Nonnull DotNetGenericExtractor defaultExtractor, @Nullable PsiElement forceQualifierElement, @Nonnull Processor<ResolveResult> processor) { PsiElement element = options.getElement(); DotNetNamespaceAsElement temp = DotNetPsiSearcher.getInstance(element.getProject()).findNamespace("", element.getResolveScope()); if(temp == null) { return; } processor.process(new CSharpResolveResult(temp)); }
Example 3
Source File: CSharpNamespaceResolveContext.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @Override public boolean processElements(@Nonnull Processor<PsiElement> processor, boolean deep) { DotNetNamespaceAsElement.ChildrenFilter filter = DotNetNamespaceAsElement.ChildrenFilter.ONLY_ELEMENTS; if(StringUtil.isEmpty(myNamespaceAsElement.getPresentableQName())) { filter = DotNetNamespaceAsElement.ChildrenFilter.NONE; } Collection<PsiElement> children = myNamespaceAsElement.getChildren(myResolveScope, CSharpTransformer.INSTANCE, filter); children = CSharpCompositeTypeDeclaration.wrapPartialTypes(myResolveScope, myNamespaceAsElement.getProject(), children); for(PsiElement element : children) { ProgressManager.checkCanceled(); if(!processor.process(element)) { return false; } } return true; }
Example 4
Source File: PantsUtil.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
/** * {@code processor} should return false if we don't want to step into the directory. */ public static void traverseDirectoriesRecursively(@NotNull File root, @NotNull Processor<File> processor) { final LinkedList<File> queue = new LinkedList<>(); queue.add(root); while (!queue.isEmpty()) { final File file = queue.removeFirst(); if (file.isFile()) { continue; } if (!processor.process(file)) { continue; } final File[] children = file.listFiles(); if (children != null) { ContainerUtil.addAll(queue, children); } } }
Example 5
Source File: BlazeGoPackage.java From intellij with Apache License 2.0 | 6 votes |
/** * Override {@link GoPackage#processFiles(Processor, Predicate)} to work on specific files instead * of by directory. */ @Override public boolean processFiles( Processor<? super PsiFile> processor, Predicate<VirtualFile> virtualFileFilter) { if (!isValid()) { return true; } FileIndexFacade fileIndexFacade = FileIndexFacade.getInstance(getProject()); for (PsiFile file : files()) { ProgressIndicatorProvider.checkCanceled(); VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile.isValid() && virtualFileFilter.test(virtualFile) && !fileIndexFacade.isExcludedFile(virtualFile) && !processor.process(file)) { return false; } } return true; }
Example 6
Source File: WeightUtil.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction public static void sortAndProcess(@Nonnull List<MethodResolveResult> list, @Nonnull Processor<ResolveResult> processor, @Nonnull PsiElement place) { if(list.isEmpty()) { return; } ContainerUtil.sort(list, ourComparator); for(MethodResolveResult methodResolveResult : list) { ProgressManager.checkCanceled(); methodResolveResult.setAssignable(place); if(!processor.process(methodResolveResult)) { return; } } }
Example 7
Source File: GlobReferenceSearcher.java From intellij with Apache License 2.0 | 6 votes |
@Override public void processQuery( SearchParameters queryParameters, Processor<? super PsiReference> consumer) { PsiFileSystemItem file = ResolveUtil.asFileSystemItemSearch(queryParameters.getElementToSearch()); if (file == null) { return; } BlazePackage containingPackage = BlazePackage.getContainingPackage(file); if (containingPackage == null || !inScope(queryParameters, containingPackage.buildFile)) { return; } String relativePath = containingPackage.getRelativePathToChild(file.getVirtualFile()); if (relativePath == null) { return; } List<GlobExpression> globs = PsiUtils.findAllChildrenOfClassRecursive(containingPackage.buildFile, GlobExpression.class); for (GlobExpression glob : globs) { if (glob.matches(relativePath, file.isDirectory())) { consumer.process(globReference(glob, file)); } } }
Example 8
Source File: SearchStringItemProvider.java From android-strings-search-plugin with Apache License 2.0 | 6 votes |
@Override public boolean filterElements(@NotNull ChooseByNameBase base, @NotNull String pattern, boolean everywhere, @NotNull ProgressIndicator indicator, @NotNull Processor<Object> consumer) { Collection<StringElement> elements = ((SearchStringModel) base.getModel()).getFilterItems(); if (elements != null) { for (StringElement element : elements) { String value = element.getValue(); if (value == null) { return false; } if (value.toLowerCase().contains(pattern.toLowerCase()) && !consumer.process(element)) { return false; } } } return false; }
Example 9
Source File: BlazeCppAutoImportHelper.java From intellij with Apache License 2.0 | 5 votes |
/** * Search in the configuration's header roots only. All other cases are covered by CLion's default * implementation. */ @Override public boolean processPathSpecificationToInclude( Project project, @Nullable VirtualFile targetFile, VirtualFile fileToImport, OCResolveRootAndConfiguration rootAndConfiguration, Processor<ImportSpecification> processor) { // Check "system" roots first. "user" roots may include the workspace root, and the system // headers might be checked into source control, which would make it under the workspace root // as well. NOTE: this is a bit backward compared to the actual #include search roots priority, // where system search roots are checked later. OCResolveConfiguration resolveConfiguration = rootAndConfiguration.getConfiguration(); if (resolveConfiguration == null) { return false; } ImportSpecification specification = findMatchingRoot( fileToImport, getHeaderRoots(rootAndConfiguration), /* asUserHeader= */ false); if (specification != null && !processor.process(specification)) { return false; } specification = findMatchingRoot( fileToImport, getHeaderRoots(rootAndConfiguration), /* asUserHeader= */ true); return specification == null || processor.process(specification); }
Example 10
Source File: ResolveUtil.java From intellij with Apache License 2.0 | 5 votes |
/** @return false if processing was stopped */ public static boolean visitChildAssignmentStatements( BuildElement parent, Processor<TargetExpression> processor) { for (AssignmentStatement stmt : parent.childrenOfClass(AssignmentStatement.class)) { TargetExpression target = stmt.getLeftHandSideExpression(); if (target != null && !processor.process(target)) { return false; } } return true; }
Example 11
Source File: ORModuleContributor.java From reasonml-idea-plugin with MIT License | 5 votes |
@Override public void processElementsWithName(@NotNull String name, @NotNull Processor<? super NavigationItem> processor, @NotNull FindSymbolParameters parameters) { Project project = parameters.getProject(); GlobalSearchScope scope = parameters.getSearchScope(); for (PsiModule psiModule : PsiFinder.getInstance(project).findModulesbyName(name, ORFileType.both, null, scope)) { processor.process(psiModule); } }
Example 12
Source File: HookSubscriberUtil.java From idea-php-shopware-plugin with MIT License | 5 votes |
public static void visitDoctrineQueryBuilderClasses(Project project, Processor<PhpClass> processor) { for(PhpClass phpClass: PhpIndex.getInstance(project).getAllSubclasses("\\Shopware\\Components\\Model\\ModelRepository")) { if(!processor.process(phpClass)) { return; } } }
Example 13
Source File: ResolveUtil.java From intellij with Apache License 2.0 | 5 votes |
/** Walks up PSI tree of local file, checking PsiNamedElements */ public static void searchInScope(PsiElement originalElement, Processor<BuildElement> processor) { // TODO: Handle list comprehension (where variable is defined *later* in the code) boolean topLevelScope = true; PsiElement element = originalElement; while (!(element instanceof PsiFileSystemItem)) { PsiElement parent = element.getParent(); if (parent instanceof BuildFile) { if (!((BuildFile) parent).searchSymbolsInScope(processor, topLevelScope ? element : null)) { return; } } else if (parent instanceof FunctionStatement) { topLevelScope = false; for (Parameter param : ((FunctionStatement) parent).getParameters()) { if (!processor.process(param)) { return; } } } else if (parent instanceof ForStatement) { for (Expression expr : ((ForStatement) parent).getForLoopVariables()) { if (expr instanceof TargetExpression && !processor.process(expr)) { return; } } } else if (parent instanceof StatementList) { if (!visitChildAssignmentStatements((BuildElement) parent, (Processor) processor)) { return; } } element = parent; } }
Example 14
Source File: CSharpElementGroupImpl.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override public boolean process(@Nonnull Processor<? super T> processor) { for(T element : myElements) { ProgressManager.checkCanceled(); if(!processor.process(element)) { return false; } } return true; }
Example 15
Source File: HaxeComponentIndex.java From intellij-haxe with Apache License 2.0 | 5 votes |
public static void processAll(Project project, Processor<Pair<String, HaxeClassInfo>> processor, GlobalSearchScope scope) { HaxeIndexUtil.warnIfDumbMode(project); final Collection<String> keys = getNames(project); for (String key : keys) { final List<HaxeClassInfo> values = FileBasedIndex.getInstance().getValues(HAXE_COMPONENT_INDEX, key, scope); for (HaxeClassInfo value : values) { final Pair<String, HaxeClassInfo> pair = Pair.create(key, value); if (!processor.process(pair)) { return; } } } }
Example 16
Source File: HaxeFindUsagesHandler.java From intellij-haxe with Apache License 2.0 | 5 votes |
@NotNull private static ReadActionProcessor<PsiReference> getConstructorSearchProcessor(@NotNull Processor<UsageInfo> processor) { return new ReadActionProcessor<PsiReference>() { @Override public boolean processInReadAction(PsiReference reference) { PsiElement refElement = reference.getElement(); final PsiElement parent = refElement.getParent(); if (parent instanceof HaxeType && parent.getParent() instanceof HaxeNewExpression) { TextRange rangeInElement = reference.getRangeInElement(); processor.process(new UsageInfo(refElement, rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), false)); } return true; } }; }
Example 17
Source File: HaxeFindUsagesHandler.java From intellij-haxe with Apache License 2.0 | 5 votes |
@NotNull private static ReadActionProcessor<PsiReference> getSimpleSearchProcessor(@NotNull Processor<UsageInfo> processor) { return new ReadActionProcessor<PsiReference>() { @Override public boolean processInReadAction(final PsiReference ref) { TextRange rangeInElement = ref.getRangeInElement(); return processor .process(new UsageInfo(ref.getElement(), rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), false)); } }; }
Example 18
Source File: BlazePackage.java From intellij with Apache License 2.0 | 4 votes |
private static void processDirectory(Processor<PsiFile> processor, PsiDirectory directory) { for (PsiFile file : directory.getFiles()) { processor.process(file); } }
Example 19
Source File: CSharpDirectTypeInheritorsSearcherExecutor.java From consulo-csharp with Apache License 2.0 | 4 votes |
@Override public boolean execute(@Nonnull final DirectTypeInheritorsSearch.SearchParameters p, @Nonnull final Processor<? super DotNetTypeDeclaration> consumer) { String vmQName = p.getVmQName(); /*if(DotNetTypes.System_Object.equals(qualifiedName)) { final SearchScope scope = useScope; return AllClassesSearch.search(scope, aClass.getProject()).forEach(new Processor<DotNetTypeDeclaration>() { @Override public boolean process(final DotNetTypeDeclaration typeDcl) { if(typeDcl.isInterface()) { return consumer.process(typeDcl); } final DotNetTypeDeclaration superClass = typeDcl.getSuperClass(); if(superClass != null && DotNetTypes.System_Object.equals(ApplicationManager.getApplication().runReadAction( new Computable<String>() { public String compute() { return superClass.getPresentableQName(); } }))) { return consumer.process(typeDcl); } return true; } }); } */ SearchScope useScope = p.getScope(); final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope) useScope : new EverythingGlobalScope(p .getProject()); final String searchKey = MsilHelper.cutGenericMarker(StringUtil.getShortName(vmQName)); if(StringUtil.isEmpty(searchKey)) { return true; } Collection<DotNetTypeList> candidates = ApplicationManager.getApplication().runReadAction((Computable<Collection<DotNetTypeList>>) () -> ExtendsListIndex.getInstance().get(searchKey, p.getProject(), scope)); Map<String, List<DotNetTypeDeclaration>> classes = new HashMap<>(); for(DotNetTypeList referenceList : candidates) { ProgressIndicatorProvider.checkCanceled(); final DotNetTypeDeclaration candidate = ReadAction.compute(() -> (DotNetTypeDeclaration) referenceList.getParent()); if(!checkInheritance(p, vmQName, candidate)) { continue; } String fqn = ReadAction.compute(candidate::getPresentableQName); List<DotNetTypeDeclaration> list = classes.get(fqn); if(list == null) { list = new ArrayList<>(); classes.put(fqn, list); } list.add(candidate); } for(List<DotNetTypeDeclaration> sameNamedClasses : classes.values()) { for(DotNetTypeDeclaration sameNamedClass : sameNamedClasses) { if(!consumer.process(sameNamedClass)) { return false; } } } return true; }
Example 20
Source File: FindUsagesImpl171.java From Android-Resource-Usage-Count with MIT License | 4 votes |
@NotNull private static UsageSearcher createUsageSearcher(@NotNull final PsiElement[] primaryElements, @NotNull final PsiElement[] secondaryElements, @NotNull final FindUsagesHandler handler, @NotNull FindUsagesOptions options, final PsiFile scopeFile) { final FindUsagesOptions optionsClone = options.clone(); return new UsageSearcher() { public void generate(@NotNull final Processor<Usage> processor) { Project project = (Project) ApplicationManager.getApplication().runReadAction(new Computable() { public Project compute() { return scopeFile != null?scopeFile.getProject():primaryElements[0].getProject(); } }); dropResolveCacheRegularly(ProgressManager.getInstance().getProgressIndicator(), project); if(scopeFile != null) { optionsClone.searchScope = new LocalSearchScope(scopeFile); } final CommonProcessors.UniqueProcessor usageInfoProcessor = new CommonProcessors.UniqueProcessor(new Processor<UsageInfo>() { @Override public boolean process(final UsageInfo usageInfo) { Usage usage = (Usage)ApplicationManager.getApplication().runReadAction(new Computable() { public Usage compute() { return UsageInfoToUsageConverter.convert(primaryElements, usageInfo); } }); return processor.process(usage); } }); Iterable elements = ContainerUtil.concat(new PsiElement[][]{primaryElements, secondaryElements}); optionsClone.fastTrack = new SearchRequestCollector(new SearchSession()); if(optionsClone.searchScope instanceof GlobalSearchScope) { optionsClone.searchScope = optionsClone.searchScope.union(GlobalSearchScope.projectScope(project)); } try { Iterator i$ = elements.iterator(); while(i$.hasNext()) { final PsiElement element = (PsiElement)i$.next(); ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { } }); handler.processElementUsages(element, usageInfoProcessor, optionsClone); CustomUsageSearcher[] arr$ = (CustomUsageSearcher[])Extensions.getExtensions(CustomUsageSearcher.EP_NAME); int len$ = arr$.length; for(int i$1 = 0; i$1 < len$; ++i$1) { CustomUsageSearcher searcher = arr$[i$1]; try { searcher.processElementUsages(element, processor, optionsClone); } catch (IndexNotReadyException var17) { DumbService.getInstance(element.getProject()).showDumbModeNotification("Find usages is not available during indexing"); } catch (ProcessCanceledException var18) { throw var18; } catch (Exception var19) { } } } PsiSearchHelper.SERVICE.getInstance(project).processRequests(optionsClone.fastTrack, new Processor<PsiReference>() { public boolean process(final PsiReference ref) { UsageInfo info = (UsageInfo)ApplicationManager.getApplication().runReadAction(new Computable() { public UsageInfo compute() { return !ref.getElement().isValid()?null:new UsageInfo(ref); } }); return info == null || usageInfoProcessor.process(info); } }); } finally { optionsClone.fastTrack = null; } } }; }