public void evaluate(String expression, InvocationResult listener) { IExpressionManager expressionManager = DebugPlugin.getDefault().getExpressionManager(); StackFrameModel stackFrame = getTopFrame(); IWatchExpressionDelegate delegate = expressionManager.newWatchExpressionDelegate(stackFrame.getStackFrame().getModelIdentifier()); delegate.evaluateExpression(expression, stackFrame.getStackFrame(), new IWatchExpressionListener() { public void watchEvaluationFinished(IWatchExpressionResult result) { listener.valueReturn(result.getValue()); // setChanged(); // notifyObservers(new Event<IStackFrameModel>(Event.Type.EVALUATION, getTopFrame())); // try { // evaluationNotify(); // } catch (DebugException e) { // e.printStackTrace(); // } } }); }
@Override public void watchEvaluationFinished(IWatchExpressionResult result) { IJavaValue ret = (IJavaValue) result.getValue(); DebugException exception = result.getException(); if(ret != null) { if(ret instanceof IJavaObject) { IJavaObject obj = (IJavaObject) ret; if(obj.isNull()) { listener.valueReturn(null); } else { IEntityModel object = getRuntimeModel().getObject((IJavaObject) ret, true, null); listener.valueReturn(object); } } else listener.valueReturn(ret); } else if(exception != null) { String trimExpression = trimExpression(expression); InvocationException cause = (InvocationException) exception.getCause(); // cause.printStackTrace(); // ObjectReference exception2 = cause.exception(); ReferenceType referenceType = cause.exception().referenceType(); // Field field = referenceType.fieldByName("NULL_CAUSE_MESSAGE"); // StackTraceElement[] stackTrace = ((InvocationException)exception.getCause()).getStackTrace(); // String message = ((InvocationException)exception.getCause()).getMessage(); // System.out.println(message); // System.out.println(stackTrace[0].getClassName() + " " + stackTrace[0].getLineNumber()); String exceptionType = ((InvocationException)exception.getCause()).exception().referenceType().name(); PandionJUI.executeUpdate(() -> { if(exceptionType.equals(IllegalArgumentException.class.getName())) MessageDialog.openError(Display.getDefault().getActiveShell(), "Illegal arguments", trimExpression + " was invoked with illegal argument values."); else if(exceptionType.equals(IllegalStateException.class.getName())) MessageDialog.openError(Display.getDefault().getActiveShell(), "Illegal object state", "the current state of the object does not allow the operation " + trimExpression); else MessageDialog.openError(Display.getDefault().getActiveShell(), "Exception occurred", exceptionType + "\nSuggestion: execute " + trimExpression + " through code statements step by step."); }); } }
public void evaluateExpression(final String expression, final IDebugElement context, final IWatchExpressionListener listener) { final DebugElementImpl contextImpl = (DebugElementImpl) context; if (!contextImpl.getDebugTarget().isSuspended()) { // can only evaluate while suspended. Notify empty result. listener.watchEvaluationFinished(new IWatchExpressionResult() { public String[] getErrorMessages() { return EMPTY_STRINGS; } public DebugException getException() { return null; } public String getExpressionText() { return expression; } public IValue getValue() { return null; } public boolean hasErrors() { return false; } }); return; } final EvaluateContext evaluateContext = (EvaluateContext) contextImpl.getAdapter(EvaluateContext.class); if (evaluateContext == null) { listener.watchEvaluationFinished(new BadWatchExpressionResult( new DebugException(new Status(Status.ERROR, ChromiumDebugUIPlugin.PLUGIN_ID,"Bad debug context")), //$NON-NLS-1$ expression)); return; } evaluateContext.getJsEvaluateContext().evaluateAsync( expression, null, new JsEvaluateContext.EvaluateCallback() { @Override public void success(ResultOrException result) { ValueBase valueBase = result.accept(new ResultOrException.Visitor<ValueBase>() { @Override public ValueBase visitResult(JsValue value) { return Value.create(evaluateContext, value, ExpressionTracker.createExpressionNode(expression)); } @Override public ValueBase visitException(JsValue exception) { return new ValueBase.ErrorMessageValue(evaluateContext, "<abnormal return>", exception); } }); listener.watchEvaluationFinished(new GoodWatchExpressionResult(valueBase, expression)); } @Override public void failure(Exception cause) { String message = cause.getMessage(); listener.watchEvaluationFinished(new BadWatchExpressionResult(new DebugException( createErrorStatus(message == null ? Messages.JsWatchExpressionDelegate_ErrorEvaluatingExpression : message, null)), expression)); return; } }, null); }