com.intellij.util.CommonProcessors Java Examples

The following examples show how to use com.intellij.util.CommonProcessors. 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: PsiFinder.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@NotNull
public Set<PsiModule> findComponents(@NotNull GlobalSearchScope scope) {
    Project project = scope.getProject();
    if (project == null) {
        return Collections.emptySet();
    }

    Set<PsiModule> result = new HashSet<>();

    BsCompiler bucklescript = ServiceManager.getService(m_project, BsCompiler.class);

    ModuleComponentIndex componentIndex = ModuleComponentIndex.getInstance();
    ModuleIndex moduleIndex = ModuleIndex.getInstance();
    componentIndex.processAllKeys(project, CommonProcessors.processAll(moduleName -> {
        for (PsiModule module : moduleIndex.get(moduleName, project, scope)) {
            FileBase file = (FileBase) module.getContainingFile();
            if (!module.isInterface() && bucklescript.isDependency(file.getVirtualFile())) {
                result.add(module);
            }
        }
    }));

    return result;
}
 
Example #2
Source File: NavBarModel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Object calculateRoot(DataContext dataContext) {
  // Narrow down the root element to the first interesting one
  Module root = dataContext.getData(LangDataKeys.MODULE);

  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) return null;

  Object projectChild;
  Object projectGrandChild = null;

  CommonProcessors.FindFirstAndOnlyProcessor<Object> processor = new CommonProcessors.FindFirstAndOnlyProcessor<>();
  processChildren(project, processor);
  projectChild = processor.reset();
  if (projectChild != null) {
    processChildren(projectChild, processor);
    projectGrandChild = processor.reset();
  }
  return ObjectUtils.chooseNotNull(projectGrandChild, ObjectUtils.chooseNotNull(projectChild, project));
}
 
Example #3
Source File: ShowIntentionsPass.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean markActionInvoked(@Nonnull Project project, @Nonnull final Editor editor, @Nonnull IntentionAction action) {
  final int offset = ((EditorEx)editor).getExpectedCaretOffset();

  List<HighlightInfo> infos = new ArrayList<>();
  DaemonCodeAnalyzerImpl.processHighlightsNearOffset(editor.getDocument(), project, HighlightSeverity.INFORMATION, offset, true, new CommonProcessors.CollectProcessor<>(infos));
  boolean removed = false;
  for (HighlightInfo info : infos) {
    if (info.quickFixActionMarkers != null) {
      for (Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker> pair : info.quickFixActionMarkers) {
        HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first;
        if (actionInGroup.getAction() == action) {
          // no CME because the list is concurrent
          removed |= info.quickFixActionMarkers.remove(pair);
        }
      }
    }
  }
  return removed;
}
 
Example #4
Source File: SmartPointerTracker.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void ensureSorted() {
  if (!mySorted) {
    List<SmartPsiElementPointerImpl<?>> pointers = new ArrayList<>();
    processAlivePointers(new CommonProcessors.CollectProcessor<>(pointers));
    if (size != pointers.size()) throw new AssertionError();

    pointers.sort((p1, p2) -> MarkerCache.INFO_COMPARATOR.compare((SelfElementInfo)p1.getElementInfo(), (SelfElementInfo)p2.getElementInfo()));

    for (int i = 0; i < pointers.size(); i++) {
      //noinspection ConstantConditions
      storePointerReference(references, i, pointers.get(i).pointerReference);
    }
    Arrays.fill(references, pointers.size(), nextAvailableIndex, null);
    nextAvailableIndex = pointers.size();
    mySorted = true;
  }
}
 
Example #5
Source File: IterationState.java    From consulo with Apache License 2.0 6 votes vote down vote up
private HighlighterSweep(@Nonnull MarkupModelEx markupModel, int start, int end, final boolean onlyFullLine, final boolean onlyFontOrForegroundAffecting) {
  myMarkupModel = markupModel;
  myOnlyFullLine = onlyFullLine;
  myOnlyFontOrForegroundAffecting = onlyFontOrForegroundAffecting;
  // we have to get all highlighters in advance and sort them by affected offsets
  // since these can be different from the real offsets the highlighters are sorted by in the tree.  (See LINES_IN_RANGE perverts)
  final List<RangeHighlighterEx> list = new ArrayList<>();
  markupModel.processRangeHighlightersOverlappingWith(myReverseIteration ? end : start, myReverseIteration ? start : end, new CommonProcessors.CollectProcessor<RangeHighlighterEx>(list) {
    @Override
    protected boolean accept(RangeHighlighterEx ex) {
      return (!onlyFullLine || ex.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) && (!onlyFontOrForegroundAffecting || EditorUtil.attributesImpactFontStyleOrColor(ex.getTextAttributes()));
    }
  });
  highlighters = list.isEmpty() ? RangeHighlighterEx.EMPTY_ARRAY : list.toArray(RangeHighlighterEx.EMPTY_ARRAY);
  Arrays.sort(highlighters, myReverseIteration ? BY_AFFECTED_END_OFFSET_REVERSED : RangeHighlighterEx.BY_AFFECTED_START_OFFSET);

  while (i < highlighters.length) {
    RangeHighlighterEx highlighter = highlighters[i++];
    if (!skipHighlighter(highlighter)) {
      myNextHighlighter = highlighter;
      break;
    }
  }
}
 
