Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Dynamic expression evaluation in Eclipse Debugger plugin(Dynamic expression evaluation in Eclipse Debugger plugin)
Dynamic expression evaluation in Eclipse Debugger plugin [message #1034961] Sat, 06 April 2013 05:16
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 10
Registered: February 2010
Junior Member

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)
{ ("This functionality is available only while debugging Java.");
return null;
IDebugTarget dbgTarget = dbgTargets[0];
if (!(dbgTarget instanceof JDIDebugTarget))
{ ("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());
IValue exprValue = watchExpr.getValue();

IVariable[] variables = exprValue.getVariables(); (variables.length);
} catch (Exception e) {

Thanks a lot in advance for helping me out!
Previous Topic:* B U G * ? Install new Software not working - Juno SR2 Linux32bit
Next Topic:Enabling navigation history for inter tab navigation
Goto Forum:

Current Time: Sun Nov 29 17:53:06 GMT 2015

Powered by FUDForum. Page generated in 0.10439 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software