Search in sources :

Example 31 with Condition

use of com.intellij.openapi.util.Condition in project intellij-plugins by JetBrains.

the class LibraryManager method getOrCreateFlexLibrarySet.

private FlexLibrarySet getOrCreateFlexLibrarySet(LibraryCollector libraryCollector, AssetCounter assetCounter) throws InitException {
    final String key = createKey(libraryCollector.sdkLibraries, true);
    FlexLibrarySet flexLibrarySet = (FlexLibrarySet) librarySets.get(key);
    if (flexLibrarySet == null) {
        final Set<CharSequence> globalDefinitions = getGlobalDefinitions(libraryCollector.getGlobalLibrary());
        final Condition<String> globalContains = name -> globalDefinitions.contains(name);
        final SortResult sortResult = sortLibraries(new LibrarySorter(new FlexDefinitionProcessor(libraryCollector.getFlexSdkVersion()), new FlexDefinitionMapProcessor(libraryCollector.getFlexSdkVersion(), globalContains)), libraryCollector, globalContains, key, true);
        flexLibrarySet = new FlexLibrarySet(sortResult, null, new ContainsCondition(globalDefinitions, sortResult.definitionMap), assetCounter, libraryCollector.getFlexSdkVersion());
        registerLibrarySet(key, flexLibrarySet);
    }
    return flexLibrarySet;
}
Also used : SortResult(com.intellij.flex.uiDesigner.libraries.LibrarySorter.SortResult) FlexUtils(com.intellij.lang.javascript.flex.FlexUtils) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener) THashMap(gnu.trove.THashMap) ReadAction(com.intellij.openapi.application.ReadAction) ProjectTopics(com.intellij.ProjectTopics) PsiManager(com.intellij.psi.PsiManager) AccessToken(com.intellij.openapi.application.AccessToken) StringBuilderSpinAllocator(com.intellij.util.StringBuilderSpinAllocator) InfoMap(org.jetbrains.io.InfoMap) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) AttachmentFactory(com.intellij.diagnostic.AttachmentFactory) ContainsCondition(com.intellij.flex.uiDesigner.libraries.FlexLibrarySet.ContainsCondition) com.intellij.flex.uiDesigner(com.intellij.flex.uiDesigner) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Disposable(com.intellij.openapi.Disposable) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) NotificationType(com.intellij.notification.NotificationType) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) ExceptionUtil(com.intellij.util.ExceptionUtil) Pair(com.intellij.openapi.util.Pair) StringRegistry(com.intellij.flex.uiDesigner.io.StringRegistry) Attachment(com.intellij.openapi.diagnostic.Attachment) RetainCondition(org.jetbrains.io.RetainCondition) NotNull(org.jetbrains.annotations.NotNull) Condition(com.intellij.openapi.util.Condition) ContainsCondition(com.intellij.flex.uiDesigner.libraries.FlexLibrarySet.ContainsCondition) SortResult(com.intellij.flex.uiDesigner.libraries.LibrarySorter.SortResult)

Example 32 with Condition

use of com.intellij.openapi.util.Condition in project intellij-plugins by JetBrains.

the class MxmlWriter method write.

