Search in sources :

Example 46 with THashSet

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);
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) java.util(java.util) GutterMark(com.intellij.codeInsight.daemon.GutterMark) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) RangeMarker(com.intellij.openapi.editor.RangeMarker) RedBlackTree(com.intellij.openapi.editor.impl.RedBlackTree) com.intellij.openapi.editor.markup(com.intellij.openapi.editor.markup) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) RangeMarkerTree(com.intellij.openapi.editor.impl.RangeMarkerTree) RangeMarkerTree(com.intellij.openapi.editor.impl.RangeMarkerTree) RangeMarker(com.intellij.openapi.editor.RangeMarker) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel)

Example 47 with THashSet

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;
}
Also used : THashSet(gnu.trove.THashSet) Stack(com.intellij.util.containers.Stack) HighlightInfoHolder(com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder) CustomHighlightInfoHolder(com.intellij.codeInsight.daemon.impl.analysis.CustomHighlightInfoHolder) SmartList(com.intellij.util.SmartList)

Example 48 with THashSet

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()]);
}
Also used : PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 49 with THashSet

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();
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) NotNull(org.jetbrains.annotations.NotNull) THashSet(gnu.trove.THashSet)

Example 50 with THashSet

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderEnumerator(com.intellij.openapi.roots.OrderEnumerator) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

THashSet (gnu.trove.THashSet)239 NotNull (org.jetbrains.annotations.NotNull)65 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 Project (com.intellij.openapi.project.Project)35 File (java.io.File)35 THashMap (gnu.trove.THashMap)31 Nullable (org.jetbrains.annotations.Nullable)31 Module (com.intellij.openapi.module.Module)29 IOException (java.io.IOException)24 PsiElement (com.intellij.psi.PsiElement)21 PsiFile (com.intellij.psi.PsiFile)18 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 java.util (java.util)16 Element (org.jdom.Element)14 Pair (com.intellij.openapi.util.Pair)13 Logger (com.intellij.openapi.diagnostic.Logger)12 ContainerUtil (com.intellij.util.containers.ContainerUtil)12 Document (com.intellij.openapi.editor.Document)11 Library (com.intellij.openapi.roots.libraries.Library)11 StringUtil (com.intellij.openapi.util.text.StringUtil)10