use of com.intellij.debugger.engine.evaluation.EvaluationContextImpl in project intellij-community by JetBrains.
the class FieldDescriptorImpl method getModifier.
@Override
public XValueModifier getModifier(JavaValue value) {
return new JavaValueModifier(value) {
@Override
protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
FieldDescriptorImpl fieldDescriptor = FieldDescriptorImpl.this;
final Field field = fieldDescriptor.getField();
if (!field.isStatic()) {
final ObjectReference object = fieldDescriptor.getObject();
if (object != null) {
set(expression, callback, debuggerContext, new SetValueRunnable() {
public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
object.setValue(field, preprocessValue(evaluationContext, newValue, field.type()));
update(debuggerContext);
}
public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, field.declaringType().classLoader());
}
});
}
} else {
// field is static
ReferenceType refType = field.declaringType();
if (refType instanceof ClassType) {
final ClassType classType = (ClassType) refType;
set(expression, callback, debuggerContext, new SetValueRunnable() {
public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
classType.setValue(field, preprocessValue(evaluationContext, newValue, field.type()));
update(debuggerContext);
}
public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, field.declaringType().classLoader());
}
});
}
}
}
};
}
use of com.intellij.debugger.engine.evaluation.EvaluationContextImpl in project intellij-community by JetBrains.
the class ArrayElementDescriptorImpl method getModifier.
@Override
public XValueModifier getModifier(JavaValue value) {
return new JavaValueModifier(value) {
@Override
protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
final ArrayElementDescriptorImpl elementDescriptor = ArrayElementDescriptorImpl.this;
final ArrayReference array = elementDescriptor.getArray();
if (array != null) {
if (VirtualMachineProxyImpl.isCollected(array)) {
// will only be the case if debugger does not use ObjectReference.disableCollection() because of Patches.IBM_JDK_DISABLE_COLLECTION_BUG
Messages.showWarningDialog(getProject(), DebuggerBundle.message("evaluation.error.array.collected") + "\n" + DebuggerBundle.message("warning.recalculate"), DebuggerBundle.message("title.set.value"));
//node.getParent().calcValue();
return;
}
final ArrayType arrType = (ArrayType) array.referenceType();
final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
set(expression, callback, debuggerContext, new SetValueRunnable() {
public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
array.setValue(elementDescriptor.getIndex(), preprocessValue(evaluationContext, newValue, arrType.componentType()));
update(debuggerContext);
}
public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, arrType.classLoader());
}
});
}
}
};
}
use of com.intellij.debugger.engine.evaluation.EvaluationContextImpl in project intellij-community by JetBrains.
the class JavaStackFrame method buildVariables.
// copied from FrameVariablesTree
private void buildVariables(DebuggerContextImpl debuggerContext, final EvaluationContextImpl evaluationContext, @NotNull DebugProcessImpl debugProcess, XValueChildrenList children, ObjectReference thisObjectReference, Location location) throws EvaluateException {
final Set<String> visibleLocals = new HashSet<>();
if (NodeRendererSettings.getInstance().getClassRenderer().SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES) {
if (thisObjectReference != null && debugProcess.getVirtualMachineProxy().canGetSyntheticAttribute()) {
final ReferenceType thisRefType = thisObjectReference.referenceType();
if (thisRefType instanceof ClassType && location != null && thisRefType.equals(location.declaringType()) && thisRefType.name().contains("$")) {
// makes sense for nested classes only
for (Field field : thisRefType.fields()) {
if (DebuggerUtils.isSynthetic(field) && StringUtil.startsWith(field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
final FieldDescriptorImpl fieldDescriptor = myNodeManager.getFieldDescriptor(myDescriptor, thisObjectReference, field);
children.add(JavaValue.create(fieldDescriptor, evaluationContext, myNodeManager));
visibleLocals.add(fieldDescriptor.calcValueName());
}
}
}
}
}
boolean myAutoWatchMode = DebuggerSettings.getInstance().AUTO_VARIABLES_MODE;
if (evaluationContext == null) {
return;
}
try {
if (!XDebuggerSettingsManager.getInstance().getDataViewSettings().isAutoExpressions() && !myAutoWatchMode) {
// optimization
superBuildVariables(evaluationContext, children);
} else {
final SourcePosition sourcePosition = debuggerContext.getSourcePosition();
final Map<String, LocalVariableProxyImpl> visibleVariables = ContainerUtil.map2Map(getVisibleVariables(), var -> Pair.create(var.name(), var));
Pair<Set<String>, Set<TextWithImports>> usedVars = EMPTY_USED_VARS;
if (sourcePosition != null) {
usedVars = ApplicationManager.getApplication().runReadAction(new Computable<Pair<Set<String>, Set<TextWithImports>>>() {
@Override
public Pair<Set<String>, Set<TextWithImports>> compute() {
return findReferencedVars(ContainerUtil.union(visibleVariables.keySet(), visibleLocals), sourcePosition);
}
});
}
// add locals
if (myAutoWatchMode) {
for (String var : usedVars.first) {
LocalVariableProxyImpl local = visibleVariables.get(var);
if (local != null) {
children.add(JavaValue.create(myNodeManager.getLocalVariableDescriptor(null, local), evaluationContext, myNodeManager));
}
}
} else {
superBuildVariables(evaluationContext, children);
}
final EvaluationContextImpl evalContextCopy = evaluationContext.createEvaluationContext(evaluationContext.getThisObject());
evalContextCopy.setAutoLoadClasses(false);
if (sourcePosition != null) {
Set<TextWithImports> extraVars = computeExtraVars(usedVars, sourcePosition, evaluationContext);
// add extra vars
addToChildrenFrom(extraVars, children, evaluationContext);
}
// add expressions
addToChildrenFrom(usedVars.second, children, evalContextCopy);
}
} catch (EvaluateException e) {
if (e.getCause() instanceof AbsentInformationException) {
children.add(LOCAL_VARIABLES_INFO_UNAVAILABLE_MESSAGE_NODE);
// trying to collect values from variable slots
try {
for (Map.Entry<DecompiledLocalVariable, Value> entry : LocalVariablesUtil.fetchValues(getStackFrameProxy(), debugProcess, true).entrySet()) {
children.add(JavaValue.create(myNodeManager.getArgumentValueDescriptor(null, entry.getKey(), entry.getValue()), evaluationContext, myNodeManager));
}
} catch (Exception ex) {
LOG.info(ex);
}
} else {
throw e;
}
}
}
use of com.intellij.debugger.engine.evaluation.EvaluationContextImpl in project intellij-community by JetBrains.
the class ValueDescriptorImpl method getValue.
@Override
public Value getValue() {
// to keep temporary objects
if (Patches.IBM_JDK_DISABLE_COLLECTION_BUG) {
final EvaluationContextImpl evalContext = myStoredEvaluationContext;
if (evalContext != null && !evalContext.getSuspendContext().isResumed() && myValue instanceof ObjectReference && VirtualMachineProxyImpl.isCollected((ObjectReference) myValue)) {
final Semaphore semaphore = new Semaphore();
semaphore.down();
evalContext.getDebugProcess().getManagerThread().invoke(new SuspendContextCommandImpl(evalContext.getSuspendContext()) {
@Override
public void contextAction() throws Exception {
// re-setting the context will cause value recalculation
try {
setContext(myStoredEvaluationContext);
} finally {
semaphore.up();
}
}
@Override
protected void commandCancelled() {
semaphore.up();
}
});
semaphore.waitFor();
}
}
assertValueReady();
return myValue;
}
use of com.intellij.debugger.engine.evaluation.EvaluationContextImpl in project intellij-community by JetBrains.
the class DebuggerTreeNodeImpl method calcValue.
public void calcValue() {
final DebuggerContextImpl context = getTree().getDebuggerContext();
update(context, () -> {
EvaluationContextImpl evaluationContext = context.createEvaluationContext();
getDescriptor().setContext(evaluationContext);
getDescriptor().updateRepresentation(evaluationContext, new DescriptorLabelListener() {
@Override
public void labelChanged() {
updateCaches();
DebuggerTreeNodeImpl.this.labelChanged();
}
});
childrenChanged(true);
}, false);
}
Aggregations