Hi,
Please let me know if this is not the right mailing group for this kind of queries.
I am writing a java-debugger plugin for Eclipse which will need to evaluate expressions selected by the user in Eclipse Java Editor.
Currently, its only for debugging Java.
Basically, I want to implement something like Inspect or Watch capability where user can select some text and say 'My-Plugin-Command' from the pop-up-menu.
I am able to get a hold to the editor and the
selected text, but I am not able to evaluate that _expression_ into an
object which I can display. (Note: since the eclipse may be debugging a
remote JVM, the evaluation technique should be able to get the
evaluation from the remote JVM)
Please point me to some code for achieving the above.
I tried the following code, but its not giving me any value of the variable that is selected in the editor:
-------------------------------------------------------------------------------------------------------------
public class SampleHandler extends AbstractHandler {
public SampleHandler() {
}
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
IEditorPart textEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
ISelection selection = textEditor.getEditorSite().getSelectionProvider().getSelection();
if (selection instanceof ITextSelection)
{
IDebugTarget[] dbgTargets = DebugPlugin.getDefault().getLaunchManager().getDebugTargets();
if (dbgTargets == null || dbgTargets.length < 1)
{
log.info ("This functionality is available only while debugging Java.");
return null;
}
IDebugTarget dbgTarget = dbgTargets[0];
if (!(dbgTarget instanceof JDIDebugTarget))
{
log.info ("This functionality is available only while debugging Java.");
return null;
}
JDIDebugTarget javaDbgTarget = (JDIDebugTarget)dbgTarget;
try {
ITextSelection txtSel = (ITextSelection) selection;
IWatchExpression watchExpr = DebugPlugin.getDefault().getExpressionManager().newWatchExpression(txtSel.getText());
watchExpr.setExpressionContext(javaDbgTarget.findVariable(txtSel.getText()));
watchExpr.setEnabled(true);
watchExpr.evaluate();
IValue exprValue = watchExpr.getValue();
IVariable[] variables = exprValue.getVariables();
} catch (Exception e) {
e.printStackTrace();
}
}
}
-------------------------------------------------------------------------------------------------------------
Thanks a lot in advance for helping me out!