From 3f637585018f791b7076d1aed3a44dd399a2d769 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Thu, 12 Sep 2002 19:10:46 +0000 Subject: [PATCH] Refactoring: moved some methods from CLocalVariable to CVariable and CModificationVariable. --- .../core/model/CArrayEntryVariable.java | 6 +- .../internal/core/model/CArrayPartition.java | 4 +- .../internal/core/model/CLocalVariable.java | 144 +----------------- .../core/model/CModificationVariable.java | 56 ++++++- .../debug/internal/core/model/CVariable.java | 131 +++++++++++++++- 5 files changed, 179 insertions(+), 162 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayEntryVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayEntryVariable.java index 18dbd14e2aa..5b930e94e90 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayEntryVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayEntryVariable.java @@ -18,7 +18,7 @@ import org.eclipse.debug.core.DebugException; * * @since Sep 9, 2002 */ -public class CArrayEntryVariable extends CLocalVariable +public class CArrayEntryVariable extends CModificationVariable { /** * The index of the variable entry. @@ -34,9 +34,9 @@ public class CArrayEntryVariable extends CLocalVariable * Constructor for CArrayEntryVariable. * @param target */ - public CArrayEntryVariable( CDebugTarget target, ICDIVariable cdiVariable, int index ) + public CArrayEntryVariable( CDebugElement parent, ICDIVariable cdiVariable, int index ) { - super( target, cdiVariable ); + super( parent, cdiVariable ); fIndex = index; } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java index 48602928954..74886103736 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartition.java @@ -41,9 +41,9 @@ public class CArrayPartition extends CVariable * Constructor for CArrayPartition. * @param target */ - public CArrayPartition( CDebugTarget target, List cdiVariables, int start, int end ) + public CArrayPartition( CDebugElement parent, List cdiVariables, int start, int end ) { - super( target ); + super( parent, null ); fStart = start; fEnd = end; fCDIVariables = cdiVariables; diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CLocalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CLocalVariable.java index 4ca128e3496..c66be9ffbb0 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CLocalVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CLocalVariable.java @@ -26,155 +26,13 @@ import org.eclipse.debug.core.model.IValue; * @since Aug 9, 2002 */ public class CLocalVariable extends CModificationVariable - implements ICDIEventListener { - /** - * The underlying CDI variable. - */ - private ICDIVariable fCDIVariable; - - /** - * The parent object this variable is contained in. - */ - private CDebugElement fParent; - /** * Constructor for CLocalVariable. * @param target */ public CLocalVariable( CDebugElement parent, ICDIVariable cdiVariable ) { - super( (CDebugTarget)parent.getDebugTarget() ); - fParent = parent; - fCDIVariable = cdiVariable; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.CModificationVariable#setValue(ICDIValue) - */ - protected void setValue( ICDIValue value ) throws DebugException - { - try - { - getCDIVariable().setValue( value ); - } - catch( CDIException e ) - { - targetRequestFailed( MessageFormat.format( "{0} occured modifying local variable value.", new String[] { e.toString() } ), e ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.CVariable#retrieveValue() - */ - protected ICDIValue retrieveValue() throws DebugException, CDIException - { - return ( ((IDebugTarget)getParent().getDebugTarget()).isSuspended() ) ? - getCDIVariable().getValue() : getLastKnownValue(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IVariable#getName() - */ - public String getName() throws DebugException - { - String name = null; - try - { - name = getCDIVariable().getName(); - } - catch( CDIException e ) - { - targetRequestFailed( MessageFormat.format( "{0} occured while retrieving local variable name.", new String[] { e.toString() } ), e ); - } - return name; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName() - */ - public String getReferenceTypeName() throws DebugException - { - String type = null; - try - { - type = getCDIVariable().getTypeName(); - } - catch( CDIException e ) - { - targetRequestFailed( MessageFormat.format( "{0} occured while retrieving local variable type.", new String[] { e.toString() } ), e ); - } - return type; - } - - /** - * Returns the underlying CDI variable. - * - * @return the underlying CDI variable - */ - protected ICDIVariable getCDIVariable() - { - return fCDIVariable; - } - - protected void setCDIVariable( ICDIVariable newVar ) - { - fCDIVariable = newVar; - } - - /** - * Returns the stack frame this variable is contained in. - * - * @return the stack frame - */ - protected CDebugElement getParent() - { - return fParent; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvent(ICDIEvent) - */ - public void handleDebugEvent( ICDIEvent event ) - { - ICDIObject source = event.getSource(); - if (source == null) - return; - - if ( source.getTarget().equals( getCDITarget() ) ) - { - if ( event instanceof ICDIChangedEvent ) - { - if ( source instanceof ICDIVariable && source.equals( getCDIVariable() ) ) - { - handleChangedEvent( (ICDIChangedEvent)event ); - } - } - } - } - - private void handleChangedEvent( ICDIChangedEvent event ) - { - try - { - //setValue( getCurrentValue() ); - setChanged( true ); - getParent().fireChangeEvent( DebugEvent.CONTENT ); - } - catch( DebugException e ) - { - logError( e ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IValueModification#setValue(IValue) - */ - public void setValue( IValue value ) throws DebugException - { - if ( verifyValue( value ) ) - { - setValue( ((CValue)value).getUnderlyingValue() ); - } + super( parent, cdiVariable ); } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CModificationVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CModificationVariable.java index 2c2e6c2474e..082e0d73189 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CModificationVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CModificationVariable.java @@ -8,6 +8,7 @@ package org.eclipse.cdt.debug.internal.core.model; import java.text.MessageFormat; +import org.eclipse.cdt.debug.core.ICValue; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.ICDIArrayValue; import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression; @@ -31,11 +32,12 @@ public abstract class CModificationVariable extends CVariable /** * Constructor for CModificationVariable. - * @param target + * @param parent + * @param cdiVariable */ - public CModificationVariable( CDebugTarget target ) + public CModificationVariable( CDebugElement parent, ICDIVariable cdiVariable ) { - super( target ); + super( parent, cdiVariable ); } /* (non-Javadoc) @@ -81,15 +83,17 @@ public abstract class CModificationVariable extends CVariable */ public final void setValue( String expression ) throws DebugException { + String newExpression = processExpression( expression ); ICDIVariable cdiVariable = getCDIVariable(); if ( cdiVariable == null ) { logError( "Error in IValueModification#setValue: no cdi variable." ); requestFailed( "Unable to set value.", null ); + return; } try { - cdiVariable.setValue( expression ); + cdiVariable.setValue( newExpression ); } catch( CDIException e ) { @@ -100,7 +104,47 @@ public abstract class CModificationVariable extends CVariable /** * Set this variable's value to the given value */ - protected abstract void setValue( ICDIValue value ) throws DebugException; + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.internal.core.CModificationVariable#setValue(ICDIValue) + */ + protected void setValue( ICDIValue value ) throws DebugException + { + ICDIVariable cdiVariable = getCDIVariable(); + if ( cdiVariable == null ) + { + logError( "Error in IValueModification#setValue: no cdi variable." ); + requestFailed( "Unable to set value.", null ); + return; + } + try + { + cdiVariable.setValue( value ); + } + catch( CDIException e ) + { + targetRequestFailed( e.getMessage(), null ); + } + } - protected abstract ICDIVariable getCDIVariable(); + private String processExpression( String oldExpression ) throws DebugException + { + CValue value = (CValue)getValue(); + if ( value == null ) + { + logError( "Error in IValueModification#setValue: no value." ); + requestFailed( "Unable to set value.", null ); + return null; + } + if ( value.getType() == ICValue.TYPE_CHAR ) + { + char[] chars = oldExpression.toCharArray(); + if ( chars.length != 1 ) + { + requestFailed( MessageFormat.format( "Invalid value: ''{0}''.", new Object[] { oldExpression } ), null ); + return null; + } + return Short.toString( (short)chars[0] ); + } + return oldExpression; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java index f0d9fe445d0..c4418a8bf11 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java @@ -7,12 +7,17 @@ package org.eclipse.cdt.debug.internal.core.model; import java.text.MessageFormat; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICValue; import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent; +import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; +import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; +import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; +import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IVariable; @@ -26,6 +31,16 @@ public abstract class CVariable extends CDebugElement implements IVariable, ICDIEventListener { + /** + * The parent object this variable is contained in. + */ + private CDebugElement fParent; + + /** + * The underlying CDI variable. + */ + private ICDIVariable fCDIVariable; + /** * Cache of current value - see #getValue(). */ @@ -49,9 +64,11 @@ public abstract class CVariable extends CDebugElement * Constructor for CVariable. * @param target */ - public CVariable( CDebugTarget target ) + public CVariable( CDebugElement parent, ICDIVariable cdiVariable ) { - super( target ); + super( (CDebugTarget)parent.getDebugTarget() ); + fParent = parent; + fCDIVariable = cdiVariable; getCDISession().getEventManager().addEventListener( this ); } @@ -120,11 +137,6 @@ public abstract class CVariable extends CDebugElement return false; } - /** - * Returns this variable's underlying CDI value. - */ - protected abstract ICDIValue retrieveValue() throws DebugException, CDIException; - /* (non-Javadoc) * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) */ @@ -214,4 +226,107 @@ public abstract class CVariable extends CDebugElement } } } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvent(ICDIEvent) + */ + public void handleDebugEvent( ICDIEvent event ) + { + ICDIObject source = event.getSource(); + if (source == null) + return; + + if ( source.getTarget().equals( getCDITarget() ) ) + { + if ( event instanceof ICDIChangedEvent ) + { + if ( source instanceof ICDIVariable && source.equals( getCDIVariable() ) ) + { + handleChangedEvent( (ICDIChangedEvent)event ); + } + } + } + } + + private void handleChangedEvent( ICDIChangedEvent event ) + { + try + { + //setValue( getCurrentValue() ); + setChanged( true ); + getParent().fireChangeEvent( DebugEvent.CONTENT ); + } + catch( DebugException e ) + { + logError( e ); + } + } + + /** + * Returns the stack frame this variable is contained in. + * + * @return the stack frame + */ + protected CDebugElement getParent() + { + return fParent; + } + + /** + * Returns the underlying CDI variable. + * + * @return the underlying CDI variable + */ + protected ICDIVariable getCDIVariable() + { + return fCDIVariable; + } + + protected void setCDIVariable( ICDIVariable newVar ) + { + fCDIVariable = newVar; + } + + /** + * Returns this variable's underlying CDI value. + */ + protected ICDIValue retrieveValue() throws DebugException, CDIException + { + return ( ((IDebugTarget)getParent().getDebugTarget()).isSuspended() ) ? + getCDIVariable().getValue() : getLastKnownValue(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.model.IVariable#getName() + */ + public String getName() throws DebugException + { + String name = null; + try + { + name = getCDIVariable().getName(); + } + catch( CDIException e ) + { + targetRequestFailed( e.getMessage(), null ); + } + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName() + */ + public String getReferenceTypeName() throws DebugException + { + String type = null; + try + { + type = getCDIVariable().getTypeName(); + } + catch( CDIException e ) + { + targetRequestFailed( e.getMessage(), null ); + } + return type; + } }