mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-28 18:53:20 +02:00
Refactoring: moved some methods from CLocalVariable to CVariable and CModificationVariable.
This commit is contained in:
parent
074c939b24
commit
3f63758501
5 changed files with 179 additions and 162 deletions
|
@ -18,7 +18,7 @@ import org.eclipse.debug.core.DebugException;
|
||||||
*
|
*
|
||||||
* @since Sep 9, 2002
|
* @since Sep 9, 2002
|
||||||
*/
|
*/
|
||||||
public class CArrayEntryVariable extends CLocalVariable
|
public class CArrayEntryVariable extends CModificationVariable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The index of the variable entry.
|
* The index of the variable entry.
|
||||||
|
@ -34,9 +34,9 @@ public class CArrayEntryVariable extends CLocalVariable
|
||||||
* Constructor for CArrayEntryVariable.
|
* Constructor for CArrayEntryVariable.
|
||||||
* @param target
|
* @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;
|
fIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,9 @@ public class CArrayPartition extends CVariable
|
||||||
* Constructor for CArrayPartition.
|
* Constructor for CArrayPartition.
|
||||||
* @param target
|
* @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;
|
fStart = start;
|
||||||
fEnd = end;
|
fEnd = end;
|
||||||
fCDIVariables = cdiVariables;
|
fCDIVariables = cdiVariables;
|
||||||
|
|
|
@ -26,155 +26,13 @@ import org.eclipse.debug.core.model.IValue;
|
||||||
* @since Aug 9, 2002
|
* @since Aug 9, 2002
|
||||||
*/
|
*/
|
||||||
public class CLocalVariable extends CModificationVariable
|
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.
|
* Constructor for CLocalVariable.
|
||||||
* @param target
|
* @param target
|
||||||
*/
|
*/
|
||||||
public CLocalVariable( CDebugElement parent, ICDIVariable cdiVariable )
|
public CLocalVariable( CDebugElement parent, ICDIVariable cdiVariable )
|
||||||
{
|
{
|
||||||
super( (CDebugTarget)parent.getDebugTarget() );
|
super( parent, cdiVariable );
|
||||||
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() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.eclipse.cdt.debug.internal.core.model;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
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.CDIException;
|
||||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIArrayValue;
|
import org.eclipse.cdt.debug.core.cdi.model.ICDIArrayValue;
|
||||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
|
import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
|
||||||
|
@ -31,11 +32,12 @@ public abstract class CModificationVariable extends CVariable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for CModificationVariable.
|
* 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)
|
/* (non-Javadoc)
|
||||||
|
@ -81,15 +83,17 @@ public abstract class CModificationVariable extends CVariable
|
||||||
*/
|
*/
|
||||||
public final void setValue( String expression ) throws DebugException
|
public final void setValue( String expression ) throws DebugException
|
||||||
{
|
{
|
||||||
|
String newExpression = processExpression( expression );
|
||||||
ICDIVariable cdiVariable = getCDIVariable();
|
ICDIVariable cdiVariable = getCDIVariable();
|
||||||
if ( cdiVariable == null )
|
if ( cdiVariable == null )
|
||||||
{
|
{
|
||||||
logError( "Error in IValueModification#setValue: no cdi variable." );
|
logError( "Error in IValueModification#setValue: no cdi variable." );
|
||||||
requestFailed( "Unable to set value.", null );
|
requestFailed( "Unable to set value.", null );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cdiVariable.setValue( expression );
|
cdiVariable.setValue( newExpression );
|
||||||
}
|
}
|
||||||
catch( CDIException e )
|
catch( CDIException e )
|
||||||
{
|
{
|
||||||
|
@ -100,7 +104,47 @@ public abstract class CModificationVariable extends CVariable
|
||||||
/**
|
/**
|
||||||
* Set this variable's value to the given value
|
* 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,17 @@ package org.eclipse.cdt.debug.internal.core.model;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
|
||||||
import org.eclipse.cdt.debug.core.ICValue;
|
import org.eclipse.cdt.debug.core.ICValue;
|
||||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
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.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.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.DebugException;
|
||||||
|
import org.eclipse.debug.core.model.IDebugTarget;
|
||||||
import org.eclipse.debug.core.model.IValue;
|
import org.eclipse.debug.core.model.IValue;
|
||||||
import org.eclipse.debug.core.model.IVariable;
|
import org.eclipse.debug.core.model.IVariable;
|
||||||
|
|
||||||
|
@ -26,6 +31,16 @@ public abstract class CVariable extends CDebugElement
|
||||||
implements IVariable,
|
implements IVariable,
|
||||||
ICDIEventListener
|
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().
|
* Cache of current value - see #getValue().
|
||||||
*/
|
*/
|
||||||
|
@ -49,9 +64,11 @@ public abstract class CVariable extends CDebugElement
|
||||||
* Constructor for CVariable.
|
* Constructor for CVariable.
|
||||||
* @param target
|
* @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 );
|
getCDISession().getEventManager().addEventListener( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,11 +137,6 @@ public abstract class CVariable extends CDebugElement
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns this variable's underlying CDI value.
|
|
||||||
*/
|
|
||||||
protected abstract ICDIValue retrieveValue() throws DebugException, CDIException;
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
|
* @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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue