Skip to main content



      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 01:16
Eclipse UserFriend
Hi,

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();
log.info (variables.length);
} catch (Exception e) {
e.printStackTrace();
}
}
}
-------------------------------------------------------------------------------------

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 Jun 22 21:21:23 EDT 2025

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

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

Back to the top