use of com.intellij.debugger.engine.events.SuspendContextCommandImpl in project intellij-community by JetBrains.
the class JavaValue method computePresentation.
@Override
public void computePresentation(@NotNull final XValueNode node, @NotNull XValuePlace place) {
final SuspendContextImpl suspendContext = myEvaluationContext.getSuspendContext();
myEvaluationContext.getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) {
@Override
public Priority getPriority() {
return Priority.NORMAL;
}
@Override
protected void commandCancelled() {
node.setPresentation(null, new XErrorValuePresentation(DebuggerBundle.message("error.context.has.changed")), false);
}
@Override
public void contextAction() throws Exception {
if (node.isObsolete()) {
return;
}
if (!myContextSet) {
myValueDescriptor.setContext(myEvaluationContext);
}
myValueDescriptor.updateRepresentation(myEvaluationContext, new DescriptorLabelListener() {
@Override
public void labelChanged() {
Icon nodeIcon = DebuggerTreeRenderer.getValueIcon(myValueDescriptor);
final String value = getValueString();
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") EvaluateException exception = myValueDescriptor.getEvaluateException();
XValuePresentation presentation = new JavaValuePresentation(value, myValueDescriptor.getIdLabel(), exception != null ? exception.getMessage() : null, myValueDescriptor);
if (myValueDescriptor.getLastRenderer() instanceof FullValueEvaluatorProvider) {
XFullValueEvaluator evaluator = ((FullValueEvaluatorProvider) myValueDescriptor.getLastRenderer()).getFullValueEvaluator(myEvaluationContext, myValueDescriptor);
if (evaluator != null) {
node.setFullValueEvaluator(evaluator);
}
} else if (value.length() > XValueNode.MAX_VALUE_LENGTH) {
node.setFullValueEvaluator(new JavaFullValueEvaluator(myEvaluationContext) {
@Override
public void evaluate(@NotNull final XFullValueEvaluationCallback callback) {
final ValueDescriptorImpl fullValueDescriptor = myValueDescriptor.getFullValueDescriptor();
fullValueDescriptor.updateRepresentation(myEvaluationContext, new DescriptorLabelListener() {
@Override
public void labelChanged() {
callback.evaluated(fullValueDescriptor.getValueText());
}
});
}
});
}
node.setPresentation(nodeIcon, presentation, myValueDescriptor.isExpandable());
}
});
}
});
}
use of com.intellij.debugger.engine.events.SuspendContextCommandImpl in project intellij-community by JetBrains.
the class JavaValue method computeChildren.
@Override
public void computeChildren(@NotNull final XCompositeNode node) {
scheduleCommand(myEvaluationContext, node, new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {
@Override
public Priority getPriority() {
return Priority.NORMAL;
}
@Override
public void contextAction() throws Exception {
final XValueChildrenList children = new XValueChildrenList();
final NodeRenderer renderer = myValueDescriptor.getRenderer(myEvaluationContext.getDebugProcess());
final Ref<Integer> remainingNum = new Ref<>(0);
renderer.buildChildren(myValueDescriptor.getValue(), new ChildrenBuilder() {
@Override
public NodeDescriptorFactory getDescriptorManager() {
return myNodeManager;
}
@Override
public NodeManager getNodeManager() {
return myNodeManager;
}
@Override
public ValueDescriptor getParentDescriptor() {
return myValueDescriptor;
}
@Override
public void setRemaining(int remaining) {
remainingNum.set(remaining);
}
@Override
public void initChildrenArrayRenderer(ArrayRenderer renderer) {
renderer.START_INDEX = myCurrentChildrenStart;
renderer.END_INDEX = myCurrentChildrenStart + XCompositeNode.MAX_CHILDREN_TO_SHOW - 1;
myCurrentChildrenStart += XCompositeNode.MAX_CHILDREN_TO_SHOW;
}
@Override
public void setChildren(List<DebuggerTreeNode> nodes) {
for (DebuggerTreeNode node : nodes) {
final NodeDescriptor descriptor = node.getDescriptor();
if (descriptor instanceof ValueDescriptorImpl) {
// Value is calculated already in NodeManagerImpl
children.add(create(JavaValue.this, (ValueDescriptorImpl) descriptor, myEvaluationContext, myNodeManager, false));
} else if (descriptor instanceof MessageDescriptor) {
children.add(new JavaStackFrame.DummyMessageValueNode(descriptor.getLabel(), null));
}
}
}
}, myEvaluationContext);
node.addChildren(children, true);
if (remainingNum.get() > 0) {
node.tooManyChildren(remainingNum.get());
}
}
});
}
use of com.intellij.debugger.engine.events.SuspendContextCommandImpl in project intellij-community by JetBrains.
the class JavaValue method calculateEvaluationExpression.
@NotNull
@Override
public Promise<XExpression> calculateEvaluationExpression() {
if (evaluationExpression != null) {
return Promise.resolve(evaluationExpression);
} else {
final AsyncPromise<XExpression> res = new AsyncPromise<>();
myEvaluationContext.getManagerThread().schedule(new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {
@Override
public Priority getPriority() {
return Priority.HIGH;
}
@Override
public void contextAction() throws Exception {
evaluationExpression = ApplicationManager.getApplication().runReadAction(new Computable<XExpression>() {
@Override
public XExpression compute() {
try {
PsiElement psiExpression = getDescriptor().getTreeEvaluation(JavaValue.this, getDebuggerContext());
if (psiExpression != null) {
XExpression res = TextWithImportsImpl.toXExpression(new TextWithImportsImpl(psiExpression));
// add runtime imports if any
Set<String> imports = psiExpression.getUserData(DebuggerTreeNodeExpression.ADDITIONAL_IMPORTS_KEY);
if (imports != null && res != null) {
if (res.getCustomInfo() != null) {
imports.add(res.getCustomInfo());
}
res = new XExpressionImpl(res.getExpression(), res.getLanguage(), StringUtil.join(imports, ","), res.getMode());
}
return res;
}
} catch (EvaluateException e) {
LOG.info(e);
}
return null;
}
});
res.setResult(evaluationExpression);
}
});
return res;
}
}
use of com.intellij.debugger.engine.events.SuspendContextCommandImpl in project intellij-community by JetBrains.
the class AdjustArrayRangeAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext());
DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
if (debugProcess == null) {
return;
}
final Project project = debuggerContext.getProject();
final XValueNodeImpl node = XDebuggerTreeActionBase.getSelectedNode(e.getDataContext());
if (node == null) {
return;
}
final XValue container = node.getValueContainer();
if (!(container instanceof JavaValue)) {
return;
}
final ValueDescriptorImpl descriptor = ((JavaValue) container).getDescriptor();
ArrayRenderer renderer = getArrayRenderer(descriptor);
if (renderer == null) {
return;
}
//String title = createNodeTitle("", selectedNode);
//String label = selectedNode.toString();
//int index = label.indexOf('=');
//if (index > 0) {
// title = title + " " + label.substring(index);
//}
String title = node.getName();
final ArrayRenderer clonedRenderer = renderer.clone();
clonedRenderer.setForced(true);
if (ShowSettingsUtil.getInstance().editConfigurable(project, new NamedArrayConfigurable(title, clonedRenderer))) {
debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(debuggerContext.getSuspendContext()) {
@Override
public void contextAction() throws Exception {
final Renderer lastRenderer = descriptor.getLastRenderer();
if (lastRenderer instanceof ArrayRenderer) {
((JavaValue) container).setRenderer(clonedRenderer, node);
} else if (lastRenderer instanceof CompoundNodeRenderer) {
final CompoundNodeRenderer compoundRenderer = (CompoundNodeRenderer) lastRenderer;
final ChildrenRenderer childrenRenderer = compoundRenderer.getChildrenRenderer();
if (childrenRenderer instanceof ExpressionChildrenRenderer) {
ExpressionChildrenRenderer.setPreferableChildrenRenderer(descriptor, clonedRenderer);
((JavaValue) container).reBuild(node);
}
}
}
});
}
}
use of com.intellij.debugger.engine.events.SuspendContextCommandImpl in project intellij-community by JetBrains.
the class DescriptorTestCase method resume.
@Override
protected void resume(final SuspendContextImpl suspendContext) {
final DebugProcessImpl localProcess = suspendContext.getDebugProcess();
invokeRatherLater(new SuspendContextCommandImpl(suspendContext) {
@Override
public void contextAction() throws Exception {
flushDescriptors();
localProcess.getManagerThread().schedule(localProcess.createResumeCommand(suspendContext, Priority.LOW));
}
});
}
Aggregations