Search in sources :

Example 6 with GetObjectConsumer

use of org.dartlang.vm.service.consumer.GetObjectConsumer in project intellij-plugins by JetBrains.

the class DartVmServiceValue method computeCollectionChildren.

private void computeCollectionChildren(@NotNull final XCompositeNode node) {
    final int offset = myCollectionChildrenAlreadyShown.get();
    final int count = Math.min(myInstanceRef.getLength() - offset, XCompositeNode.MAX_CHILDREN_TO_SHOW);
    myDebugProcess.getVmServiceWrapper().getCollectionObject(myIsolateId, myInstanceRef.getId(), offset, count, new GetObjectConsumer() {

        @Override
        public void received(Obj instance) {
            if (isListKind(myInstanceRef.getKind())) {
                addListChildren(node, ((Instance) instance).getElements());
            } else if (myInstanceRef.getKind() == InstanceKind.Map) {
                addMapChildren(node, ((Instance) instance).getAssociations());
            } else {
                assert false : myInstanceRef.getKind();
            }
            myCollectionChildrenAlreadyShown.set(myCollectionChildrenAlreadyShown.get() + count);
            if (offset + count < myInstanceRef.getLength()) {
                node.tooManyChildren(myInstanceRef.getLength() - offset - count);
            }
        }

        @Override
        public void received(Sentinel sentinel) {
            node.setErrorMessage(sentinel.getValueAsString());
        }

        @Override
        public void onError(RPCError error) {
            node.setErrorMessage(error.getMessage());
        }
    });
}
Also used : GetObjectConsumer(org.dartlang.vm.service.consumer.GetObjectConsumer)

Example 7 with GetObjectConsumer

use of org.dartlang.vm.service.consumer.GetObjectConsumer in project flutter-intellij by flutter.

the class ScriptManager method getScriptSync.

private Script getScriptSync(@NotNull final ScriptRef scriptRef) {
    final Ref<Script> resultRef = Ref.create();
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    vmService.getObject(isolateRef.getId(), scriptRef.getId(), new GetObjectConsumer() {

        @Override
        public void received(Obj script) {
            resultRef.set((Script) script);
            semaphore.up();
        }

        @Override
        public void received(Sentinel response) {
            semaphore.up();
        }

        @Override
        public void onError(RPCError error) {
            semaphore.up();
        }
    });
    semaphore.waitFor(RESPONSE_WAIT_TIMEOUT);
    return resultRef.get();
}
Also used : GetObjectConsumer(org.dartlang.vm.service.consumer.GetObjectConsumer) Semaphore(com.intellij.util.concurrency.Semaphore)

Example 8 with GetObjectConsumer

use of org.dartlang.vm.service.consumer.GetObjectConsumer in project flutter-intellij by flutter.

the class CanonicalBreakpoint method getScriptSync.

@Nullable
public Script getScriptSync(@NotNull final String isolateId, @NotNull final String scriptId) {
    assertSyncRequestAllowed();
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    final Ref<Script> resultRef = Ref.create();
    addRequest(() -> myVmService.getObject(isolateId, scriptId, new GetObjectConsumer() {

        @Override
        public void received(Obj script) {
            resultRef.set((Script) script);
            semaphore.up();
        }

        @Override
        public void received(Sentinel response) {
            semaphore.up();
        }

        @Override
        public void onError(RPCError error) {
            semaphore.up();
        }
    }));
    semaphore.waitFor(RESPONSE_WAIT_TIMEOUT);
    return resultRef.get();
}
Also used : Script(org.dartlang.vm.service.element.Script) Sentinel(org.dartlang.vm.service.element.Sentinel) Obj(org.dartlang.vm.service.element.Obj) GetObjectConsumer(org.dartlang.vm.service.consumer.GetObjectConsumer) RPCError(org.dartlang.vm.service.element.RPCError) Semaphore(com.intellij.util.concurrency.Semaphore) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with GetObjectConsumer

use of org.dartlang.vm.service.consumer.GetObjectConsumer in project flutter-intellij by flutter.

the class DartStaticFieldsGroup method computeChildren.