Example #6
Source File: VcsLogStorageImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
public CommitId findCommitId(@Nonnull final Condition<CommitId> condition) {
  checkDisposed();
  try {
    final Ref<CommitId> hashRef = Ref.create();
    myCommitIdEnumerator.iterateData(new CommonProcessors.FindProcessor<CommitId>() {
      @Override
      protected boolean accept(CommitId commitId) {
        boolean matches = condition.value(commitId);
        if (matches) {
          hashRef.set(commitId);
        }
        return matches;
      }
    });
    return hashRef.get();
  }
  catch (IOException e) {
    myExceptionReporter.consume(this, e);
    return null;
  }
}
 
Example #7
Source File: InspectionEngine.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static Map<String, List<ProblemDescriptor>> inspectEx(@Nonnull final List<LocalInspectionToolWrapper> toolWrappers,
                                                             @Nonnull final PsiFile file,
                                                             @Nonnull final InspectionManager iManager,
                                                             final boolean isOnTheFly,
                                                             boolean failFastOnAcquireReadAction,
                                                             @Nonnull final ProgressIndicator indicator) {
  if (toolWrappers.isEmpty()) return Collections.emptyMap();


  TextRange range = file.getTextRange();
  List<Divider.DividedElements> allDivided = new ArrayList<>();
  Divider.divideInsideAndOutsideAllRoots(file, range, range, Conditions.alwaysTrue(), new CommonProcessors.CollectProcessor<>(allDivided));

  List<PsiElement> elements = ContainerUtil.concat(
          (List<List<PsiElement>>)ContainerUtil.map(allDivided, d -> ContainerUtil.concat(d.inside, d.outside, d.parents)));

  return inspectElements(toolWrappers, file, iManager, isOnTheFly, failFastOnAcquireReadAction, indicator, elements,
                         calcElementDialectIds(elements));
}
 
Example #8
Source File: TokenSetTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Test
public void performance() throws Exception {
  final IElementType[] elementTypes = IElementType.enumerate(CommonProcessors.<IElementType>alwaysTrue());
  final TokenSet set = TokenSet.create();
  final int shift = new Random().nextInt(500000);

  PlatformTestUtil.startPerformanceTest("TokenSet.contains() performance", 25, new ThrowableRunnable() {
    @Override
    public void run() throws Throwable {
      for (int i = 0; i < 1000000; i++) {
        final IElementType next = elementTypes[((i + shift) % elementTypes.length)];
        assertFalse(set.contains(next));
      }
    }
  }).cpuBound().assertTiming();
}
 
Example #9
Source File: RangeMarkerTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testRangeHighlighterLinesInRangeForLongLinePerformance() throws Exception {
  final int N = 50000;
  Document document = EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol('x', 2 * N));

  final MarkupModelEx markupModel = (MarkupModelEx)DocumentMarkupModel.forDocument(document, ourProject, true);
  for (int i=0; i<N-1;i++) {
    markupModel.addRangeHighlighter(2*i, 2*i+1, 0, null, HighlighterTargetArea.EXACT_RANGE);
  }
  markupModel.addRangeHighlighter(N / 2, N / 2 + 1, 0, null, HighlighterTargetArea.LINES_IN_RANGE);

  PlatformTestUtil.startPerformanceTest("slow highlighters lookup", (int)(N*Math.log(N)/1000), new ThrowableRunnable() {
    @Override
    public void run() {
      List<RangeHighlighterEx> list = new ArrayList<RangeHighlighterEx>();
      CommonProcessors.CollectProcessor<RangeHighlighterEx> coll = new CommonProcessors.CollectProcessor<RangeHighlighterEx>(list);
      for (int i=0; i<N-1;i++) {
        list.clear();
        markupModel.processRangeHighlightersOverlappingWith(2*i, 2*i+1, coll);
        assertEquals(2, list.size());  // 1 line plus one exact range marker
      }
    }
  }).assertTiming();
}
 
Example #10
Source File: SortedMemberResolveScopeProcessor.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
public void consumeAll()
{
	ResolveResult[] resolveResults = ((CommonProcessors.CollectProcessor<ResolveResult>) myResultProcessor).toArray(ResolveResult.ARRAY_FACTORY);

	ContainerUtil.sort(resolveResults, myComparator);

	for(ResolveResult result : resolveResults)
	{
		ProgressManager.checkCanceled();

		if(!myOriginalProcessor.process(result))
		{
			return;
		}
	}
}
 
