From 26fc07b6cf3c3f007ed6b2cf6014a6e2d39c32c4 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Wed, 18 Sep 2002 19:02:52 +0000 Subject: [PATCH] Implementation of expressions. --- .../internal/core/model/CDebugTarget.java | 34 ++++++++++ .../internal/core/model/CExpression.java | 5 ++ .../ui/CDTDebugModelPresentation.java | 10 +++ .../actions/AddExpressionActionDelegate.java | 67 ++++++++++--------- 4 files changed, 85 insertions(+), 31 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java index 5e6b79abb49..8f6bc0b4c74 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java @@ -28,6 +28,7 @@ import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointManager; import org.eclipse.cdt.debug.core.cdi.ICDICondition; import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration; import org.eclipse.cdt.debug.core.cdi.ICDIEndSteppingRange; +import org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager; import org.eclipse.cdt.debug.core.cdi.ICDILocation; import org.eclipse.cdt.debug.core.cdi.ICDIRegisterObject; import org.eclipse.cdt.debug.core.cdi.ICDISessionObject; @@ -60,6 +61,7 @@ import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IBreakpointManager; import org.eclipse.debug.core.IExpressionListener; +import org.eclipse.debug.core.IExpressionManager; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchListener; import org.eclipse.debug.core.model.IBreakpoint; @@ -210,6 +212,7 @@ public class CDebugTarget extends CDebugElement setThreadList( new ArrayList( 5 ) ); initialize(); DebugPlugin.getDefault().getLaunchManager().addLaunchListener( this ); + DebugPlugin.getDefault().getExpressionManager().addExpressionListener( this ); getCDISession().getEventManager().addEventListener( this ); } @@ -996,7 +999,9 @@ public class CDebugTarget extends CDebugElement removeAllRegisterGroups(); getCDISession().getEventManager().removeEventListener( this ); DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener( this ); + DebugPlugin.getDefault().getExpressionManager().removeExpressionListener( this ); DebugPlugin.getDefault().getLaunchManager().removeLaunchListener( this ); + removeAllExpressions(); try { removeAllBreakpoints(); @@ -1023,6 +1028,23 @@ public class CDebugTarget extends CDebugElement } } + /** + * Removes all expressions from this target. + * + */ + protected void removeAllExpressions() + { + IExpressionManager em = DebugPlugin.getDefault().getExpressionManager(); + IExpression[] expressions = em.getExpressions(); + for ( int i = 0; i < expressions.length; ++i ) + { + if ( expressions[i] instanceof CExpression && expressions[i].getDebugTarget().equals( this ) ) + { + em.removeExpression( expressions[i] ); + } + } + } + /** * Removes all breakpoints from this target. * @@ -1681,5 +1703,17 @@ public class CDebugTarget extends CDebugElement */ public void expressionRemoved( IExpression expression ) { + if ( expression != null && expression.getDebugTarget().equals( this ) && expression instanceof CExpression ) + { + ICDIExpressionManager em = getCDISession().getExpressionManager(); + try + { + em.removeExpression( ((CExpression)expression).getCDIExpression() ); + } + catch( CDIException e ) + { + // do nothing + } + } } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CExpression.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CExpression.java index f61d7f1cc77..9dfbad14a52 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CExpression.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CExpression.java @@ -66,4 +66,9 @@ public class CExpression extends CVariable { super.dispose(); } + + protected ICDIExpression getCDIExpression() + { + return (ICDIExpression)getCDIVariable(); + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java index 960ddabd4ce..fcfea6a6781 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java @@ -35,6 +35,7 @@ import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IDisconnect; +import org.eclipse.debug.core.model.IExpression; import org.eclipse.debug.core.model.IRegister; import org.eclipse.debug.core.model.IRegisterGroup; import org.eclipse.debug.core.model.IStackFrame; @@ -181,6 +182,10 @@ public class CDTDebugModelPresentation extends LabelProvider { return getRegisterGroupImage( (IRegisterGroup)element ); } + if ( element instanceof IExpression ) + { + return getExpressionImage( (IExpression)element ); + } if ( element instanceof IRegister ) { return getRegisterImage( (IRegister)element ); @@ -671,4 +676,9 @@ public class CDTDebugModelPresentation extends LabelProvider { return fDebugImageRegistry.get( new CImageDescriptor( CDebugImages.DESC_OBJS_REGISTER, 0 ) ); } + + protected Image getExpressionImage( IExpression element ) throws DebugException + { + return fDebugImageRegistry.get( new CImageDescriptor( DebugUITools.getImageDescriptor( IDebugUIConstants.IMG_OBJS_EXPRESSION ), 0 ) ); + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionActionDelegate.java index a44f6e34163..e45f6004319 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionActionDelegate.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionActionDelegate.java @@ -5,29 +5,31 @@ */ package org.eclipse.cdt.debug.internal.ui.actions; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.CDebugModel; import org.eclipse.cdt.debug.core.ICExpressionEvaluator; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IDebugEventSetListener; import org.eclipse.debug.core.model.IDebugElement; import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IExpression; import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorActionDelegate; import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.INullSelectionListener; import org.eclipse.ui.IPartListener; +import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; @@ -43,19 +45,20 @@ import org.eclipse.ui.texteditor.ITextEditor; public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelegate, IEditorActionDelegate, IPartListener, - IDebugEventSetListener + ISelectionListener, + INullSelectionListener { private IAction fAction; private IWorkbenchWindow fWorkbenchWindow; private IWorkbenchPart fTargetPart; private IEditorPart fTargetEditor; + private IDebugTarget fDebugTarget = null; /** * Constructor for AddExpressionActionDelegate. */ public AddExpressionActionDelegate() { - DebugPlugin.getDefault().addDebugEventListener( this ); } /* (non-Javadoc) @@ -63,11 +66,11 @@ public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelega */ public void dispose() { - DebugPlugin.getDefault().removeDebugEventListener( this ); IWorkbenchWindow win = getWorkbenchWindow(); if ( win != null ) { win.getPartService().removePartListener( this ); + win.getSelectionService().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this ); } } @@ -83,6 +86,7 @@ public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelega setTargetPart( page.getActivePart() ); } window.getPartService().addPartListener( this ); + window.getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this ); update(); } @@ -239,24 +243,6 @@ public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelega } return null; } - - protected IDebugTarget getDebugTarget() - { - IAdaptable context = DebugUITools.getDebugContext(); - if ( context != null ) - { - IDebugTarget target = ((IDebugTarget)context.getAdapter( IDebugTarget.class )).getDebugTarget(); - if ( target != null ) - { - ICExpressionEvaluator ee = (ICExpressionEvaluator)target.getAdapter( ICExpressionEvaluator.class ); - if ( ee != null && ee.canEvaluate() ) - { - return target; - } - } - } - return null; - } private void createExpression( final String text ) { @@ -281,19 +267,38 @@ public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelega } } ); } - /** - * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(DebugEvent[]) + * @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, ISelection) */ - public void handleDebugEvents( DebugEvent[] events ) + public void selectionChanged( IWorkbenchPart part, ISelection selection ) { - for ( int i = 0; i < events.length; ++i ) + IDebugTarget target = null; + if ( part.getSite().getId().equals( IDebugUIConstants.ID_DEBUG_VIEW ) ) { - if ( ( events[i].getKind() == DebugEvent.CREATE || events[i].getKind() == DebugEvent.TERMINATE ) && - events[i].getSource() instanceof ICExpressionEvaluator ) + if ( selection != null && selection instanceof IStructuredSelection ) { - update(); + Object element = ((IStructuredSelection)selection).getFirstElement(); + if ( element != null && element instanceof IDebugElement ) + { + IDebugTarget target1 = ((IDebugElement)element).getDebugTarget(); + if ( target1 != null && target1 instanceof ICExpressionEvaluator ) + { + target = target1; + } + } } + setDebugTarget( target ); + update(); } } + + protected void setDebugTarget( IDebugTarget target ) + { + fDebugTarget = target; + } + + protected IDebugTarget getDebugTarget() + { + return fDebugTarget; + } }