@Nullable
public Pair<ProjectComponentReferenceCounter, List<RangeMarker>> write(XmlFile psiFile) throws IOException {
    document = MxmlUtil.getDocumentAndWaitIfNotCommitted(psiFile);
    final AccessToken token = ReadAction.start();
    try {
        VirtualFile virtualFile = psiFile.getVirtualFile();
        LOG.assertTrue(virtualFile != null);
        problemsHolder.setCurrentFile(virtualFile);
        XmlTag tag = psiFile.getRootTag();
        XmlElementDescriptor untypedDescriptor = tag == null ? null : tag.getDescriptor();
        final ClassBackedElementDescriptor descriptor;
        if (untypedDescriptor instanceof ClassBackedElementDescriptor) {
            descriptor = (ClassBackedElementDescriptor) untypedDescriptor;
        } else {
            return null;
        }
        final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
        try {
            PsiElement declaration = descriptor.getDeclaration();
            if (declaration == null) {
                return null;
            }
            effectiveClassInfo = MxmlUtil.computeEffectiveClass(tag, declaration, projectComponentReferenceCounter, true);
        } catch (InvalidPropertyException e) {
            problemsHolder.add(e);
            return null;
        }
        if (effectiveClassInfo.first == -1) {
            out.write(Amf3Types.OBJECT);
            writer.mxmlObjectHeader(effectiveClassInfo.second == null ? descriptor.getQualifiedName() : effectiveClassInfo.second);
        } else {
            writer.documentReference(effectiveClassInfo.first);
            out.allocateClearShort();
        }
        processElements(tag, null, false, -1, out.size() - 2, true, effectiveClassInfo.third);
        writer.endObject();
        if (stateWriter != null) {
            stateWriter.write();
            hasStates = false;
        } else {
            out.write(0);
        }
        injectedASWriter.write();
        writer.writeMessageHeader(projectComponentReferenceCounter);
        return Pair.create(projectComponentReferenceCounter, rangeMarkers);
    } finally {
        token.finish();
        problemsHolder.setCurrentFile(null);
        writer.resetAfterMessage();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Condition(com.intellij.openapi.util.Condition) ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) AccessToken(com.intellij.openapi.application.AccessToken) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with Condition

use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.

the class UpdaterTreeState method processAjusted.

private ActionCallback processAjusted(final Map<Object, Condition> adjusted, final Set<Object> originallySelected) {
    final ActionCallback result = new ActionCallback();
    final Set<Object> allSelected = myUi.getSelectedElements();
    Set<Object> toSelect = new HashSet<>();
    for (Map.Entry<Object, Condition> entry : adjusted.entrySet()) {
        if (entry.getValue().value(entry.getKey()))
            continue;
        for (final Object eachSelected : allSelected) {
            if (isParentOrSame(entry.getKey(), eachSelected))
                continue;
            toSelect.add(entry.getKey());
        }
        if (allSelected.isEmpty()) {
            toSelect.add(entry.getKey());
        }
    }
    final Object[] newSelection = ArrayUtil.toObjectArray(toSelect);
    if (newSelection.length > 0) {
        myUi._select(newSelection, new TreeRunnable("UpdaterTreeState.processAjusted") {

            @Override
            public void perform() {
                final Set<Object> hangByParent = new HashSet<>();
                processUnsuccessfulSelections(newSelection, o -> {
                    if (myUi.isInStructure(o) && !adjusted.get(o).value(o)) {
                        hangByParent.add(o);
                    } else {
                        addAdjustedSelection(o, adjusted.get(o), null);
                    }
                    return null;
                }, originallySelected);
                processHangByParent(hangByParent).notify(result);
            }
        }, false, true, true);
    } else {
        result.setDone();
    }
    return result;
}
Also used : Condition(com.intellij.openapi.util.Condition) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) TreePath(javax.swing.tree.TreePath) ActionCallback(com.intellij.openapi.util.ActionCallback) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) Function(com.intellij.util.Function) Conditions(com.intellij.openapi.util.Conditions) NotNull(org.jetbrains.annotations.NotNull) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 34 with Condition

use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.

the class XDebuggerInstanceTreeCreator method createTree.