@Override
public void computeChildren(@NotNull final XCompositeNode node) {
    final AtomicInteger counter = new AtomicInteger(myFieldRefs.size());
    final XValueChildrenList list = new XValueChildrenList(myFieldRefs.size());
    for (final FieldRef fieldRef : myFieldRefs) {
        myDebugProcess.getVmServiceWrapper().getObject(myIsolateId, fieldRef.getId(), new GetObjectConsumer() {

            @Override
            public void received(Obj field) {
                final InstanceRef instanceRef = ((Field) field).getStaticValue();
                // static field may be not initialized yet, in this case this instanceRef is in fact a Sentinel
                if ("@Instance".equals(instanceRef.getType())) {
                    list.add(new DartVmServiceValue(myDebugProcess, myIsolateId, ((Field) field).getName(), instanceRef, null, fieldRef, false));
                } else if ("Sentinel".equals(instanceRef.getType())) {
                    list.add(new XNamedValue(((Field) field).getName()) {

                        @Override
                        public void computeSourcePosition(@NotNull XNavigatable navigatable) {
                            DartVmServiceValue.doComputeSourcePosition(myDebugProcess, navigatable, myIsolateId, fieldRef);
                        }

                        @Override
                        public void computePresentation(@NotNull XValueNode node, @NotNull XValuePlace place) {
                            final JsonElement valueAsString = instanceRef.getJson().get("valueAsString");
                            final String value = valueAsString == null ? "not initialized" : valueAsString.getAsString();
                            node.setPresentation(AllIcons.Nodes.Field, null, value, false);
                        }
                    });
                }
                if (counter.decrementAndGet() == 0) {
                    if (list.size() == 0) {
                        node.setErrorMessage("Static fields not initialized yet");
                    } else {
                        node.addChildren(list, true);
                    }
                }
            }

            @Override
            public void received(Sentinel sentinel) {
                node.setErrorMessage(sentinel.getValueAsString());
            }

            @Override
            public void onError(RPCError error) {
                node.setErrorMessage(error.getMessage());
            }
        });
    }
}
Also used : GetObjectConsumer(org.dartlang.vm.service.consumer.GetObjectConsumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JsonElement(com.google.gson.JsonElement)

Example 10 with GetObjectConsumer

use of org.dartlang.vm.service.consumer.GetObjectConsumer in project flutter-intellij by flutter.

the class DartVmServiceStackFrame method addStaticFieldsIfPresentAndThenAllVars.

private void addStaticFieldsIfPresentAndThenAllVars(@NotNull final XCompositeNode node, @Nullable final BoundVariable thisVar, @NotNull final ElementList<BoundVariable> vars) {
    if (thisVar == null) {
        addVars(node, vars);
        return;
    }
    final Object thisVarValue = thisVar.getValue();
    if (!(thisVarValue instanceof InstanceRef)) {
        addVars(node, vars);
        return;
    }
    // InstanceRef
    final ClassRef classRef = ((InstanceRef) thisVarValue).getClassRef();
    myDebugProcess.getVmServiceWrapper().getObject(myIsolateId, classRef.getId(), new GetObjectConsumer() {

        @Override
        public void received(Obj classObj) {
            final SmartList<FieldRef> staticFields = new SmartList<>();
            for (FieldRef fieldRef : ((ClassObj) classObj).getFields()) {
                if (fieldRef.isStatic()) {
                    staticFields.add(fieldRef);
                }
            }
            if (!staticFields.isEmpty()) {
                final XValueChildrenList list = new XValueChildrenList();
                list.addTopGroup(new DartStaticFieldsGroup(myDebugProcess, myIsolateId, ((ClassObj) classObj).getName(), staticFields));
                node.addChildren(list, false);
            }
            addVars(node, vars);
        }

        @Override
        public void received(Sentinel sentinel) {
            node.setErrorMessage(sentinel.getValueAsString());
        }

        @Override
        public void onError(RPCError error) {
            node.setErrorMessage(error.getMessage());
        }
    });
}
Also used : GetObjectConsumer(org.dartlang.vm.service.consumer.GetObjectConsumer) XValueChildrenList(com.intellij.xdebugger.frame.XValueChildrenList) SmartList(com.intellij.util.SmartList)

Aggregations

GetObjectConsumer (org.dartlang.vm.service.consumer.GetObjectConsumer)11 JsonElement (com.google.gson.JsonElement)2 Project (com.intellij.openapi.project.Project)2 Semaphore (com.intellij.util.concurrency.Semaphore)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 OpenFileHyperlinkInfo (com.intellij.execution.filters.OpenFileHyperlinkInfo)1 Editor (com.intellij.openapi.editor.Editor)1 FileEditorLocation (com.intellij.openapi.fileEditor.FileEditorLocation)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 TextEditorLocation (com.intellij.openapi.fileEditor.TextEditorLocation)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 SmartList (com.intellij.util.SmartList)1 XValue (com.intellij.xdebugger.frame.XValue)1 XValueChildrenList (com.intellij.xdebugger.frame.XValueChildrenList)1 VmServiceWrapper (io.flutter.vmService.VmServiceWrapper)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1