Example #11
Source File: DecompileAndAttachAction.java    From decompile-and-attach with MIT License 6 votes vote down vote up
private Optional<Library> findModuleDependency(Module module, VirtualFile sourceVF) {
    final CommonProcessors.FindProcessor<OrderEntry> processor = new CommonProcessors.FindProcessor<OrderEntry>() {

        @Override
        protected boolean accept(OrderEntry orderEntry) {
            final String[] urls = orderEntry.getUrls(OrderRootType.CLASSES);
            final boolean contains = Arrays.asList(urls).contains("jar://" + sourceVF.getPath() + "!/");
            return contains && orderEntry instanceof LibraryOrderEntry;
        }
    };
    ModuleRootManager.getInstance(module).orderEntries().forEach(processor);
    Library result = null;
    if (processor.getFoundValue() != null) {
        result = ((LibraryOrderEntry) processor.getFoundValue()).getLibrary();
    }
    return Optional.ofNullable(result);
}
 
Example #12
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 #13
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 #14
Source File: PsiFinder.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@NotNull
public <T extends PsiModule> Set<T> findModulesbyName(@NotNull String name, @NotNull ORFileType fileType, ModuleFilter<PsiModule> filter,
                                                      @NotNull GlobalSearchScope scope) {
    Set<T> result = new HashSet<>();
    ModuleIndex instance = ModuleIndex.getInstance();

    instance.processAllKeys(m_project, CommonProcessors.processAll(moduleName -> {
        if (name.equals(moduleName)) {
            Collection<PsiModule> modules = instance.get(moduleName, m_project, scope);
            PartitionedModules partitionedModules = new PartitionedModules(m_project, modules, filter);

            if (fileType == interfaceOrImplementation || fileType == both || fileType == interfaceOnly) {
                result.addAll((Collection<? extends T>) partitionedModules.getInterfaces());
            }

            if (fileType != interfaceOnly) {
                if (fileType == both || fileType == implementationOnly || !partitionedModules.hasInterfaces()) {
                    result.addAll((Collection<? extends T>) partitionedModules.getImplementations());
                }
            }
        }
    }));

    if (LOG.isTraceEnabled()) {
        LOG.trace("  modules " + name + " (found " + result.size() + "): " + Joiner
                .join(", ", result.stream().map(PsiModule::getName).collect(Collectors.toList())));
    }

    return result;
}
 
Example #15
Source File: LocalInspectionsPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void inspect(@Nonnull final List<LocalInspectionToolWrapper> toolWrappers,
                     @Nonnull final InspectionManager iManager,
                     final boolean isOnTheFly,
                     boolean failFastOnAcquireReadAction,
                     @Nonnull final ProgressIndicator progress) {
  myFailFastOnAcquireReadAction = failFastOnAcquireReadAction;
  if (toolWrappers.isEmpty()) return;

  List<Divider.DividedElements> allDivided = new ArrayList<>();
  Divider.divideInsideAndOutsideAllRoots(myFile, myRestrictRange, myPriorityRange, SHOULD_INSPECT_FILTER,
                                         new CommonProcessors.CollectProcessor<>(allDivided));
  List<PsiElement> inside = ContainerUtil.concat((List<List<PsiElement>>)ContainerUtil.map(allDivided, d -> d.inside));
  List<PsiElement> outside = ContainerUtil.concat((List<List<PsiElement>>)ContainerUtil.map(allDivided, d -> ContainerUtil.concat(d.outside, d.parents)));

  Set<String> elementDialectIds = InspectionEngine.calcElementDialectIds(inside, outside);
  Map<LocalInspectionToolWrapper, Set<String>> toolToSpecifiedLanguageIds = InspectionEngine.getToolsToSpecifiedLanguages(toolWrappers);

  setProgressLimit(toolToSpecifiedLanguageIds.size() * 2L);
  final LocalInspectionToolSession session = new LocalInspectionToolSession(getFile(), myRestrictRange.getStartOffset(), myRestrictRange.getEndOffset());

  List<InspectionContext> init =
          visitPriorityElementsAndInit(toolToSpecifiedLanguageIds, iManager, isOnTheFly, progress, inside, session, toolWrappers, elementDialectIds);
  inspectInjectedPsi(inside, isOnTheFly, progress, iManager, true, toolWrappers);
  visitRestElementsAndCleanup(progress, outside, session, init, elementDialectIds);
  inspectInjectedPsi(outside, isOnTheFly, progress, iManager, false, toolWrappers);

  progress.checkCanceled();

  myInfos = new ArrayList<>();
  addHighlightsFromResults(myInfos, progress);
}
 
