Java Code Examples for com.intellij.util.CommonProcessors#CollectProcessor

The following examples show how to use com.intellij.util.CommonProcessors#CollectProcessor . 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: UnityScriptGotoClassContributor.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public String[] getNames(Project project, boolean includeNonProjectItems)
{
	CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(ContainerUtil.<String>newTroveSet());
	processNames(processor, GlobalSearchScope.allScope(project), IdFilter.getProjectIdFilter(project, includeNonProjectItems));
	return processor.toArray(ArrayUtil.STRING_ARRAY_FACTORY);
}
 
Example 2
Source File: UnityScriptGotoClassContributor.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems)
{
	CommonProcessors.CollectProcessor<NavigationItem> processor = new CommonProcessors.CollectProcessor<NavigationItem>(ContainerUtil.<NavigationItem>newTroveSet());
	processElementsWithName(name, processor, new FindSymbolParameters(pattern, name, GlobalSearchScope.allScope(project), IdFilter.getProjectIdFilter(project, includeNonProjectItems)));
	return processor.toArray(NavigationItem.ARRAY_FACTORY);
}
 
Example 3
Source File: OverrideUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public static Collection<PsiElement> getAllMembers(@Nonnull final PsiElement targetTypeDeclaration,
		@Nonnull GlobalSearchScope scope,
		@Nonnull DotNetGenericExtractor extractor,
		boolean completion,
		boolean overrideTool)
{
	final CommonProcessors.CollectProcessor<PsiElement> collectProcessor = new CommonProcessors.CollectProcessor<>();
	CSharpResolveContext context = CSharpResolveContextUtil.createContext(extractor, scope, targetTypeDeclaration);
	// process method & properties
	context.processElements(collectProcessor, true);
	// process index methods
	CSharpElementGroup<CSharpIndexMethodDeclaration> group = context.indexMethodGroup(true);
	if(group != null)
	{
		group.process(collectProcessor);
	}

	Collection<PsiElement> results = collectProcessor.getResults();

	List<PsiElement> mergedElements = CSharpResolveUtil.mergeGroupsToIterable(results);
	List<PsiElement> psiElements = OverrideUtil.filterOverrideElements(targetTypeDeclaration, mergedElements, OverrideProcessor.ALWAYS_TRUE);

	List<PsiElement> elements = CSharpResolveUtil.mergeGroupsToIterable(psiElements);
	if(overrideTool)
	{
		// filter self methods, we need it in circular extends
		elements = ContainerUtil.filter(elements, element ->
		{
			ProgressManager.checkCanceled();
			return element.getParent() != targetTypeDeclaration;
		});
	}
	return completion ? elements : ContainerUtil.filter(elements, element ->
	{
		ProgressManager.checkCanceled();
		return !(element instanceof DotNetTypeDeclaration);
	});
}
 
Example 4
Source File: CSharpArrayInitializerCompositeValueImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public ResolveResult[] multiResolve(boolean incompleteCode)
{
	CSharpArrayInitializerOwner arrayInitializerOwner = PsiTreeUtil.getParentOfType(this, CSharpArrayInitializerOwner.class);
	if(arrayInitializerOwner instanceof CSharpNewExpressionImpl)
	{
		DotNetTypeRef typeRef = ((CSharpNewExpressionImpl) arrayInitializerOwner).toTypeRef(false);
		if(typeRef == DotNetTypeRef.ERROR_TYPE)
		{
			return ResolveResult.EMPTY_ARRAY;
		}

		DotNetTypeResolveResult typeResolveResult = typeRef.resolve();
		PsiElement resolvedElement = typeResolveResult.getElement();
		if(resolvedElement == null)
		{
			return ResolveResult.EMPTY_ARRAY;
		}

		CSharpResolveOptions options = new CSharpResolveOptions(CSharpReferenceExpression.ResolveToKind.METHOD,
				new MemberByNameSelector("Add"), this, this, false, true);

		CommonProcessors.CollectProcessor<ResolveResult> processor = new CommonProcessors.CollectProcessor<ResolveResult>();
		CSharpReferenceExpressionImplUtil.collectResults(options, typeResolveResult.getGenericExtractor(), resolvedElement, processor);
		return processor.toArray(ResolveResult.ARRAY_FACTORY);
	}
	return ResolveResult.EMPTY_ARRAY;
}
 
Example 5
Source File: CSharpArrayInitializerSingleValueImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public ResolveResult[] multiResolve(boolean b)
{
	CSharpArrayInitializerOwner arrayInitializerOwner = PsiTreeUtil.getParentOfType(this, CSharpArrayInitializerOwner.class);
	if(arrayInitializerOwner instanceof CSharpNewExpressionImpl)
	{
		DotNetTypeRef typeRef = ((CSharpNewExpressionImpl) arrayInitializerOwner).toTypeRef(false);
		if(typeRef == DotNetTypeRef.ERROR_TYPE)
		{
			return ResolveResult.EMPTY_ARRAY;
		}

		DotNetTypeResolveResult typeResolveResult = typeRef.resolve();
		PsiElement resolvedElement = typeResolveResult.getElement();
		if(resolvedElement == null)
		{
			return ResolveResult.EMPTY_ARRAY;
		}

		CSharpResolveOptions options = new CSharpResolveOptions(CSharpReferenceExpression.ResolveToKind.METHOD,
				new MemberByNameSelector("Add"), this, this, false, true);

		CommonProcessors.CollectProcessor<ResolveResult> processor = new CommonProcessors.CollectProcessor<ResolveResult>();
		CSharpReferenceExpressionImplUtil.collectResults(options, typeResolveResult.getGenericExtractor(), resolvedElement, processor);
		return processor.toArray(ResolveResult.ARRAY_FACTORY);
	}
	return ResolveResult.EMPTY_ARRAY;
}
 
