try {
IJavaType type = javaValue.getJavaType();
if (!(type instanceof IJavaClassType)) {
return null;
}
IJavaStackFrame stackFrame = getStackFrame(javaValue);
if (stackFrame == null) {
return null;
}
// find the project the snippets will be compiled in.
ISourceLocator locator = javaValue.getLaunch().getSourceLocator();
Object sourceElement = null;
if (locator instanceof ISourceLookupDirector) {
if (type instanceof JDIReferenceType) {
String[] sourcePaths = ((JDIReferenceType) type)
.getSourcePaths(null);
if (sourcePaths.length > 0) {
sourceElement = ((ISourceLookupDirector) locator)
.getSourceElement(sourcePaths[0]);
}
}
if (!(sourceElement instanceof IJavaElement)
&& sourceElement instanceof IAdaptable) {
sourceElement = ((IAdaptable) sourceElement)
.getAdapter(IJavaElement.class);
}
}
if (sourceElement == null) {
sourceElement = locator.getSourceElement(stackFrame);
if (!(sourceElement instanceof IJavaElement)
&& sourceElement instanceof IAdaptable) {
sourceElement = ((IAdaptable) sourceElement)
.getAdapter(IJavaElement.class);
}
}
IJavaProject project = null;
if (sourceElement instanceof IJavaElement) {
project = ((IJavaElement) sourceElement).getJavaProject();
} else if (sourceElement instanceof IResource) {
IJavaProject resourceProject = JavaCore
.create(((IResource) sourceElement).getProject());
if (resourceProject.exists()) {
project = resourceProject;
}
}
if (project == null) {
return null;
}
IAstEvaluationEngine evaluationEngine = JDIDebugPlugin.getDefault()
.getEvaluationEngine(project,
(IJavaDebugTarget) stackFrame.getDebugTarget());
EvaluationBlock evaluationBlock = new EvaluationBlock(javaValue,
(IJavaReferenceType) type, (IJavaThread) stackFrame.getThread(),
evaluationEngine);
return evaluationBlock.evaluate(expression);
} catch (CoreException e) {
DroolsIDEPlugin.log(e);