Example #16
Source File: ShowIntentionsPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<HighlightInfo.IntentionActionDescriptor> getAvailableFixes(@Nonnull final Editor editor, @Nonnull final PsiFile file, final int passId, int offset) {
  final Project project = file.getProject();

  List<HighlightInfo> infos = new ArrayList<>();
  DaemonCodeAnalyzerImpl.processHighlightsNearOffset(editor.getDocument(), project, HighlightSeverity.INFORMATION, offset, true, new CommonProcessors.CollectProcessor<>(infos));
  List<HighlightInfo.IntentionActionDescriptor> result = new ArrayList<>();
  infos.forEach(info -> addAvailableFixesForGroups(info, editor, file, result, passId, offset));
  return result;
}
 
Example #17
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 #18
Source File: FoldRegionsTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
FoldRegion[] fetchAllRegions() {
  if (!isFoldingEnabled()) return FoldRegion.EMPTY_ARRAY;
  List<FoldRegion> regions = new ArrayList<>();
  myMarkerTree.processOverlappingWith(0, Integer.MAX_VALUE, new CommonProcessors.CollectProcessor<>(regions));
  return toFoldArray(regions);
}
 
Example #19
Source File: IndexCacheManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processFilesWithWord(@Nonnull final Processor<PsiFile> psiFileProcessor, @Nonnull final String word, final short occurrenceMask, @Nonnull final GlobalSearchScope scope, final boolean caseSensitively) {
  final List<VirtualFile> vFiles = new ArrayList<VirtualFile>(5);
  collectVirtualFilesWithWord(new CommonProcessors.CollectProcessor<VirtualFile>(vFiles), word, occurrenceMask, scope, caseSensitively);
  if (vFiles.isEmpty()) return true;

  final Processor<VirtualFile> virtualFileProcessor = new ReadActionProcessor<VirtualFile>() {
    @RequiredReadAction
    @Override
    public boolean processInReadAction(VirtualFile virtualFile) {
      if (virtualFile.isValid()) {
        final PsiFile psiFile = myPsiManager.findFile(virtualFile);
        return psiFile == null || psiFileProcessor.process(psiFile);
      }
      return true;
    }
  };


  // IMPORTANT!!!
  // Since implementation of virtualFileProcessor.process() may call indices directly or indirectly,
  // we cannot call it inside FileBasedIndex.processValues() method
  // If we do, deadlocks are possible (IDEADEV-42137). So first we obtain files with the word specified,
  // and then process them not holding indices' read lock.
  for (VirtualFile vFile : vFiles) {
    ProgressIndicatorProvider.checkCanceled();
    if (!virtualFileProcessor.process(vFile)) {
      return false;
    }
  }
  return true;
}
 
Example #20
Source File: IndexCacheManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public VirtualFile[] getVirtualFilesWithWord(@Nonnull final String word, final short occurenceMask, @Nonnull final GlobalSearchScope scope, final boolean caseSensitively) {
  if (myProject.isDefault()) {
    return VirtualFile.EMPTY_ARRAY;
  }

  final List<VirtualFile> vFiles = new ArrayList<VirtualFile>(5);
  collectVirtualFilesWithWord(new CommonProcessors.CollectProcessor<VirtualFile>(vFiles), word, occurenceMask, scope, caseSensitively);
  return vFiles.isEmpty() ? VirtualFile.EMPTY_ARRAY : vFiles.toArray(new VirtualFile[vFiles.size()]);
}
 
Example #21
Source File: SortedMemberResolveScopeProcessor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
public SortedMemberResolveScopeProcessor(@Nonnull CSharpResolveOptions options,
		@Nonnull Processor<ResolveResult> resultProcessor,
		@Nonnull Comparator<ResolveResult> comparator,
		ExecuteTarget[] targets)
{
	super(options, CommonProcessors.<ResolveResult>alwaysTrue(), targets);
	myOriginalProcessor = resultProcessor;
	myComparator = comparator;
	initThisProcessor();
}
 
Example #22
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 #23
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 #24
Source File: RangeMarkerTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testRangeHighlighterIteratorOrder() throws Exception {
  Document document = EditorFactory.getInstance().createDocument("1234567890");

  final MarkupModelEx markupModel = (MarkupModelEx)DocumentMarkupModel.forDocument(document, ourProject, true);
  RangeHighlighter exact = markupModel.addRangeHighlighter(3, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
  RangeHighlighter line = markupModel.addRangeHighlighter(4, 5, 0, null, HighlighterTargetArea.LINES_IN_RANGE);
  List<RangeHighlighter> list = new ArrayList<RangeHighlighter>();
  markupModel.processRangeHighlightersOverlappingWith(2, 9, new CommonProcessors.CollectProcessor<RangeHighlighter>(list));
  assertEquals(Arrays.asList(line, exact), list);
}
 
Example #25
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 #26
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 #27
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 #28
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 #29
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 #30
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;
}