@NotNull
@Override
public Tree createTree(@NotNull Pair<XInstanceEvaluator, String> descriptor) {
    final XDebuggerTree tree = new XDebuggerTree(myProject, myProvider, myPosition, XDebuggerActions.INSPECT_TREE_POPUP_GROUP, myMarkers);
    final XValueNodeImpl root = new XValueNodeImpl(tree, null, descriptor.getSecond(), new InstanceEvaluatorTreeRootValue(descriptor.getFirst(), descriptor.getSecond()));
    tree.setRoot(root, false);
    Condition<TreeNode> visibleRootCondition = node -> node.getParent() == root;
    tree.expandNodesOnLoad(visibleRootCondition);
    tree.selectNodeOnLoad(visibleRootCondition);
    return tree;
}
Also used : XValueNodeImpl(com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl) TreeNode(javax.swing.tree.TreeNode) XDebuggerActions(com.intellij.xdebugger.impl.actions.XDebuggerActions) XDebuggerTree(com.intellij.xdebugger.impl.ui.tree.XDebuggerTree) ResultConsumer(com.intellij.concurrency.ResultConsumer) XDebuggerEditorsProvider(com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider) XSourcePosition(com.intellij.xdebugger.XSourcePosition) XInstanceEvaluator(com.intellij.xdebugger.evaluation.XInstanceEvaluator) com.intellij.xdebugger.frame(com.intellij.xdebugger.frame) Pair(com.intellij.openapi.util.Pair) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) DebuggerTreeCreator(com.intellij.xdebugger.impl.evaluate.quick.common.DebuggerTreeCreator) XValueMarkers(com.intellij.xdebugger.impl.frame.XValueMarkers) NotNull(org.jetbrains.annotations.NotNull) XDebugSession(com.intellij.xdebugger.XDebugSession) Condition(com.intellij.openapi.util.Condition) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) TreeNode(javax.swing.tree.TreeNode) XValueNodeImpl(com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl) XDebuggerTree(com.intellij.xdebugger.impl.ui.tree.XDebuggerTree) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with Condition

use of com.intellij.openapi.util.Condition in project intellij-community by JetBrains.

the class CommandProcessor method run.

private boolean run(boolean synchronously) {
    synchronized (myLock) {
        final CommandGroup commandGroup = getNextCommandGroup();
        if (commandGroup == null || commandGroup.isEmpty())
            return false;
        final Condition conditionForGroup = commandGroup.getExpireCondition();
        final FinalizableCommand command = commandGroup.takeNextCommand();
        myCommandCount--;
        Condition expire = command.getExpireCondition() != null ? command.getExpireCondition() : conditionForGroup;
        if (expire == null)
            expire = ApplicationManager.getApplication().getDisposed();
        if (expire.value(null))
            return true;
        if (LOG.isDebugEnabled()) {
            LOG.debug("CommandProcessor.run " + command);
        }
        if (synchronously) {
            command.run();
            return true;
        }
        // max. I'm not actually quite sure this should have NON_MODAL modality but it should
        // definitely have some since runnables in command list may (and do) request some PSI activity
        final boolean queueNext = myCommandCount > 0;
        Application application = ApplicationManager.getApplication();
        ModalityState modalityState = Registry.is("ide.perProjectModality") ? ModalityState.current() : ModalityState.NON_MODAL;
        application.getInvokator().invokeLater(command, modalityState, expire).doWhenDone(() -> {
            if (queueNext) {
                run(false);
            }
        });
        return true;
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) ModalityState(com.intellij.openapi.application.ModalityState) FinalizableCommand(com.intellij.openapi.wm.impl.commands.FinalizableCommand) Application(com.intellij.openapi.application.Application)

Aggregations

Condition (com.intellij.openapi.util.Condition)48 NotNull (org.jetbrains.annotations.NotNull)26 Nullable (org.jetbrains.annotations.Nullable)23 Project (com.intellij.openapi.project.Project)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 List (java.util.List)16 StringUtil (com.intellij.openapi.util.text.StringUtil)15 ContainerUtil (com.intellij.util.containers.ContainerUtil)14 javax.swing (javax.swing)13 PsiElement (com.intellij.psi.PsiElement)11 Module (com.intellij.openapi.module.Module)10 java.util (java.util)10 Logger (com.intellij.openapi.diagnostic.Logger)9 ApplicationManager (com.intellij.openapi.application.ApplicationManager)8 NonNls (org.jetbrains.annotations.NonNls)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)7 Collection (java.util.Collection)7 ModalityState (com.intellij.openapi.application.ModalityState)6 Document (com.intellij.openapi.editor.Document)6 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)6