use of gnu.trove.THashSet 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 gnu.trove.THashSet in project intellij-community by JetBrains.
the class GeneralHighlightingPass method collectHighlights.
private boolean collectHighlights(@NotNull final List<PsiElement> elements1, @NotNull final List<ProperTextRange> ranges1, @NotNull final List<PsiElement> elements2, @NotNull final List<ProperTextRange> ranges2, @NotNull final ProgressIndicator progress, @NotNull final HighlightVisitor[] visitors, @NotNull final List<HighlightInfo> insideResult, @NotNull final List<HighlightInfo> outsideResult, final boolean forceHighlightParents) {
final Set<PsiElement> skipParentsSet = new THashSet<>();
// TODO - add color scheme to holder
final HighlightInfoHolder holder = createInfoHolder(getFile());
// one percent precision is enough
final int chunkSize = Math.max(1, (elements1.size() + elements2.size()) / 100);
boolean success = analyzeByVisitors(visitors, holder, 0, () -> {
Stack<TextRange> nestedRange = new Stack<>();
Stack<List<HighlightInfo>> nestedInfos = new Stack<>();
runVisitors(elements1, ranges1, chunkSize, progress, skipParentsSet, holder, insideResult, outsideResult, forceHighlightParents, visitors, nestedRange, nestedInfos);
final TextRange priorityIntersection = myPriorityRange.intersection(myRestrictRange);
if ((!elements1.isEmpty() || !insideResult.isEmpty()) && priorityIntersection != null) {
// do not apply when there were no elements to highlight
myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, insideResult, myPriorityRange, myRestrictRange, getId());
}
runVisitors(elements2, ranges2, chunkSize, progress, skipParentsSet, holder, insideResult, outsideResult, forceHighlightParents, visitors, nestedRange, nestedInfos);
});
List<HighlightInfo> postInfos = new ArrayList<>(holder.size());
// there can be extra highlights generated in PostHighlightVisitor
for (int j = 0; j < holder.size(); j++) {
final HighlightInfo info = holder.get(j);
assert info != null;
postInfos.add(info);
}
myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, postInfos, getFile().getTextRange(), getFile().getTextRange(), POST_UPDATE_ALL);
return success;
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class InspectionProfileEntry method getBatchSuppressActions.
@NotNull
@Override
public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) {
if (element == null) {
return SuppressQuickFix.EMPTY_ARRAY;
}
Set<SuppressQuickFix> fixes = new THashSet<>(new TObjectHashingStrategy<SuppressQuickFix>() {
@Override
public int computeHashCode(SuppressQuickFix object) {
int result = object instanceof InjectionAwareSuppressQuickFix ? ((InjectionAwareSuppressQuickFix) object).isShouldBeAppliedToInjectionHost().hashCode() : 0;
return 31 * result + object.getName().hashCode();
}
@Override
public boolean equals(SuppressQuickFix o1, SuppressQuickFix o2) {
if (o1 instanceof InjectionAwareSuppressQuickFix && o2 instanceof InjectionAwareSuppressQuickFix) {
if (((InjectionAwareSuppressQuickFix) o1).isShouldBeAppliedToInjectionHost() != ((InjectionAwareSuppressQuickFix) o2).isShouldBeAppliedToInjectionHost()) {
return false;
}
}
return o1.getName().equals(o2.getName());
}
});
Set<InspectionSuppressor> suppressors = getSuppressors(element);
final PsiLanguageInjectionHost injectionHost = InjectedLanguageManager.getInstance(element.getProject()).getInjectionHost(element);
if (injectionHost != null) {
Set<InspectionSuppressor> injectionHostSuppressors = getSuppressors(injectionHost);
for (InspectionSuppressor suppressor : injectionHostSuppressors) {
addAllSuppressActions(fixes, injectionHost, suppressor, ThreeState.YES, getSuppressId());
}
}
for (InspectionSuppressor suppressor : suppressors) {
addAllSuppressActions(fixes, element, suppressor, injectionHost != null ? ThreeState.NO : ThreeState.UNSURE, getSuppressId());
}
return fixes.toArray(new SuppressQuickFix[fixes.size()]);
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class AnalysisScope method initFilesSet.
protected void initFilesSet() {
if (myType == FILE) {
myFilesSet = new HashSet<>(1);
myFilesSet.add(((PsiFileSystemItem) myElement).getVirtualFile());
} else if (myType == DIRECTORY || myType == PROJECT || myType == MODULES || myType == MODULE || myType == CUSTOM) {
myFilesSet = new THashSet<>();
accept(createFileSearcher(), false);
} else if (myType == VIRTUAL_FILES) {
myFilesSet = new THashSet<>();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
for (Iterator<VirtualFile> iterator = myVFiles.iterator(); iterator.hasNext(); ) {
final VirtualFile vFile = iterator.next();
VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor() {
@NotNull
@Override
public Result visitFileEx(@NotNull VirtualFile file) {
boolean ignored = fileIndex.isExcluded(file);
if (!ignored && !file.isDirectory()) {
myFilesSet.add(file);
}
return ignored ? SKIP_CHILDREN : CONTINUE;
}
});
if (vFile.isDirectory()) {
iterator.remove();
}
}
}
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class VfsRootAccess method getAllRoots.
@NotNull
private static VirtualFile[] getAllRoots(@NotNull Project project) {
insideGettingRoots = true;
final Set<VirtualFile> roots = new THashSet<>();
final OrderEnumerator enumerator = ProjectRootManager.getInstance(project).orderEntries();
ContainerUtil.addAll(roots, enumerator.getClassesRoots());
ContainerUtil.addAll(roots, enumerator.getSourceRoots());
insideGettingRoots = false;
return VfsUtilCore.toVirtualFileArray(roots);
}
Aggregations