Search in sources :

Example 26 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class VcsDirtyScopeImpl method addDirtyDirRecursively.

/**
   * Add dirty directory recursively. If there are already dirty entries
   * that are descendants or ancestors for the added directory, the contained
   * entries are dropped from scope.
   *
   * @param newcomer a new directory to add
   */
@Override
public void addDirtyDirRecursively(final FilePath newcomer) {
    final VirtualFile vcsRoot = myVcsManager.getVcsRootFor(newcomer);
    if (vcsRoot == null)
        return;
    myAffectedContentRoots.add(vcsRoot);
    for (Map.Entry<VirtualFile, THashSet<FilePath>> entry : myDirtyFiles.entrySet()) {
        final VirtualFile groupRoot = entry.getKey();
        if (groupRoot != null && VfsUtilCore.isAncestor(vcsRoot, groupRoot, false)) {
            final THashSet<FilePath> files = entry.getValue();
            if (files != null) {
                for (Iterator<FilePath> it = files.iterator(); it.hasNext(); ) {
                    FilePath oldBoy = it.next();
                    if (oldBoy.isUnder(newcomer, false)) {
                        it.remove();
                    }
                }
            }
        }
    }
    THashSet<FilePath> dirsByRoot = myDirtyDirectoriesRecursively.get(vcsRoot);
    if (dirsByRoot == null) {
        dirsByRoot = newFilePathsSet();
        myDirtyDirectoriesRecursively.put(vcsRoot, dirsByRoot);
    } else {
        for (Iterator<FilePath> it = dirsByRoot.iterator(); it.hasNext(); ) {
            FilePath oldBoy = it.next();
            if (newcomer.isUnder(oldBoy, false)) {
                return;
            }
            if (oldBoy.isUnder(newcomer, false)) {
                it.remove();
            }
        }
    }
    dirsByRoot.add(newcomer);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MultiMap(com.intellij.util.containers.MultiMap) THashSet(gnu.trove.THashSet)

Example 27 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class VfsUtil method getCommonAncestors.

/**
   * Gets the array of common ancestors for passed files.
   *
   * @param files array of files
   * @return array of common ancestors for passed files
   */
@NotNull
public static VirtualFile[] getCommonAncestors(@NotNull VirtualFile[] files) {
    // Separate files by first component in the path.
    HashMap<VirtualFile, Set<VirtualFile>> map = new HashMap<>();
    for (VirtualFile aFile : files) {
        VirtualFile directory = aFile.isDirectory() ? aFile : aFile.getParent();
        if (directory == null)
            return VirtualFile.EMPTY_ARRAY;
        VirtualFile[] path = getPathComponents(directory);
        Set<VirtualFile> filesSet;
        final VirtualFile firstPart = path[0];
        if (map.containsKey(firstPart)) {
            filesSet = map.get(firstPart);
        } else {
            filesSet = new THashSet<>();
            map.put(firstPart, filesSet);
        }
        filesSet.add(directory);
    }
    // Find common ancestor for each set of files.
    ArrayList<VirtualFile> ancestorsList = new ArrayList<>();
    for (Set<VirtualFile> filesSet : map.values()) {
        VirtualFile ancestor = null;
        for (VirtualFile file : filesSet) {
            if (ancestor == null) {
                ancestor = file;
                continue;
            }
            ancestor = getCommonAncestor(ancestor, file);
        //assertTrue(ancestor != null);
        }
        ancestorsList.add(ancestor);
        filesSet.clear();
    }
    return toVirtualFileArray(ancestorsList);
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class CacheUpdateRunner method processFiles.

public static void processFiles(final ProgressIndicator indicator, boolean processInReadAction, Collection<VirtualFile> files, Project project, Consumer<FileContent> processor) {
    indicator.checkCanceled();
    final FileContentQueue queue = new FileContentQueue(files, indicator);
    final double total = files.size();
    queue.startLoading();
    ProgressUpdater progressUpdater = new ProgressUpdater() {

        final Set<VirtualFile> myFilesBeingProcessed = new THashSet<>();

        final AtomicInteger myNumberOfFilesProcessed = new AtomicInteger();

        @Override
        public void processingStarted(VirtualFile virtualFile) {
            indicator.checkCanceled();
            synchronized (myFilesBeingProcessed) {
                boolean added = myFilesBeingProcessed.add(virtualFile);
                if (added) {
                    indicator.setFraction(myNumberOfFilesProcessed.incrementAndGet() / total);
                }
                if (added) {
                    VirtualFile parent = virtualFile.getParent();
                    if (parent != null)
                        indicator.setText2(parent.getPresentableUrl());
                }
            }
        }

        @Override
        public void processingSuccessfullyFinished(VirtualFile virtualFile) {
            synchronized (myFilesBeingProcessed) {
                boolean removed = myFilesBeingProcessed.remove(virtualFile);
                assert removed;
            }
        }
    };
    while (!project.isDisposed()) {
        indicator.checkCanceled();
        // todo wait for the user...
        if (processSomeFilesWhileUserIsInactive(queue, progressUpdater, processInReadAction, project, processor)) {
            break;
        }
    }
    if (project.isDisposed()) {
        indicator.cancel();
        indicator.checkCanceled();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Set(java.util.Set) THashSet(gnu.trove.THashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 29 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class LibraryImpl method disposeMyPointers.

private void disposeMyPointers() {
    for (VirtualFilePointerContainer container : new THashSet<>(myRoots.values())) {
        container.killAll();
    }
    if (myExcludedRoots != null) {
        myExcludedRoots.killAll();
    }
    Disposer.dispose(myPointersDisposable);
    Disposer.register(this, myPointersDisposable);
}
Also used : THashSet(gnu.trove.THashSet) VirtualFilePointerContainer(com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)

Example 30 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class ThreadTracker method checkLeak.

@TestOnly
public void checkLeak() throws AssertionError {
    NettyUtil.awaitQuiescenceOfGlobalEventExecutor(100, TimeUnit.SECONDS);
    ShutDownTracker.getInstance().waitFor(100, TimeUnit.SECONDS);
    try {
        if (myDefaultProjectInitialized != ((ProjectManagerImpl) ProjectManager.getInstance()).isDefaultProjectInitialized())
            return;
        Collection<Thread> after = new THashSet<>(getThreads());
        after.removeAll(before);
        for (final Thread thread : after) {
            if (thread == Thread.currentThread())
                continue;
            ThreadGroup group = thread.getThreadGroup();
            if (group != null && "system".equals(group.getName()))
                continue;
            if (isWellKnownOffender(thread))
                continue;
            if (!thread.isAlive())
                continue;
            if (thread.getStackTrace().length == 0) {
                thread.interrupt();
                if (new WaitFor(10000) {

                    @Override
                    protected boolean condition() {
                        return !thread.isAlive();
                    }
                }.isConditionRealized()) {
                    continue;
                }
            }
            StackTraceElement[] stackTrace = thread.getStackTrace();
            if (stackTrace.length == 0) {
                // ignore threads with empty stack traces for now. Seems they are zombies unwilling to die.
                continue;
            }
            if (isIdleApplicationPoolThread(thread, stackTrace)) {
                continue;
            }
            @SuppressWarnings("NonConstantStringShouldBeStringBuffer") String trace = "Thread leaked: " + thread + "; " + thread.getState() + " (" + thread.isAlive() + ")\n--- its stacktrace:\n";
            for (final StackTraceElement stackTraceElement : stackTrace) {
                trace += " at " + stackTraceElement + "\n";
            }
            trace += "---\n";
            Assert.fail(trace);
        }
    } finally {
        before.clear();
    }
}
Also used : WaitFor(com.intellij.util.WaitFor) THashSet(gnu.trove.THashSet) TestOnly(org.jetbrains.annotations.TestOnly)

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