use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.
the class ClassObjectRenderer method getFullValueEvaluator.
@Nullable
@Override
public XFullValueEvaluator getFullValueEvaluator(final EvaluationContextImpl evaluationContext, final ValueDescriptorImpl valueDescriptor) {
return new JavaValue.JavaFullValueEvaluator(DebuggerBundle.message("message.node.navigate"), evaluationContext) {
@Override
public void evaluate(@NotNull XFullValueEvaluationCallback callback) {
Value value = valueDescriptor.getValue();
ClassType type = ((ClassType) value.type());
Method nameMethod = type.concreteMethodByName("getName", "()Ljava/lang/String;");
if (nameMethod != null) {
try {
final DebugProcessImpl process = evaluationContext.getDebugProcess();
Value res = process.invokeMethod(evaluationContext, (ObjectReference) value, nameMethod, Collections.emptyList());
if (res instanceof StringReference) {
callback.evaluated("");
final String line = ((StringReference) res).value();
ApplicationManager.getApplication().runReadAction(() -> {
final PsiClass psiClass = DebuggerUtils.findClass(line, valueDescriptor.getProject(), process.getSearchScope());
if (psiClass != null) {
DebuggerUIUtil.invokeLater(() -> psiClass.navigate(true));
}
});
}
} catch (EvaluateException e) {
LOG.info("Exception while getting type name", e);
}
}
}
@Override
public boolean isShowValuePopup() {
return false;
}
};
}
use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.
the class EvaluationDescriptor method calcValue.
public final Value calcValue(EvaluationContextImpl evaluationContext) throws EvaluateException {
try {
PsiDocumentManager.getInstance(myProject).commitAndRunReadAction(() -> {
});
EvaluationContextImpl thisEvaluationContext = getEvaluationContext(evaluationContext);
SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
PsiElement psiContext = ContextUtil.getContextElement(evaluationContext, position);
ExpressionEvaluator evaluator = ReadAction.compute(() -> {
PsiCodeFragment code = getEvaluationCode(thisEvaluationContext);
try {
return DebuggerUtilsEx.findAppropriateCodeFragmentFactory(getEvaluationText(), psiContext).getEvaluatorBuilder().build(code, position);
} catch (UnsupportedExpressionException ex) {
ExpressionEvaluator eval = CompilingEvaluatorImpl.create(myProject, code.getContext(), element -> code);
if (eval != null) {
return eval;
}
throw ex;
}
});
if (!thisEvaluationContext.getDebugProcess().isAttached()) {
throw EvaluateExceptionUtil.PROCESS_EXITED;
}
StackFrameProxyImpl frameProxy = thisEvaluationContext.getFrameProxy();
if (frameProxy == null) {
throw EvaluateExceptionUtil.NULL_STACK_FRAME;
}
Value value = evaluator.evaluate(thisEvaluationContext);
DebuggerUtilsEx.keep(value, thisEvaluationContext);
myModifier = evaluator.getModifier();
setLvalue(myModifier != null);
return value;
} catch (final EvaluateException ex) {
throw new EvaluateException(ex.getLocalizedMessage(), ex);
} catch (ObjectCollectedException ex) {
throw EvaluateExceptionUtil.OBJECT_WAS_COLLECTED;
}
}
use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.
the class EvaluationDescriptor method getModifier.
@Override
public XValueModifier getModifier(JavaValue value) {
return new JavaValueModifier(value) {
@Override
protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
final EvaluationDescriptor evaluationDescriptor = EvaluationDescriptor.this;
if (evaluationDescriptor.canSetValue()) {
final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
set(expression, callback, debuggerContext, new SetValueRunnable() {
public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
final Modifier modifier = evaluationDescriptor.getModifier();
modifier.setValue(preprocessValue(evaluationContext, newValue, modifier.getExpectedType()));
update(debuggerContext);
}
public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, evaluationContext.getClassLoader());
}
});
}
}
};
}
use of com.intellij.debugger.engine.evaluation.EvaluateException 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.EvaluateException in project intellij-community by JetBrains.
the class FieldDescriptorImpl method getDescriptorEvaluation.
@Override
public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(myProject).getElementFactory();
String fieldName;
if (isStatic()) {
String typeName = myField.declaringType().name().replace('$', '.');
typeName = DebuggerTreeNodeExpression.normalize(typeName, PositionUtil.getContextElement(context), myProject);
fieldName = typeName + "." + getName();
} else {
//noinspection HardCodedStringLiteral
fieldName = isOuterLocalVariableValue() ? StringUtil.trimStart(getName(), OUTER_LOCAL_VAR_FIELD_PREFIX) : "this." + getName();
}
try {
return elementFactory.createExpressionFromText(fieldName, null);
} catch (IncorrectOperationException e) {
throw new EvaluateException(DebuggerBundle.message("error.invalid.field.name", getName()), e);
}
}
Aggregations