}
buf.append(" Hit Breakpoints: "); //$NON-NLS-1$
buf.append(fHitBreakpoints);
JDIDebugOptions.trace(buf.toString());
}
EvaluationResult result = new EvaluationResult(
ASTEvaluationEngine.this, fExpression.getSnippet(), fThread);
if (fExpression.hasErrors()) {
String[] errors = fExpression.getErrorMessages();
for (String error : errors) {
result.addError(error);
}
evaluationFinished(result);
if (JDIDebugOptions.DEBUG_AST_EVAL) {
StringBuffer buf = new StringBuffer();
buf.append("\tErrors: "); //$NON-NLS-1$
for (int i = 0; i < errors.length; i++) {
if (i > 0) {
buf.append('\n');
}
buf.append("\t\t"); //$NON-NLS-1$
buf.append(errors[i]);
}
JDIDebugOptions.trace(buf.toString());
}
return;
}
final Interpreter interpreter = new Interpreter(fExpression,
fContext);
class EvaluationRunnable implements IEvaluationRunnable, ITerminate {
CoreException fException;
boolean fTerminated = false;
public void run(IJavaThread jt, IProgressMonitor pm) {
EventFilter filter = new EventFilter();
try {
DebugPlugin.getDefault().addDebugEventFilter(filter);
interpreter.execute();
} catch (CoreException exception) {
fException = exception;
if (fEvaluationDetail == DebugEvent.EVALUATION
&& exception.getStatus().getException() instanceof InvocationException) {
// print the stack trace for the exception if an
// *explicit* evaluation
InvocationException invocationException = (InvocationException) exception
.getStatus().getException();
ObjectReference exObject = invocationException
.exception();
IJavaObject modelObject = (IJavaObject) JDIValue
.createValue(
(JDIDebugTarget) getDebugTarget(),
exObject);
try {
modelObject
.sendMessage(
"printStackTrace", "()V", null, jt, false); //$NON-NLS-1$ //$NON-NLS-2$
} catch (DebugException e) {
// unable to print stack trace
}
}
} finally {
DebugPlugin.getDefault().removeDebugEventFilter(filter);
}
}
public void terminate() {
fTerminated = true;
interpreter.stop();
}
public boolean canTerminate() {
return true;
}
public boolean isTerminated() {
return false;
}
public CoreException getException() {
return fException;
}
}
EvaluationRunnable er = new EvaluationRunnable();
CoreException exception = null;
long start = System.currentTimeMillis();
try {
fThread.runEvaluation(er, null, fEvaluationDetail,
fHitBreakpoints);
} catch (DebugException e) {
exception = e;
}
long end = System.currentTimeMillis();
IJavaValue value = interpreter.getResult();
if (exception == null) {
exception = er.getException();
}
result.setTerminated(er.fTerminated);
if (exception != null) {
if (JDIDebugOptions.DEBUG_AST_EVAL) {
StringBuffer buf = new StringBuffer();
buf.append("\tException: "); //$NON-NLS-1$
buf.append(exception.toString());
JDIDebugOptions.trace(buf.toString());
}
if (exception instanceof DebugException) {
result.setException((DebugException) exception);
} else {
result.setException(new DebugException(exception
.getStatus()));
}
} else {
if (value != null) {
result.setValue(value);
if (JDIDebugOptions.DEBUG_AST_EVAL) {
StringBuffer buf = new StringBuffer();
buf.append("\tResult: "); //$NON-NLS-1$
buf.append(value);
JDIDebugOptions.trace(buf.toString());
}
} else {
result.addError(EvaluationEngineMessages.ASTEvaluationEngine_An_unknown_error_occurred_during_evaluation);
}
}
if (JDIDebugOptions.DEBUG_AST_EVAL) {
StringBuffer buf = new StringBuffer();