mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Core support of the "Cast To Type" and "Restore Default Type" actions.
This commit is contained in:
parent
5c9351fc25
commit
d32a10f776
5 changed files with 217 additions and 14 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2003-03-09 Mikhail Khodjaiants
|
||||||
|
Core support of the "Cast To Type" and "Restore Default Type" actions.
|
||||||
|
* ICastToType.java: new
|
||||||
|
* CLocalVariable.java
|
||||||
|
* CStackFrame.java
|
||||||
|
* CVariable.java
|
||||||
|
|
||||||
2003-02-24 Alain Magloire
|
2003-02-24 Alain Magloire
|
||||||
|
|
||||||
* src/org/eclipse/cdt/debug/core/cdi/ICDIRegisterObject.java:
|
* src/org/eclipse/cdt/debug/core/cdi/ICDIRegisterObject.java:
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.debug.core.model;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter type comment.
|
||||||
|
*
|
||||||
|
* @since Mar 7, 2003
|
||||||
|
*/
|
||||||
|
public interface ICastToType extends IAdaptable
|
||||||
|
{
|
||||||
|
boolean supportsCasting();
|
||||||
|
|
||||||
|
String getCurrentType();
|
||||||
|
|
||||||
|
void cast( String type ) throws DebugException;
|
||||||
|
|
||||||
|
void restoreDefault() throws DebugException;
|
||||||
|
|
||||||
|
boolean isCasted();
|
||||||
|
}
|
|
@ -6,6 +6,9 @@
|
||||||
package org.eclipse.cdt.debug.internal.core.model;
|
package org.eclipse.cdt.debug.internal.core.model;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
|
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
|
||||||
|
import org.eclipse.cdt.debug.core.model.ICValue;
|
||||||
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
import org.eclipse.debug.core.model.IValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -15,12 +18,36 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
|
||||||
*/
|
*/
|
||||||
public class CLocalVariable extends CModificationVariable
|
public class CLocalVariable extends CModificationVariable
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Constructor for CLocalVariable.
|
|
||||||
* @param target
|
|
||||||
*/
|
|
||||||
public CLocalVariable( CDebugElement parent, ICDIVariable cdiVariable )
|
public CLocalVariable( CDebugElement parent, ICDIVariable cdiVariable )
|
||||||
{
|
{
|
||||||
super( parent, cdiVariable );
|
super( parent, cdiVariable );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.debug.core.model.ICastToType#supportsCasting()
|
||||||
|
*/
|
||||||
|
public boolean supportsCasting()
|
||||||
|
{
|
||||||
|
boolean enabled = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IValue value = getValue();
|
||||||
|
if ( value instanceof ICValue )
|
||||||
|
{
|
||||||
|
switch( ((ICValue)value).getType() )
|
||||||
|
{
|
||||||
|
case ICValue.TYPE_SIMPLE:
|
||||||
|
case ICValue.TYPE_POINTER:
|
||||||
|
case ICValue.TYPE_CHAR:
|
||||||
|
enabled = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( DebugException e )
|
||||||
|
{
|
||||||
|
logError( e );
|
||||||
|
}
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ public class CStackFrame extends CDebugElement
|
||||||
while( index < fVariables.size() )
|
while( index < fVariables.size() )
|
||||||
{
|
{
|
||||||
CLocalVariable local = (CLocalVariable)fVariables.get( index );
|
CLocalVariable local = (CLocalVariable)fVariables.get( index );
|
||||||
ICDIVariable var = findVariable( locals, local.getCDIVariable() );
|
ICDIVariable var = findVariable( locals, local.getOriginalCDIVariable() );
|
||||||
if ( var != null )
|
if ( var != null )
|
||||||
{
|
{
|
||||||
locals.remove( var );
|
locals.remove( var );
|
||||||
|
@ -684,7 +684,7 @@ public class CStackFrame extends CDebugElement
|
||||||
for ( int i = 0; i < vars.length; ++i )
|
for ( int i = 0; i < vars.length; ++i )
|
||||||
{
|
{
|
||||||
if ( vars[i] instanceof CLocalVariable &&
|
if ( vars[i] instanceof CLocalVariable &&
|
||||||
((CLocalVariable)vars[i]).getCDIVariable() instanceof ICDIArgument )
|
((CLocalVariable)vars[i]).getOriginalCDIVariable() instanceof ICDIArgument )
|
||||||
{
|
{
|
||||||
list.add( vars[i] );
|
list.add( vars[i] );
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,16 +5,21 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.debug.internal.core.model;
|
package org.eclipse.cdt.debug.internal.core.model;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||||
import org.eclipse.cdt.debug.core.cdi.ICDIFormat;
|
import org.eclipse.cdt.debug.core.cdi.ICDIFormat;
|
||||||
import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent;
|
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.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.ICDIExpression;
|
||||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIObject;
|
import org.eclipse.cdt.debug.core.cdi.model.ICDIObject;
|
||||||
|
import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame;
|
||||||
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.cdt.debug.core.cdi.model.ICDIVariable;
|
||||||
import org.eclipse.cdt.debug.core.model.ICValue;
|
import org.eclipse.cdt.debug.core.model.ICValue;
|
||||||
import org.eclipse.cdt.debug.core.model.ICVariable;
|
import org.eclipse.cdt.debug.core.model.ICVariable;
|
||||||
|
import org.eclipse.cdt.debug.core.model.ICastToType;
|
||||||
import org.eclipse.debug.core.DebugEvent;
|
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.IDebugTarget;
|
||||||
|
@ -29,7 +34,8 @@ import org.eclipse.debug.core.model.IVariable;
|
||||||
*/
|
*/
|
||||||
public abstract class CVariable extends CDebugElement
|
public abstract class CVariable extends CDebugElement
|
||||||
implements ICVariable,
|
implements ICVariable,
|
||||||
ICDIEventListener
|
ICDIEventListener,
|
||||||
|
ICastToType
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The parent object this variable is contained in.
|
* The parent object this variable is contained in.
|
||||||
|
@ -41,6 +47,11 @@ public abstract class CVariable extends CDebugElement
|
||||||
*/
|
*/
|
||||||
private ICDIVariable fCDIVariable;
|
private ICDIVariable fCDIVariable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The shadow CDI variable used for casting.
|
||||||
|
*/
|
||||||
|
private ICDIVariable fShadow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache of current value - see #getValue().
|
* Cache of current value - see #getValue().
|
||||||
*/
|
*/
|
||||||
|
@ -79,6 +90,7 @@ public abstract class CVariable extends CDebugElement
|
||||||
super( (CDebugTarget)parent.getDebugTarget() );
|
super( (CDebugTarget)parent.getDebugTarget() );
|
||||||
fParent = parent;
|
fParent = parent;
|
||||||
fCDIVariable = cdiVariable;
|
fCDIVariable = cdiVariable;
|
||||||
|
fShadow = null;
|
||||||
getCDISession().getEventManager().addEventListener( this );
|
getCDISession().getEventManager().addEventListener( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,6 +170,8 @@ public abstract class CVariable extends CDebugElement
|
||||||
*/
|
*/
|
||||||
public Object getAdapter( Class adapter )
|
public Object getAdapter( Class adapter )
|
||||||
{
|
{
|
||||||
|
if ( adapter.equals( ICastToType.class ) )
|
||||||
|
return this;
|
||||||
if ( adapter.equals( IVariable.class ) )
|
if ( adapter.equals( IVariable.class ) )
|
||||||
return this;
|
return this;
|
||||||
if ( adapter.equals( ICVariable.class ) )
|
if ( adapter.equals( ICVariable.class ) )
|
||||||
|
@ -229,6 +243,15 @@ public abstract class CVariable extends CDebugElement
|
||||||
((CValue)fValue).dispose();
|
((CValue)fValue).dispose();
|
||||||
}
|
}
|
||||||
getCDISession().getEventManager().removeEventListener( this );
|
getCDISession().getEventManager().removeEventListener( this );
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if ( getShadow() != null )
|
||||||
|
destroyShadow( getShadow() );
|
||||||
|
}
|
||||||
|
catch( DebugException e )
|
||||||
|
{
|
||||||
|
logError( e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void setChanged( boolean changed ) throws DebugException
|
protected synchronized void setChanged( boolean changed ) throws DebugException
|
||||||
|
@ -300,12 +323,9 @@ public abstract class CVariable extends CDebugElement
|
||||||
*/
|
*/
|
||||||
protected ICDIVariable getCDIVariable()
|
protected ICDIVariable getCDIVariable()
|
||||||
{
|
{
|
||||||
return fCDIVariable;
|
if ( fShadow != null )
|
||||||
}
|
return fShadow;
|
||||||
|
return getOriginalCDIVariable();
|
||||||
protected void setCDIVariable( ICDIVariable newVar )
|
|
||||||
{
|
|
||||||
fCDIVariable = newVar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -325,7 +345,7 @@ public abstract class CVariable extends CDebugElement
|
||||||
String name = null;
|
String name = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
name = getCDIVariable().getName();
|
name = getOriginalCDIVariable().getName();
|
||||||
}
|
}
|
||||||
catch( CDIException e )
|
catch( CDIException e )
|
||||||
{
|
{
|
||||||
|
@ -391,4 +411,125 @@ public abstract class CVariable extends CDebugElement
|
||||||
((ICValue)getValue()).setChanged( true );
|
((ICValue)getValue()).setChanged( true );
|
||||||
fireChangeEvent( DebugEvent.STATE );
|
fireChangeEvent( DebugEvent.STATE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.debug.core.model.ICastToType#cast(java.lang.String)
|
||||||
|
*/
|
||||||
|
public void cast( String type ) throws DebugException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String newName = MessageFormat.format( "({0})({1})", new String[] { type, getOriginalCDIVariable().getName() } );
|
||||||
|
ICDIVariable newVar = createShadow( getOriginalCDIVariable().getStackFrame(), newName );
|
||||||
|
ICDIVariable oldVar = getShadow();
|
||||||
|
setShadow( newVar );
|
||||||
|
if ( oldVar != null )
|
||||||
|
destroyShadow( oldVar );
|
||||||
|
}
|
||||||
|
catch( CDIException e )
|
||||||
|
{
|
||||||
|
targetRequestFailed( e.getMessage(), null );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if ( fValue != null )
|
||||||
|
{
|
||||||
|
((CValue)fValue).dispose();
|
||||||
|
fValue = null;
|
||||||
|
}
|
||||||
|
fireChangeEvent( DebugEvent.STATE );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.debug.core.model.ICastToType#getCurrentType()
|
||||||
|
*/
|
||||||
|
public String getCurrentType()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return getReferenceTypeName();
|
||||||
|
}
|
||||||
|
catch( DebugException e )
|
||||||
|
{
|
||||||
|
logError( e );
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.debug.core.model.ICastToType#restoreDefault()
|
||||||
|
*/
|
||||||
|
public void restoreDefault() throws DebugException
|
||||||
|
{
|
||||||
|
ICDIVariable oldVar = getShadow();
|
||||||
|
setShadow( null );
|
||||||
|
if ( oldVar != null )
|
||||||
|
destroyShadow( oldVar );
|
||||||
|
if ( fValue != null )
|
||||||
|
{
|
||||||
|
((CValue)fValue).dispose();
|
||||||
|
fValue = null;
|
||||||
|
}
|
||||||
|
fireChangeEvent( DebugEvent.STATE );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.debug.core.model.ICastToType#supportsCasting()
|
||||||
|
*/
|
||||||
|
public boolean supportsCasting()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ICDIVariable getOriginalCDIVariable()
|
||||||
|
{
|
||||||
|
return fCDIVariable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ICDIVariable getShadow()
|
||||||
|
{
|
||||||
|
return fShadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setShadow( ICDIVariable shadow )
|
||||||
|
{
|
||||||
|
fShadow = shadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ICDIVariable createShadow( ICDIStackFrame cdiFrame, String expression ) throws DebugException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// ICDIVariableObject varObject = getCDISession().getVariableManager().getVariableObject( getCDIVariable().getStackFrame(), newName );
|
||||||
|
// return getCDISession().getVariableManager().createVariable( varObject );
|
||||||
|
return getCDISession().getExpressionManager().createExpression( expression );
|
||||||
|
}
|
||||||
|
catch( CDIException e )
|
||||||
|
{
|
||||||
|
targetRequestFailed( e.getMessage(), null );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroyShadow( ICDIVariable shadow ) throws DebugException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// getCDISession().getVariableManager().destroyVariable( shadow );
|
||||||
|
getCDISession().getExpressionManager().destroyExpression( (ICDIExpression)shadow );
|
||||||
|
}
|
||||||
|
catch( CDIException e )
|
||||||
|
{
|
||||||
|
targetRequestFailed( e.getMessage(), null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.debug.core.model.ICastToType#isCasted()
|
||||||
|
*/
|
||||||
|
public boolean isCasted()
|
||||||
|
{
|
||||||
|
return ( getShadow() != null );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue