Search in sources :

Example 1 with LockToken

use of com.intellij.util.concurrency.LockToken in project intellij-community by JetBrains.

the class AbstractTreeUi method getChildrenFor.

//todo [kirillk] temporary consistency check
private Object[] getChildrenFor(final Object element) {
    final Ref<Object[]> passOne = new Ref<>();
    try (LockToken ignored = acquireLock()) {
        execute(new TreeRunnable("AbstractTreeUi.getChildrenFor") {

            @Override
            public void perform() {
                passOne.set(getTreeStructure().getChildElements(element));
            }
        });
    } catch (IndexNotReadyException e) {
        warnOnIndexNotReady(e);
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    if (!Registry.is("ide.tree.checkStructure"))
        return passOne.get();
    final Object[] passTwo = getTreeStructure().getChildElements(element);
    final HashSet<Object> two = new HashSet<>(Arrays.asList(passTwo));
    if (passOne.get().length != passTwo.length) {
        LOG.error("AbstractTreeStructure.getChildren() must either provide same objects or new objects but with correct hashCode() and equals() methods. Wrong parent element=" + element);
    } else {
        for (Object eachInOne : passOne.get()) {
            if (!two.contains(eachInOne)) {
                LOG.error("AbstractTreeStructure.getChildren() must either provide same objects or new objects but with correct hashCode() and equals() methods. Wrong parent element=" + element);
                break;
            }
        }
    }
    return passOne.get();
}
Also used : LockToken(com.intellij.util.concurrency.LockToken) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet)

Example 2 with LockToken

use of com.intellij.util.concurrency.LockToken in project intellij-community by JetBrains.

the class AbstractTreeUi method releaseNow.

private void releaseNow() {
    try (LockToken ignored = acquireLock()) {
        myTree.removeTreeExpansionListener(myExpansionListener);
        myTree.removeTreeSelectionListener(mySelectionListener);
        myTree.removeFocusListener(myFocusListener);
        disposeNode(getRootNode());
        myElementToNodeMap.clear();
        getUpdater().cancelAllRequests();
        myWorker.clear();
        clearWorkerTasks();
        TREE_NODE_WRAPPER.setValue(null);
        if (myProgress != null) {
            myProgress.cancel();
        }
        cancelCurrentCleanupTask();
        myTree = null;
        setUpdater(null);
        myTreeStructure = null;
        myBuilder.releaseUi();
        myBuilder = null;
        clearNodeActions();
        myDeferredSelections.clear();
        myDeferredExpansions.clear();
        myYieldingDoneRunnables.clear();
    }
}
Also used : LockToken(com.intellij.util.concurrency.LockToken)

Example 3 with LockToken

use of com.intellij.util.concurrency.LockToken in project intellij-community by JetBrains.

the class AbstractTreeUi method update.

private boolean update(@NotNull final NodeDescriptor nodeDescriptor) {
    try (LockToken ignored = acquireLock()) {
        final AtomicBoolean update = new AtomicBoolean();
        execute(new TreeRunnable("AbstractTreeUi.update") {

            @Override
            public void perform() {
                nodeDescriptor.setUpdateCount(nodeDescriptor.getUpdateCount() + 1);
                update.set(getBuilder().updateNodeDescriptor(nodeDescriptor));
            }
        });
        return update.get();
    } catch (IndexNotReadyException e) {
        warnOnIndexNotReady(e);
        return false;
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LockToken(com.intellij.util.concurrency.LockToken) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Aggregations

LockToken (com.intellij.util.concurrency.LockToken)3 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)2 HashSet (com.intellij.util.containers.HashSet)1 THashSet (gnu.trove.THashSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1