use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class LibraryUsageCollector method getProjectUsages.
@NotNull
@Override
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
final Set<LibraryKind> usedKinds = new HashSet<>();
final Processor<Library> processor = library -> {
usedKinds.addAll(LibraryPresentationManagerImpl.getLibraryKinds(library, null));
return true;
};
for (Module module : ModuleManager.getInstance(project).getModules()) {
ModuleRootManager.getInstance(module).orderEntries().librariesOnly().forEachLibrary(processor);
}
final HashSet<UsageDescriptor> usageDescriptors = new HashSet<>();
for (LibraryKind kind : usedKinds) {
usageDescriptors.add(new UsageDescriptor(kind.getKindId(), 1));
}
return usageDescriptors;
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class FindUsagesTest method testNonCodeClassUsages.
public void testNonCodeClassUsages() throws Exception {
final TempDirTestFixture tdf = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
tdf.setUp();
try {
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(getProject()).getModifiableModel();
moduleModel.newModule("independent/independent.iml", StdModuleTypes.JAVA.getId());
moduleModel.commit();
tdf.createFile("plugin.xml", "<document>\n" + " <action class=\"com.Foo\" />\n" + " <action class=\"com.Foo.Bar\" />\n" + " <action class=\"com.Foo$Bar\" />\n" + "</document>");
PsiTestUtil.addContentRoot(ModuleManager.getInstance(getProject()).findModuleByName("independent"), tdf.getFile(""));
}
}.execute();
GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
PsiClass foo = myJavaFacade.findClass("com.Foo", scope);
PsiClass bar = myJavaFacade.findClass("com.Foo.Bar", scope);
final int[] count = { 0 };
Processor<UsageInfo> processor = usageInfo -> {
int navigationOffset = usageInfo.getNavigationOffset();
assertTrue(navigationOffset > 0);
String textAfter = usageInfo.getFile().getText().substring(navigationOffset);
assertTrue(textAfter, textAfter.startsWith("Foo") || textAfter.startsWith("Bar") || textAfter.startsWith("com.Foo.Bar"));
count[0]++;
return true;
};
JavaFindUsagesHandler handler = new JavaFindUsagesHandler(bar, JavaFindUsagesHandlerFactory.getInstance(getProject()));
count[0] = 0;
handler.processUsagesInText(foo, processor, scope);
assertEquals(3, count[0]);
count[0] = 0;
handler.processUsagesInText(bar, processor, scope);
assertEquals(2, count[0]);
} finally {
tdf.tearDown();
}
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class UpdateHighlightersUtil method setHighlightersOutsideRange.
// set highlights inside startOffset,endOffset but outside priorityRange
static void setHighlightersOutsideRange(@NotNull final Project project, @NotNull final Document document, @NotNull final PsiFile psiFile, @NotNull final List<HighlightInfo> infos, @Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used
final int startOffset, final int endOffset, @NotNull final ProperTextRange priorityRange, final int group) {
ApplicationManager.getApplication().assertIsDispatchThread();
final DaemonCodeAnalyzerEx codeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(project);
if (startOffset == 0 && endOffset == document.getTextLength()) {
codeAnalyzer.cleanFileLevelHighlights(project, group, psiFile);
}
final MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true);
assertMarkupConsistent(markup, project);
final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project);
final HighlightersRecycler infosToRemove = new HighlightersRecycler();
ContainerUtil.quickSort(infos, BY_START_OFFSET_NODUPS);
Set<HighlightInfo> infoSet = new THashSet<>(infos);
Processor<HighlightInfo> processor = info -> {
if (info.getGroup() == group) {
RangeHighlighter highlighter = info.getHighlighter();
int hiStart = highlighter.getStartOffset();
int hiEnd = highlighter.getEndOffset();
if (!info.isFromInjection() && hiEnd < document.getTextLength() && (hiEnd <= startOffset || hiStart >= endOffset)) {
return true;
}
boolean toRemove = infoSet.contains(info) || !priorityRange.containsRange(hiStart, hiEnd) && (hiEnd != document.getTextLength() || priorityRange.getEndOffset() != document.getTextLength());
if (toRemove) {
infosToRemove.recycleHighlighter(highlighter);
info.setHighlighter(null);
}
}
return true;
};
DaemonCodeAnalyzerEx.processHighlightsOverlappingOutside(document, project, null, priorityRange.getStartOffset(), priorityRange.getEndOffset(), processor);
final Map<TextRange, RangeMarker> ranges2markersCache = new THashMap<>(10);
final boolean[] changed = { false };
RangeMarkerTree.sweep((RangeMarkerTree.Generator<HighlightInfo>) processor1 -> ContainerUtil.process(infos, processor1), (offset, info, atStart, overlappingIntervals) -> {
if (!atStart)
return true;
// injections are oblivious to restricting range
if (!info.isFromInjection() && info.getEndOffset() < document.getTextLength() && (info.getEndOffset() <= startOffset || info.getStartOffset() >= endOffset))
return true;
if (info.isFileLevelAnnotation()) {
codeAnalyzer.addFileLevelHighlight(project, group, info, psiFile);
changed[0] = true;
return true;
}
if (isWarningCoveredByError(info, overlappingIntervals, severityRegistrar)) {
return true;
}
if (info.getStartOffset() < priorityRange.getStartOffset() || info.getEndOffset() > priorityRange.getEndOffset()) {
createOrReuseHighlighterFor(info, colorsScheme, document, group, psiFile, (MarkupModelEx) markup, infosToRemove, ranges2markersCache, severityRegistrar);
changed[0] = true;
}
return true;
});
for (RangeHighlighter highlighter : infosToRemove.forAllInGarbageBin()) {
highlighter.dispose();
changed[0] = true;
}
if (changed[0]) {
clearWhiteSpaceOptimizationFlag(document);
}
assertMarkupConsistent(markup, project);
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class UpdateHighlightersUtil method setHighlightersInRange.
static void setHighlightersInRange(@NotNull final Project project, @NotNull final Document document, @NotNull final TextRange range, // if null global scheme will be used
@Nullable final EditorColorsScheme colorsScheme, @NotNull final List<HighlightInfo> infos, @NotNull final MarkupModelEx markup, final int group) {
ApplicationManager.getApplication().assertIsDispatchThread();
final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project);
final HighlightersRecycler infosToRemove = new HighlightersRecycler();
DaemonCodeAnalyzerEx.processHighlights(document, project, null, range.getStartOffset(), range.getEndOffset(), info -> {
if (info.getGroup() == group) {
RangeHighlighter highlighter = info.getHighlighter();
int hiStart = highlighter.getStartOffset();
int hiEnd = highlighter.getEndOffset();
boolean willBeRemoved = hiEnd == document.getTextLength() && range.getEndOffset() == document.getTextLength() || range.containsRange(hiStart, hiEnd);
if (willBeRemoved) {
infosToRemove.recycleHighlighter(highlighter);
info.setHighlighter(null);
}
}
return true;
});
ContainerUtil.quickSort(infos, BY_START_OFFSET_NODUPS);
final Map<TextRange, RangeMarker> ranges2markersCache = new THashMap<>(10);
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
final DaemonCodeAnalyzerEx codeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(project);
final boolean[] changed = { false };
RangeMarkerTree.sweep((RangeMarkerTree.Generator<HighlightInfo>) processor -> ContainerUtil.process(infos, processor), (offset, info, atStart, overlappingIntervals) -> {
if (!atStart) {
return true;
}
if (info.isFileLevelAnnotation() && psiFile != null && psiFile.getViewProvider().isPhysical()) {
codeAnalyzer.addFileLevelHighlight(project, group, info, psiFile);
changed[0] = true;
return true;
}
if (isWarningCoveredByError(info, overlappingIntervals, severityRegistrar)) {
return true;
}
if (info.getStartOffset() >= range.getStartOffset() && info.getEndOffset() <= range.getEndOffset() && psiFile != null) {
createOrReuseHighlighterFor(info, colorsScheme, document, group, psiFile, markup, infosToRemove, ranges2markersCache, severityRegistrar);
changed[0] = true;
}
return true;
});
for (RangeHighlighter highlighter : infosToRemove.forAllInGarbageBin()) {
highlighter.dispose();
changed[0] = true;
}
if (changed[0]) {
clearWhiteSpaceOptimizationFlag(document);
}
assertMarkupConsistent(markup, project);
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class DefaultSymbolNavigationContributor method processElementsWithName.
@Override
public void processElementsWithName(@NotNull String name, @NotNull final Processor<NavigationItem> processor, @NotNull final FindSymbolParameters parameters) {
GlobalSearchScope scope = parameters.getSearchScope();
IdFilter filter = parameters.getIdFilter();
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(scope.getProject());
String completePattern = parameters.getCompletePattern();
final Condition<PsiMember> qualifiedMatcher = getQualifiedNameMatcher(completePattern);
//noinspection UnusedDeclaration
final Set<PsiMethod> collectedMethods = new THashSet<>();
boolean success = cache.processFieldsWithName(name, field -> {
if (isOpenable(field) && qualifiedMatcher.value(field))
return processor.process(field);
return true;
}, scope, filter) && cache.processClassesWithName(name, aClass -> {
if (isOpenable(aClass) && qualifiedMatcher.value(aClass))
return processor.process(aClass);
return true;
}, scope, filter) && cache.processMethodsWithName(name, method -> {
if (!method.isConstructor() && isOpenable(method) && qualifiedMatcher.value(method)) {
collectedMethods.add(method);
}
return true;
}, scope, filter);
if (success) {
// hashSuperMethod accesses index and can not be invoked without risk of the deadlock in processMethodsWithName
Iterator<PsiMethod> iterator = collectedMethods.iterator();
while (iterator.hasNext()) {
PsiMethod method = iterator.next();
if (!hasSuperMethod(method, scope, qualifiedMatcher) && !processor.process(method))
return;
ProgressManager.checkCanceled();
iterator.remove();
}
}
}
Aggregations