Example 6
Source File: CSharpDictionaryInitializerImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public ResolveResult[] multiResolve(boolean b)
{
	CSharpArrayInitializerOwner arrayInitializerOwner = PsiTreeUtil.getParentOfType(this, CSharpArrayInitializerOwner.class);
	if(arrayInitializerOwner instanceof CSharpNewExpressionImpl)
	{
		DotNetTypeRef typeRef = ((CSharpNewExpressionImpl) arrayInitializerOwner).toTypeRef(false);
		if(typeRef == DotNetTypeRef.ERROR_TYPE)
		{
			return ResolveResult.EMPTY_ARRAY;
		}

		DotNetTypeResolveResult typeResolveResult = typeRef.resolve();
		PsiElement resolvedElement = typeResolveResult.getElement();
		if(resolvedElement == null)
		{
			return ResolveResult.EMPTY_ARRAY;
		}

		CSharpResolveOptions options = new CSharpResolveOptions(CSharpReferenceExpression.ResolveToKind.METHOD,
				new MemberByNameSelector("Add"), this, this, false, true);

		CommonProcessors.CollectProcessor<ResolveResult> processor = new CommonProcessors.CollectProcessor<ResolveResult>();
		CSharpReferenceExpressionImplUtil.collectResults(options, typeResolveResult.getGenericExtractor(), resolvedElement, processor);
		return processor.toArray(ResolveResult.ARRAY_FACTORY);
	}
	return ResolveResult.EMPTY_ARRAY;
}
 
Example 7
Source File: CSharpTypeNameContributor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public String[] getNames(Project project, boolean includeNonProjectItems)
{
	CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(ContainerUtil.<String>newTroveSet());
	processNames(processor, GlobalSearchScope.allScope(project), IdFilter.getProjectIdFilter(project, includeNonProjectItems));
	return processor.toArray(ArrayUtil.STRING_ARRAY_FACTORY);
}
 
Example 8
Source File: CSharpTypeNameContributor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public NavigationItem[] getItemsByName(String name, final String pattern, Project project, boolean includeNonProjectItems)
{
	CommonProcessors.CollectProcessor<NavigationItem> processor = new CommonProcessors.CollectProcessor<NavigationItem>(ContainerUtil.<NavigationItem>newTroveSet());
	processElementsWithName(name, processor, new FindSymbolParameters(pattern, name, GlobalSearchScope.allScope(project), IdFilter.getProjectIdFilter(project, includeNonProjectItems)));
	return processor.toArray(NavigationItem.ARRAY_FACTORY);
}
 
Example 9
Source File: IndexCacheManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public PsiFile[] getFilesWithWord(@Nonnull final String word, final short occurenceMask, @Nonnull final GlobalSearchScope scope, final boolean caseSensitively) {
  if (myProject.isDefault()) {
    return PsiFile.EMPTY_ARRAY;
  }
  CommonProcessors.CollectProcessor<PsiFile> processor = new CommonProcessors.CollectProcessor<PsiFile>();
  processFilesWithWord(processor, word, occurenceMask, scope, caseSensitively);
  return processor.getResults().isEmpty() ? PsiFile.EMPTY_ARRAY : processor.toArray(PsiFile.EMPTY_ARRAY);
}
 
Example 10
Source File: EditorHyperlinkSupport.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static List<RangeHighlighter> getHyperlinks(int startOffset, int endOffset, final Editor editor) {
  final MarkupModelEx markupModel = (MarkupModelEx)editor.getMarkupModel();
  final CommonProcessors.CollectProcessor<RangeHighlighterEx> processor = new CommonProcessors.CollectProcessor<>();
  markupModel.processRangeHighlightersOverlappingWith(startOffset, endOffset,
                                                      new FilteringProcessor<>(rangeHighlighterEx -> rangeHighlighterEx.isValid() && getHyperlinkInfo(rangeHighlighterEx) != null, processor));
  return new ArrayList<>(processor.getResults());
}
 
Example 11
Source File: InplaceRefactoring.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected Collection<PsiReference> collectRefs(SearchScope referencesSearchScope) {
  final Query<PsiReference> search = ReferencesSearch.search(myElementToRename, referencesSearchScope, false);

  final CommonProcessors.CollectProcessor<PsiReference> processor = new CommonProcessors.CollectProcessor<PsiReference>() {
    @Override
    protected boolean accept(PsiReference reference) {
      return acceptReference(reference);
    }
  };

  search.forEach(processor);
  return processor.getResults();
}
 
Example 12
Source File: SortedMemberResolveScopeProcessor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
private void initThisProcessor()
{
	myResultProcessor = new CommonProcessors.CollectProcessor<>(new LinkedHashSet<>());
}
 
Example 13
Source File: HaxeSymbolIndex.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
public static String[] getAllSymbols(@NotNull final GlobalSearchScope scope) {
  HaxeIndexUtil.warnIfDumbMode(scope.getProject());
  final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>();
  FileBasedIndex.getInstance().processAllKeys(HAXE_SYMBOL_INDEX, processor, scope, null);
  return ArrayUtil.toStringArray(processor.getResults());
}