diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog
index 30489b3d24f..273b8dde243 100644
--- a/debug/org.eclipse.cdt.debug.core/ChangeLog
+++ b/debug/org.eclipse.cdt.debug.core/ChangeLog
@@ -1,3 +1,33 @@
+2004-08-04 Mikhail Khodjaiants
+ New implementation of the variable types.
+ * CDIDebugModel.java
+ * CVariableFormat.java: new
+ * ICastToArray.java
+ * ICastToType.java
+ * ICGlobalVariable.java
+ * ICType.java
+ * ICValue.java
+ * ICVariable.java
+ * IFormatSupport.java: new
+ * CGlobalVariableManager.java
+ * CoreModelMessages.properties
+ * AbstractCValue.java: new
+ * AbstractCVariable.java: new
+ * CArrayPartition.java
+ * CArrayPartitionValue.java
+ * CDebugTarget.java
+ * CExpression.java
+ * CGlobalVariable.java
+ * CRegister.java
+ * CRegisterGroup.java
+ * CStackFrame.java
+ * CType.java
+ * CValue.java
+ * CValueFactory.java
+ * CVariable.java
+ * CVariableFactory.java: new
+ * CModificationVariable: deleted
+
2004-07-23 Mikhail Khodjaiants
Marked the expression creation methods as deprecated in CDebugModel.
* CDebugModel.java
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java
index 4160da74e1a..3d626b290f8 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java
@@ -12,7 +12,6 @@ package org.eclipse.cdt.debug.core;
import java.text.MessageFormat;
import java.util.HashMap;
-
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration;
import org.eclipse.cdt.debug.core.cdi.ICDILocation;
@@ -39,7 +38,7 @@ import org.eclipse.cdt.debug.internal.core.breakpoints.CWatchpoint;
import org.eclipse.cdt.debug.internal.core.model.CCoreFileDebugTarget;
import org.eclipse.cdt.debug.internal.core.model.CDebugTarget;
import org.eclipse.cdt.debug.internal.core.model.CExpression;
-import org.eclipse.cdt.debug.internal.core.model.CGlobalVariable;
+import org.eclipse.cdt.debug.internal.core.model.CVariableFactory;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
@@ -543,8 +542,7 @@ public class CDIDebugModel {
ICDIVariableObject vo = null;
try {
vo = ((CDebugTarget)target).getCDISession().getVariableManager().getGlobalVariableObject( info.getPath().lastSegment(), null, info.getName() );
- ICDIVariable cdiVariable = ((CDebugTarget)target).getCDISession().getVariableManager().createVariable( vo );
- return new CGlobalVariable( (CDebugTarget)target, cdiVariable );
+ return CVariableFactory.createGlobalVariable( (CDebugTarget)target, vo );
}
catch( CDIException e ) {
throw new DebugException( new Status( IStatus.ERROR, getPluginIdentifier(), DebugException.TARGET_REQUEST_FAILED, (vo != null) ? vo.getName() + ": " + e.getMessage() : e.getMessage(), null ) ); //$NON-NLS-1$
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/CVariableFormat.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/CVariableFormat.java
new file mode 100644
index 00000000000..736cedee60c
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/CVariableFormat.java
@@ -0,0 +1,50 @@
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.core.model;
+
+/**
+ * Defines the variable format types.
+ */
+public class CVariableFormat {
+
+ private final String fName;
+
+ private CVariableFormat( String name ) {
+ this.fName = name;
+ }
+
+ public String toString() {
+ return this.fName;
+ }
+
+ public static CVariableFormat getFormat( int code ) {
+ switch( code ) {
+ case 0:
+ return NATURAL;
+ case 1:
+ return DECIMAL;
+ case 2:
+ return BINARY;
+ case 3:
+ return OCTAL;
+ case 4:
+ return HEXADECIMAL;
+ default:
+ return NATURAL;
+ }
+ }
+
+ public static final CVariableFormat NATURAL = new CVariableFormat( "natural" ); //$NON-NLS-1$
+ public static final CVariableFormat DECIMAL = new CVariableFormat( "decimal" ); //$NON-NLS-1$
+ public static final CVariableFormat BINARY = new CVariableFormat( "binary" ); //$NON-NLS-1$
+ public static final CVariableFormat OCTAL = new CVariableFormat( "octal" ); //$NON-NLS-1$
+ public static final CVariableFormat HEXADECIMAL = new CVariableFormat( "hexadecimal" ); //$NON-NLS-1$
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICGlobalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICGlobalVariable.java
index db5d740b271..e8ca791a421 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICGlobalVariable.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICGlobalVariable.java
@@ -14,5 +14,4 @@ package org.eclipse.cdt.debug.core.model;
* Represents a global C/C++ variable.
*/
public interface ICGlobalVariable extends ICVariable {
- public void dispose();
}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICType.java
index c8037235131..ec9114da9ed 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICType.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICType.java
@@ -8,33 +8,75 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.debug.core.model;
-import org.eclipse.core.runtime.IAdaptable;
-
/**
- * Enter type comment.
- *
- * @since Jun 10, 2003
+ * Represents a type of a varibale.
+ * Used by the UI responsible components for variable rendering.
*/
-public interface ICType extends IAdaptable
-{
+public interface ICType {
+
+ /**
+ * Returns the name of this type.
+ *
+ * @return the name of this type
+ */
String getName();
-
+
+ /**
+ * Returns whether this is an array type.
+ *
+ * @return whether this is an array type
+ */
boolean isArray();
+ /**
+ * Returns the array dimensions for array types,
+ * otherwise returns an empty array.
+ *
+ * @return the array dimensions
+ */
int[] getArrayDimensions();
+ /**
+ * Returns whether this is a structure or a class type.
+ *
+ * @return whether this is a structure or a class type
+ */
boolean isStructure();
+ /**
+ * Returns whether this is a character type.
+ *
+ * @return whether this is a character type
+ */
boolean isCharacter();
+ /**
+ * Returns whether this is a floating point type.
+ *
+ * @return whether this is a floating point type
+ */
boolean isFloatingPointType();
+ /**
+ * Returns whether this is a pointer type.
+ *
+ * @return whether this is a pointer type
+ */
boolean isPointer();
+ /**
+ * Returns whether this is a reference type.
+ *
+ * @return whether this is a reference type
+ */
boolean isReference();
- void dispose();
-}
+ /**
+ * Returns whether this is an unsigned type.
+ *
+ * @return whether this is an unsigned type
+ */
+ boolean isUnsigned();
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICValue.java
index eb94045b81c..0f6bb667d7c 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICValue.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICValue.java
@@ -8,20 +8,14 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.debug.core.model;
import org.eclipse.debug.core.model.IValue;
/**
- *
- * Extends the IValue interface by C/C++ specific functionality.
- *
- * @since Sep 9, 2002
+ * Extends the IValue interface by C/C++ specific functionality.
*/
-public interface ICValue extends IValue
-{
- String evaluateAsExpression();
+public interface ICValue extends IValue, ICDebugElement {
- void dispose();
-}
+ String evaluateAsExpression();
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java
index 6a2ebd4b513..13a39d20ada 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java
@@ -11,31 +11,48 @@
package org.eclipse.cdt.debug.core.model;
import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IValueModification;
import org.eclipse.debug.core.model.IVariable;
/**
- *
- * Enter type comment.
- *
- * @since Dec 15, 2002
+ * C/C++ specific extension IVariable
.
*/
-public interface ICVariable extends IVariable
-{
- int getFormat();
-
- void setFormat( int format ) throws DebugException;
-
- ICType getType() throws DebugException;
-
- boolean isEditable();
-
- boolean hasChildren();
+public interface ICVariable extends IVariable, ICDebugElement, IFormatSupport, ICastToArray, IValueModification {
+ /**
+ * Returns the type of this variable.
+ *
+ * @return the type of this variable
+ * @throws DebugException
+ */
+ ICType getType() throws DebugException;
+
+ /**
+ * Returns whether this variable is enabled.
+ *
+ * @return whether this variable is enabled
+ */
boolean isEnabled();
+ /**
+ * Sets the enabled state of this action.
+ *
+ * @param enabled true
to enable, and false
to disable
+ * @throws DebugException
+ */
void setEnabled( boolean enabled ) throws DebugException;
+ /**
+ * Returns whether this variable supports enable/disable operation.
+ *
+ * @return whether this variable supports enable/disable operation
+ */
boolean canEnableDisable();
+ /**
+ * Returns whether this variable is an argument.
+ *
+ * @return whether this variable is an argument
+ */
boolean isArgument();
-}
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICastToArray.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICastToArray.java
index 2f215ed4faf..e9ffaae9d1e 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICastToArray.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICastToArray.java
@@ -8,19 +8,29 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.debug.core.model;
import org.eclipse.debug.core.DebugException;
/**
- * Enter type comment.
- *
- * @since Mar 10, 2003
+ * Provides the ability to present a variable as an array of the same type.
*/
-public interface ICastToArray extends ICastToType
-{
- boolean supportsCastToArray();
+public interface ICastToArray extends ICastToType {
+ /**
+ * Returns whether this element can be currently casted to array.
+ *
+ * @return whether this element can be currently casted to array
+ */
+ boolean canCastToArray();
+
+ /**
+ * Performs the casting. The element is transformed to the array of the same type.
+ *
+ * @param startIndex the index of the first element of the array. 0 means that
+ * the original element is the first member of the array.
+ * @param length tha array size
+ * @throws DebugException
+ */
void castToArray( int startIndex, int length ) throws DebugException;
-}
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICastToType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICastToType.java
index 3c5a4b25a04..05907b1f464 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICastToType.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICastToType.java
@@ -8,26 +8,49 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
-
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
+ * Provides the ability to cast a variable to the given type.
*/
-public interface ICastToType extends IAdaptable
-{
- boolean supportsCasting();
-
+public interface ICastToType extends IAdaptable {
+
+ /**
+ * Returns whether this element can currently be casted.
+ *
+ * @return whether this element can currently be casted
+ */
+ boolean canCast();
+
+ /**
+ * Returns the string presentation of the current type.
+ *
+ * @return the string presentation of the current type
+ */
String getCurrentType();
-
+
+ /**
+ * Performs the casting to the given type.
+ *
+ * @param type a type to cast to.
+ * @throws DebugException
+ */
void cast( String type ) throws DebugException;
-
- void restoreDefault() throws DebugException;
-
+
+ /**
+ * Restores the original type.
+ *
+ * @throws DebugException
+ */
+ void restoreOriginal() throws DebugException;
+
+ /**
+ * Returns whether this element is casted.
+ *
+ * @return whether this element is casted
+ */
boolean isCasted();
-}
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IFormatSupport.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IFormatSupport.java
new file mode 100644
index 00000000000..9dbfac9a4f1
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IFormatSupport.java
@@ -0,0 +1,41 @@
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.core.model;
+
+import org.eclipse.debug.core.DebugException;
+
+/**
+ * Provides the ability to set and get the format of a variable.
+ */
+public interface IFormatSupport {
+
+ /**
+ * Returns whether this variable supports formatting operations.
+ *
+ * @return whether this variable supports formatting operations
+ */
+ boolean supportsFormatting();
+
+ /**
+ * Returns the current format of this variable.
+ *
+ * @return the current format of this variable
+ */
+ CVariableFormat getFormat();
+
+ /**
+ * Sets the current format of this variable to format
.
+ *
+ * @param format the new format type
+ * @throws DebugException if this method fails.
+ */
+ void changeFormat( CVariableFormat format ) throws DebugException;
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CGlobalVariableManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CGlobalVariableManager.java
index b3aee134f6a..18a6555ce49 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CGlobalVariableManager.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CGlobalVariableManager.java
@@ -86,7 +86,8 @@ public class CGlobalVariableManager implements ICGlobalVariableManager {
fGlobals.removeAll( Arrays.asList( globals ) );
}
for ( int i = 0; i < globals.length; ++i ) {
- globals[i].dispose();
+ if ( globals[i] instanceof CVariable )
+ ((CVariable)globals[i]).dispose();
}
getDebugTarget().fireChangeEvent( DebugEvent.CONTENT );
}
@@ -101,7 +102,8 @@ public class CGlobalVariableManager implements ICGlobalVariableManager {
fGlobals.clear();
}
for ( int i = 0; i < globals.length; ++i ) {
- ((CVariable)globals[i]).dispose();
+ if ( globals[i] instanceof CVariable )
+ ((CVariable)globals[i]).dispose();
}
getDebugTarget().fireChangeEvent( DebugEvent.CONTENT );
}
@@ -109,7 +111,7 @@ public class CGlobalVariableManager implements ICGlobalVariableManager {
public void dispose() {
Iterator it = fGlobals.iterator();
while( it.hasNext() ) {
- ((ICGlobalVariable)it.next()).dispose();
+ ((CVariable)it.next()).dispose();
}
fGlobals.clear();
}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCValue.java
new file mode 100644
index 00000000000..4b7803b6b10
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCValue.java
@@ -0,0 +1,28 @@
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.internal.core.model;
+
+import org.eclipse.cdt.debug.core.model.ICValue;
+
+/**
+ * The abstract super class for the C/C++ value types.
+ */
+public abstract class AbstractCValue extends CDebugElement implements ICValue {
+
+ /**
+ * Constructor for AbstractCValue.
+ */
+ public AbstractCValue( CDebugTarget target ) {
+ super( target );
+ }
+
+ abstract public void dispose();
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java
new file mode 100644
index 00000000000..365a130e158
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java
@@ -0,0 +1,37 @@
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.internal.core.model;
+
+import org.eclipse.cdt.debug.core.model.ICVariable;
+import org.eclipse.debug.core.DebugException;
+
+/**
+ * The super class for all variable types.
+ */
+public abstract class AbstractCVariable extends CDebugElement implements ICVariable {
+
+ /**
+ * Constructor for AbstractCVariable.
+ */
+ public AbstractCVariable( CDebugTarget target ) {
+ super( target );
+ }
+
+ /**
+ * Returns the text presentation of this variable as an expression.
+ *
+ * @return the text presentation of this variable as an expression
+ * @throws DebugException
+ */
+ public abstract String getExpressionString() throws DebugException;
+
+ public abstract void dispose();
+}
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 d034e686f38..4d405d0f4bf 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
@@ -1,75 +1,119 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 QNX Software Systems and others.
- * All rights reserved. This program and the accompanying materials
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
- *
+ *
* Contributors:
- * QNX Software Systems - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.cdt.debug.internal.core.model;
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.internal.core.model;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException;
-import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent;
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.ICDIVariableObject;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue;
+import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.cdt.debug.core.model.ICType;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
/**
- *
* A sub-range of an array.
- *
- * @since Sep 9, 2002
*/
-public class CArrayPartition extends CVariable
-{
+public class CArrayPartition extends AbstractCVariable {
+
static final protected int SLOT_SIZE = 100;
private int fStart;
+
private int fEnd;
+
private ICDIVariableObject fCDIVariableObject;
+
private ICDIVariable fCDIVariable;
+
private ICType fType = null;
+
private String fQualifiedName = null;
/**
- * Cache of value.
+ * Cached value.
*/
private CArrayPartitionValue fArrayPartitionValue = null;
- /**
- * Constructor for CArrayPartition.
- * @param target
+ /**
+ * Constructor for CArrayPartition.
*/
- public CArrayPartition( CDebugElement parent, ICDIVariable cdiVariable, int start, int end )
- {
- super( parent, null );
+ private CArrayPartition( CDebugElement parent, ICDIVariable cdiVariable, int start, int end ) {
+ super( (CDebugTarget)parent.getDebugTarget() );
fStart = start;
fEnd = end;
fCDIVariable = cdiVariable;
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.debug.internal.core.model.CVariable#retrieveValue()
+ * @see org.eclipse.cdt.debug.core.model.ICVariable#getType()
*/
- protected ICDIValue retrieveValue() throws DebugException, CDIException
- {
- return null;
+ public ICType getType() throws DebugException {
+ if ( fType == null ) {
+ try {
+ ICDIVariableObject varObject = getVariableObject();
+ if ( varObject != null )
+ fType = new CType( varObject.getType() );
+ }
+ catch( CDIException e ) {
+ requestFailed( CoreModelMessages.getString( "CArrayPartition.0" ), e ); //$NON-NLS-1$
+ }
+ }
+ return fType;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled()
+ */
+ public boolean isEnabled() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICVariable#setEnabled(boolean)
+ */
+ public void setEnabled( boolean enabled ) throws DebugException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable()
+ */
+ public boolean canEnableDisable() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICVariable#isArgument()
+ */
+ public boolean isArgument() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IVariable#getValue()
+ */
+ public IValue getValue() throws DebugException {
+ if ( fArrayPartitionValue == null ) {
+ fArrayPartitionValue = CValueFactory.createArrayValue( this, getCDIVariable(), getStart(), getEnd() );
+ }
+ return fArrayPartitionValue;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getName()
*/
- public String getName() throws DebugException
- {
+ public String getName() throws DebugException {
StringBuffer name = new StringBuffer();
name.append( '[' );
name.append( fStart );
@@ -82,63 +126,160 @@ public class CArrayPartition extends CVariable
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
*/
- public String getReferenceTypeName() throws DebugException
- {
+ public String getReferenceTypeName() throws DebugException {
+ ICType type = getType();
+ return ( type != null ) ? type.getName() : null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
+ */
+ public boolean hasValueChanged() throws DebugException {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.IFormatSupport#supportsFormatting()
+ */
+ public boolean supportsFormatting() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.IFormatSupport#getFormat()
+ */
+ public CVariableFormat getFormat() {
return null;
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(ICDIEvent)
+ * @see org.eclipse.cdt.debug.core.model.IFormatSupport#changeFormat(org.eclipse.cdt.debug.core.model.CVariableFormat)
*/
- public void handleDebugEvents( ICDIEvent[] events )
- {
+ public void changeFormat( CVariableFormat format ) throws DebugException {
}
/* (non-Javadoc)
- * @see org.eclipse.debug.core.model.IVariable#getValue()
+ * @see org.eclipse.cdt.debug.core.model.ICastToArray#canCastToArray()
*/
- public IValue getValue() throws DebugException
- {
- if ( fArrayPartitionValue == null )
- {
- fArrayPartitionValue = new CArrayPartitionValue( this, fCDIVariable, getStart(), getEnd() );
- }
- return fArrayPartitionValue;
+ public boolean canCastToArray() {
+ return false;
}
- static public List splitArray( CDebugElement parent, ICDIVariable cdiVariable, int start, int end ) throws DebugException
- {
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICastToArray#castToArray(int, int)
+ */
+ public void castToArray( int startIndex, int length ) throws DebugException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
+ */
+ public void setValue( String expression ) throws DebugException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
+ */
+ public void setValue( IValue value ) throws DebugException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
+ */
+ public boolean supportsValueModification() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
+ */
+ public boolean verifyValue( String expression ) throws DebugException {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
+ */
+ public boolean verifyValue( IValue value ) throws DebugException {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICastToType#canCast()
+ */
+ public boolean canCast() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICastToType#getCurrentType()
+ */
+ public String getCurrentType() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICastToType#cast(java.lang.String)
+ */
+ public void cast( String type ) throws DebugException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICastToType#restoreOriginal()
+ */
+ public void restoreOriginal() throws DebugException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICastToType#isCasted()
+ */
+ public boolean isCasted() {
+ return false;
+ }
+
+ private ICDIVariableObject getVariableObject() throws CDIException {
+ if ( fCDIVariableObject == null ) {
+ fCDIVariableObject = getCDISession().getVariableManager().getVariableObjectAsArray( getCDIVariable(), getStart(), getEnd() - getStart() + 1 );
+ }
+ return fCDIVariableObject;
+ }
+
+ private ICDIVariable getCDIVariable() {
+ return fCDIVariable;
+ }
+
+ private int getEnd() {
+ return fEnd;
+ }
+
+ private int getStart() {
+ return fStart;
+ }
+
+ static public List splitArray( CDebugElement parent, ICDIVariable cdiVariable, int start, int end ) throws DebugException {
ArrayList children = new ArrayList();
int len = end - start + 1;
int perSlot = 1;
- while( len > perSlot * SLOT_SIZE )
- {
+ while( len > perSlot * SLOT_SIZE ) {
perSlot *= SLOT_SIZE;
}
- if ( perSlot == 1 )
- {
- try
- {
+ if ( perSlot == 1 ) {
+ try {
ICDIValue value = cdiVariable.getValue();
- if ( value instanceof ICDIArrayValue )
- {
+ if ( value instanceof ICDIArrayValue ) {
ICDIVariable[] cdiVars = ((ICDIArrayValue)value).getVariables( start, len );
- for ( int i = 0; i < cdiVars.length; ++i )
- children.add( new CModificationVariable( parent, cdiVars[i] ) );
+ for( int i = 0; i < cdiVars.length; ++i )
+ children.add( CVariableFactory.createVariable( parent, cdiVars[i] ) );
}
}
- catch( CDIException e )
- {
- children.add( new CModificationVariable( parent, new CVariable.ErrorVariable( null, e ) ) );
+ catch( CDIException e ) {
+// children.add( CVariableFactory.createVariableWithError( parent, e.getMessage() ) );
}
}
- else
- {
+ else {
int pos = start;
- while( pos <= end )
- {
- if ( pos + perSlot > end )
- {
+ while( pos <= end ) {
+ if ( pos + perSlot > end ) {
perSlot = end - pos + 1;
}
children.add( new CArrayPartition( parent, cdiVariable, pos, pos + perSlot - 1 ) );
@@ -147,82 +288,35 @@ public class CArrayPartition extends CVariable
}
return children;
}
-
- protected int getStart()
- {
- return fStart;
- }
-
- protected int getEnd()
- {
- return fEnd;
- }
/* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable()
+ * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#getExpressionString()
*/
- public boolean canEnableDisable()
- {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICVariable#getType()
- */
- public ICType getType() throws DebugException
- {
- if ( fType == null )
- {
- try
- {
- ICDIVariableObject varObject = getVariableObject();
- if ( varObject != null )
- fType = new CType( varObject.getType() );
- }
- catch (CDIException e)
- {
- requestFailed( CoreModelMessages.getString( "CArrayPartition.0" ), e ); //$NON-NLS-1$
- }
- }
- return fType;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICVariable#hasChildren()
- */
- public boolean hasChildren()
- {
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.internal.core.model.CVariable#getQualifiedName()
- */
- protected String getQualifiedName() throws DebugException
- {
- if ( fQualifiedName == null )
- {
- try
- {
- if ( getVariableObject() != null )
- {
+ public String getExpressionString() throws DebugException {
+ if ( fQualifiedName == null ) {
+ try {
+ if ( getVariableObject() != null ) {
fQualifiedName = getVariableObject().getQualifiedName();
}
}
- catch( CDIException e )
- {
+ catch( CDIException e ) {
requestFailed( CoreModelMessages.getString( "CArrayPartition.1" ), e ); //$NON-NLS-1$
}
}
return fQualifiedName;
}
- private ICDIVariableObject getVariableObject() throws CDIException
- {
- if ( fCDIVariableObject == null )
- {
- fCDIVariableObject = getCDISession().getVariableManager().getVariableObjectAsArray( fCDIVariable, getStart(), getEnd() - getStart() + 1 );
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#dispose()
+ */
+ public void dispose() {
+ if ( fType != null ) {
+ ((CType)fType).dispose();
+ fType = null;
+ }
+ if ( fArrayPartitionValue != null ) {
+ fArrayPartitionValue.dispose();
+ fArrayPartitionValue = null;
}
- return fCDIVariableObject;
}
}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java
index f17521d9643..0c623797b13 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CArrayPartitionValue.java
@@ -8,27 +8,21 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.debug.internal.core.model;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator;
-import org.eclipse.cdt.debug.core.model.ICValue;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IVariable;
/**
- *
- * The value for an array partition.
- *
- * @since Sep 9, 2002
+ * A value for an array partition.
*/
-public class CArrayPartitionValue extends CDebugElement implements ICValue
-{
+public class CArrayPartitionValue extends AbstractCValue {
+
/**
* The underlying CDI variable.
*/
@@ -37,7 +31,7 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue
/**
* Parent variable.
*/
- private CVariable fParent = null;
+ private AbstractCVariable fParent = null;
/**
* List of child variables.
@@ -50,10 +44,8 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue
/**
* Constructor for CArrayPartitionValue.
- * @param target
*/
- public CArrayPartitionValue( CVariable parent, ICDIVariable cdiVariable, int start, int end )
- {
+ public CArrayPartitionValue( AbstractCVariable parent, ICDIVariable cdiVariable, int start, int end ) {
super( (CDebugTarget)parent.getDebugTarget() );
fCDIVariable = cdiVariable;
fParent = parent;
@@ -61,115 +53,108 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue
fEnd = end;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
*/
- public String getReferenceTypeName() throws DebugException
- {
- return null;
+ public String getReferenceTypeName() throws DebugException {
+ return ( getParentVariable() != null ) ? getParentVariable().getReferenceTypeName() : null;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.debug.core.model.IValue#getValueString()
*/
- public String getValueString() throws DebugException
- {
- return null;
+ public String getValueString() throws DebugException {
+ return ""; //$NON-NLS-1$
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.debug.core.model.IValue#isAllocated()
*/
- public boolean isAllocated() throws DebugException
- {
+ public boolean isAllocated() throws DebugException {
return true;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.debug.core.model.IValue#getVariables()
*/
- public IVariable[] getVariables() throws DebugException
- {
+ public IVariable[] getVariables() throws DebugException {
List list = getVariables0();
return (IVariable[])list.toArray( new IVariable[list.size()] );
}
- protected synchronized List getVariables0() throws DebugException
- {
+ protected synchronized List getVariables0() throws DebugException {
if ( !isAllocated() || !hasVariables() )
return Collections.EMPTY_LIST;
- if ( fVariables.size() == 0 )
- {
+ if ( fVariables.size() == 0 ) {
fVariables = CArrayPartition.splitArray( this, getCDIVariable(), getStart(), getEnd() );
}
return fVariables;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.debug.core.model.IValue#hasVariables()
*/
- public boolean hasVariables() throws DebugException
- {
+ public boolean hasVariables() throws DebugException {
return true;
}
-
- protected int getStart()
- {
+
+ protected int getStart() {
return fStart;
}
- protected int getEnd()
- {
+ protected int getEnd() {
return fEnd;
}
- public void setChanged( boolean changed ) throws DebugException
- {
+ public void setChanged( boolean changed ) throws DebugException {
Iterator it = fVariables.iterator();
- while( it.hasNext() )
- {
+ while( it.hasNext() ) {
((CVariable)it.next()).setChanged( changed );
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.cdt.debug.core.model.ICValue#computeDetail()
*/
- public String evaluateAsExpression()
- {
+ public String evaluateAsExpression() {
ICExpressionEvaluator ee = (ICExpressionEvaluator)getDebugTarget().getAdapter( ICExpressionEvaluator.class );
- String valueString = null;
- if ( ee != null && ee.canEvaluate() )
- {
- try
- {
+ String valueString = null;
+ if ( ee != null && ee.canEvaluate() ) {
+ try {
if ( getParentVariable() != null )
- valueString = ee.evaluateExpressionToString( getParentVariable().getQualifiedName() );
+ valueString = ee.evaluateExpressionToString( getParentVariable().getExpressionString() );
}
- catch( DebugException e )
- {
+ catch( DebugException e ) {
valueString = e.getMessage();
}
}
return valueString;
}
- public CVariable getParentVariable()
- {
+ public AbstractCVariable getParentVariable() {
return fParent;
}
- protected ICDIVariable getCDIVariable()
- {
+ protected ICDIVariable getCDIVariable() {
return fCDIVariable;
}
- public void dispose()
- {
+ public void dispose() {
Iterator it = fVariables.iterator();
- while( it.hasNext() )
- {
- ((CVariable)it.next()).dispose();
+ while( it.hasNext() ) {
+ ((AbstractCVariable)it.next()).dispose();
}
}
-}
+}
\ No newline at end of file
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 688f4418d2b..e5f93ac0043 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
@@ -34,7 +34,6 @@ import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointHit;
import org.eclipse.cdt.debug.core.cdi.ICDIConfiguration;
import org.eclipse.cdt.debug.core.cdi.ICDIEndSteppingRange;
import org.eclipse.cdt.debug.core.cdi.ICDIErrorInfo;
-import org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager;
import org.eclipse.cdt.debug.core.cdi.ICDILocation;
import org.eclipse.cdt.debug.core.cdi.ICDISession;
import org.eclipse.cdt.debug.core.cdi.ICDISessionObject;
@@ -1294,14 +1293,8 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
* @see org.eclipse.debug.core.IExpressionListener#expressionRemoved(org.eclipse.debug.core.model.IExpression)
*/
public void expressionRemoved( IExpression expression ) {
- if ( expression != null && expression.getDebugTarget().equals( this ) && expression instanceof CExpression ) {
- ICDIExpressionManager em = getCDISession().getExpressionManager();
- try {
- em.destroyExpression( ((CExpression)expression).getCDIExpression() );
- }
- catch( CDIException e ) {
- // do nothing
- }
+ if ( expression instanceof CExpression && expression.getDebugTarget().equals( this ) ) {
+ ((CExpression)expression).dispose();
}
}
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 a27e782c107..fc1a0d1204f 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
@@ -12,139 +12,88 @@ package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDebugConstants;
-import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent;
import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
-import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject;
+import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IExpression;
import org.eclipse.debug.core.model.IValue;
/**
- *
- * Enter type comment.
- *
- * @since Sep 17, 2002
+ * Represents an expression in the CDI model.
*/
-public class CExpression extends CModificationVariable
- implements IExpression
-{
+public class CExpression extends CVariable implements IExpression {
+
/**
* Constructor for CExpression.
- * @param target
- * @param cdiExpression
*/
- public CExpression( CDebugTarget target, ICDIExpression cdiExpression )
- {
+ public CExpression( CDebugTarget target, ICDIExpression cdiExpression ) {
super( target, cdiExpression );
- fFormat = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT );
+ setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ) ) );
}
/**
* Constructor for CExpression.
- * @param target
- * @param cdiExpression
*/
- public CExpression( CDebugTarget target, ICDIVariableObject cdiVariableObject )
- {
+ public CExpression( CDebugTarget target, ICDIVariableObject cdiVariableObject ) {
super( target, cdiVariableObject );
- fFormat = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT );
+ setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ) ) );
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IExpression#getExpressionText()
*/
- public String getExpressionText()
- {
- try
- {
+ public String getExpressionText() {
+ try {
return getName();
}
- catch( DebugException e )
- {
+ catch( DebugException e ) {
}
return null;
}
/* (non-Javadoc)
- * @see org.eclipse.debug.core.model.IExpression#getValue()
+ * @see org.eclipse.debug.core.model.IVariable#getValue()
*/
- public IValue getValue()
- {
- try
- {
+ public IValue getValue() {
+ try {
return super.getValue();
}
- catch( DebugException e )
- {
+ catch( DebugException e ) {
}
return null;
}
- public void dispose()
- {
- super.dispose();
- try {
- ICDIExpression cdiExpression = getCDIExpression();
- if ( cdiExpression != null ) {
- getCDISession().getExpressionManager().destroyExpression( cdiExpression );
- }
- }
- catch( CDIException e ) {
- DebugPlugin.log( e );
- }
- }
-
- protected ICDIExpression getCDIExpression() throws CDIException
- {
- ICDIVariable var = getCDIVariable();
- return ( var instanceof ICDIExpression ) ? (ICDIExpression)var : null;
- }
-
- /**
- * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(ICDIEvent)
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[])
*/
- public void handleDebugEvents( ICDIEvent[] events )
- {
- for (int i = 0; i < events.length; i++)
- {
+ public void handleDebugEvents( ICDIEvent[] events ) {
+ for( int i = 0; i < events.length; i++ ) {
ICDIEvent event = events[i];
- if ( event instanceof ICDIResumedEvent )
- {
- if ( event.getSource() instanceof ICDITarget && getCDITarget().equals( event.getSource() ) )
- {
- try
- {
- setChanged( false );
- }
- catch( DebugException e )
- {
- CDebugCorePlugin.log( e );
- }
+ if ( event instanceof ICDIResumedEvent ) {
+ if ( event.getSource() instanceof ICDITarget && getCDITarget().equals( event.getSource() ) ) {
+ setChanged( false );
}
break;
}
}
- super.handleDebugEvents(events);
+ super.handleDebugEvents( events );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled()
*/
- public boolean isEnabled()
- {
+ public boolean isEnabled() {
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable()
*/
- public boolean canEnableDisable()
- {
+ public boolean canEnableDisable() {
return false;
}
-}
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java
index 16350ae0844..5b5e4a95de2 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java
@@ -7,116 +7,29 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
-***********************************************************************/
-
+ ***********************************************************************/
package org.eclipse.cdt.debug.internal.core.model;
-import org.eclipse.cdt.debug.core.CDebugCorePlugin;
-import org.eclipse.cdt.debug.core.cdi.CDIException;
-import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent;
-import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent;
-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.cdt.debug.core.cdi.model.type.ICDIArrayValue;
+import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject;
import org.eclipse.cdt.debug.core.model.ICGlobalVariable;
-import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.model.IValue;
/**
- *
- * Enter type comment.
- *
- * @since: Oct 2, 2002
+ * Represents a global variable.
*/
-public class CGlobalVariable extends CModificationVariable implements ICGlobalVariable
-{
+public class CGlobalVariable extends CVariable implements ICGlobalVariable {
+
/**
* Constructor for CGlobalVariable.
- * @param parent
- * @param cdiVariable
*/
- public CGlobalVariable( CDebugElement parent, ICDIVariable cdiVariable )
- {
- super( parent, cdiVariable );
+ protected CGlobalVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject ) {
+ super( parent, cdiVariableObject );
}
/**
- * Returns the current value of this variable. The value
- * is cached.
- *
- * @see org.eclipse.debug.core.model.IVariable#getValue()
+ * Constructor for CGlobalVariable.
*/
- public IValue getValue() throws DebugException
- {
- if ( !isEnabled() )
- return fDisabledValue;
- if ( fValue == null )
- {
- ICDIValue cdiValue = getCurrentValue();
- if ( cdiValue instanceof ICDIArrayValue )
- {
- ICDIVariable var = null;
- try
- {
- var = getCDIVariable();
- }
- catch( CDIException e )
- {
- requestFailed( "", e ); //$NON-NLS-1$
- }
- int[] dims = getType().getArrayDimensions();
- if ( dims.length > 0 && dims[0] > 0 )
- fValue = CValueFactory.createArrayValue( this, var, 0, dims.length - 1 );
- }
- else
- fValue = CValueFactory.createGlobalValue( this, getCurrentValue() );
- }
- return fValue;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(ICDIEvent)
- */
- public void handleDebugEvents( ICDIEvent[] events )
- {
- super.handleDebugEvents( events );
- for (int i = 0; i < events.length; i++)
- {
- ICDIEvent event = events[i];
- ICDIObject source = event.getSource();
- if (source == null)
- continue;
-
- if ( source.getTarget().equals( getCDITarget() ) )
- {
- if ( event instanceof ICDIResumedEvent )
- {
- try
- {
- setChanged( false );
- }
- catch( DebugException e )
- {
- CDebugCorePlugin.log( e );
- }
- }
- }
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.internal.core.model.CVariable#dispose()
- */
- public void dispose() {
- if ( getShadow() != null )
- getShadow().dispose();
- try {
- getCDISession().getVariableManager().destroyVariable( getCDIVariable() );
- }
- catch( CDIException e ) {
- }
- super.dispose();
+ protected CGlobalVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject, String message ) {
+ super( parent, cdiVariableObject, message );
}
/* (non-Javadoc)
@@ -125,4 +38,4 @@ public class CGlobalVariable extends CModificationVariable implements ICGlobalVa
public boolean canEnableDisable() {
return true;
}
-}
+}
\ No newline at end of file
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
deleted file mode 100644
index 89d807ee744..00000000000
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CModificationVariable.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 QNX Software Systems and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * QNX Software Systems - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.cdt.debug.internal.core.model;
-
-import org.eclipse.cdt.debug.core.cdi.CDIException;
-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.ICDIVariableObject;
-import org.eclipse.cdt.debug.core.model.CDebugElementState;
-import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.model.IValue;
-import org.eclipse.debug.core.model.IValueModification;
-
-/**
- *
- * Common functionality for variables that support value modification
- *
- * @since Aug 9, 2002
- */
-public class CModificationVariable extends CVariable
-{
- /**
- * Constructor for CModificationVariable.
- * @param parent
- * @param cdiVariable
- */
- public CModificationVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject )
- {
- super( parent, cdiVariableObject );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
- */
- public boolean supportsValueModification()
- {
- CDebugTarget target = (CDebugTarget)getDebugTarget().getAdapter( CDebugTarget.class );
- return ( target != null && CDebugElementState.SUSPENDED.equals( target.getState() ) && isEditable() );
- }
-
- /**
- * @see IValueModification#verifyValue(String)
- */
- public boolean verifyValue( String expression )
- {
- return true;
- }
-
- /**
- * @see IValueModification#verifyValue(IValue)
- */
- public boolean verifyValue( IValue value )
- {
- return value.getDebugTarget().equals( getDebugTarget() );
- }
-
- /**
- * @see IValueModification#setValue(String)
- */
- public final void setValue( String expression ) throws DebugException
- {
- String newExpression = processExpression( expression );
- ICDIVariable cdiVariable = null;
- try
- {
- cdiVariable = getCDIVariable();
- if ( cdiVariable != null )
- cdiVariable.setValue( newExpression );
- else
- requestFailed( CoreModelMessages.getString( "CModificationVariable.0" ), null ); //$NON-NLS-1$
-
- }
- catch( CDIException e )
- {
- targetRequestFailed( e.getMessage(), null );
- }
- }
-
- /**
- * Set this variable's value to the given value
- */
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.internal.core.CModificationVariable#setValue(ICDIValue)
- */
- protected void setValue( ICDIValue value ) throws DebugException
- {
- ICDIVariable cdiVariable = null;
- try
- {
- cdiVariable = getCDIVariable();
- if ( cdiVariable != null )
- cdiVariable.setValue( value );
- else
- requestFailed( CoreModelMessages.getString( "CModificationVariable.1" ), null ); //$NON-NLS-1$
- }
- catch( CDIException e )
- {
- targetRequestFailed( e.getMessage(), null );
- }
- }
-
- private String processExpression( String oldExpression ) throws DebugException
- {
- return oldExpression;
- }
-}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java
index b8614c447ca..2d633061f85 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java
@@ -13,70 +13,44 @@ package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDebugConstants;
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister;
-import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject;
+import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterObject;
+import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IRegister;
import org.eclipse.debug.core.model.IRegisterGroup;
-import org.eclipse.debug.core.model.IValue;
/**
- *
- * Enter type comment.
- *
- * @since Sep 16, 2002
+ * Represents a register in the CDI model.
*/
-public class CRegister extends CGlobalVariable implements IRegister
-{
- public static class ErrorRegister extends ErrorVariable implements ICDIRegister
- {
- public ErrorRegister( ICDIVariableObject varObject, Exception e )
- {
- super( varObject, e );
- }
+public class CRegister extends CGlobalVariable implements IRegister {
+
+ /**
+ * Constructor for CRegister.
+ */
+ protected CRegister( CRegisterGroup parent, ICDIRegister cdiRegister ) {
+ super( parent, cdiRegister );
+ setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) );
}
/**
* Constructor for CRegister.
- * @param parent
- * @param cdiVariable
*/
- public CRegister( CRegisterGroup parent, ICDIRegister cdiRegister )
- {
- super( parent, cdiRegister );
- fFormat = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT );
+ protected CRegister( CRegisterGroup parent, ICDIRegisterObject registerObject, String message ) {
+ super( parent, registerObject, message );
+ setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) );
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IRegister#getRegisterGroup()
*/
- public IRegisterGroup getRegisterGroup() throws DebugException
- {
+ public IRegisterGroup getRegisterGroup() throws DebugException {
return (IRegisterGroup)getParent();
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
- */
- public boolean hasValueChanged() throws DebugException
- {
- try {
- IValue value = getValue();
- if ( value != null )
- {
- return ( value.hasVariables() ) ? false : fChanged;
- }
- }
- catch( DebugException e ) {
- // ignore to prevent logging.
- }
- return false;
- }
-
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled()
*/
- public boolean isEnabled()
- {
+ public boolean isEnabled() {
return true;
}
-}
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java
index 009d6351eac..a112ee80bf2 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java
@@ -14,12 +14,11 @@ import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister;
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterObject;
import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IRegister;
import org.eclipse.debug.core.model.IRegisterGroup;
/**
- * Represents a group of registers of a debug target.
+ * Represents a group of registers.
*/
public class CRegisterGroup extends CDebugElement implements IRegisterGroup {
@@ -39,32 +38,31 @@ public class CRegisterGroup extends CDebugElement implements IRegisterGroup {
fRegisters = new IRegister[regObjects.length];
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IRegisterGroup#getName()
*/
public String getName() throws DebugException {
return fName;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IRegisterGroup#getRegisters()
*/
public IRegister[] getRegisters() throws DebugException {
for ( int i = 0; i < fRegisters.length; ++i ) {
if ( fRegisters[i] == null ) {
- fRegisters[i] = new CRegister( this, getCDIRegister( fRegisterObjects[i] ) );
+ try {
+ fRegisters[i] = new CRegister( this, getCDIRegister( fRegisterObjects[i] ) );
+ }
+ catch( DebugException e ) {
+ fRegisters[i] = new CRegister( this, fRegisterObjects[i], e.getMessage() );
+ }
}
}
return fRegisters;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IRegisterGroup#hasRegisters()
*/
public boolean hasRegisters() throws DebugException {
@@ -81,23 +79,20 @@ public class CRegisterGroup extends CDebugElement implements IRegisterGroup {
}
private ICDIRegister getCDIRegister( ICDIRegisterObject ro ) throws DebugException {
+ ICDIRegister register = null;
try {
- return ((CDebugTarget)getDebugTarget()).getCDISession().getRegisterManager().createRegister( ro );
+ register = ((CDebugTarget)getDebugTarget()).getCDISession().getRegisterManager().createRegister( ro );
}
catch( CDIException e ) {
- return new CRegister.ErrorRegister( ro, e );
+ requestFailed( e.getMessage(), null );
}
+ return register;
}
public void resetChangeFlags() {
for ( int i = 0; i < fRegisters.length; ++i ) {
if ( fRegisters[i] != null ) {
- try {
- ((CRegister)fRegisters[i]).setChanged( false );
- }
- catch( DebugException e ) {
- DebugPlugin.log( e );
- }
+ ((CRegister)fRegisters[i]).setChanged( false );
}
}
}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java
index 07b657cfd3e..f44ad29c932 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java
@@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDILocation;
import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent;
@@ -109,7 +108,7 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart
fVariables = new ArrayList( vars.size() );
Iterator it = vars.iterator();
while( it.hasNext() ) {
- fVariables.add( new CModificationVariable( this, (ICDIVariableObject)it.next() ) );
+ fVariables.add( CVariableFactory.createVariable( this, (ICDIVariableObject)it.next() ) );
}
}
else if ( refreshVariables() ) {
@@ -140,7 +139,7 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart
// add any new locals
Iterator newOnes = locals.iterator();
while( newOnes.hasNext() ) {
- fVariables.add( new CModificationVariable( this, (ICDIVariableObject)newOnes.next() ) );
+ fVariables.add( CVariableFactory.createVariable( this, (ICDIVariableObject)newOnes.next() ) );
}
}
@@ -582,14 +581,9 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart
private void preserveVariables() {
if ( fVariables == null )
return;
- try {
- Iterator it = fVariables.iterator();
- while( it.hasNext() ) {
- ((CVariable)it.next()).setChanged( false );
- }
- }
- catch( DebugException e ) {
- CDebugCorePlugin.log( e );
+ Iterator it = fVariables.iterator();
+ while( it.hasNext() ) {
+ ((CVariable)it.next()).setChanged( false );
}
}
@@ -597,7 +591,7 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart
Iterator it = list.iterator();
while( it.hasNext() ) {
ICDIVariableObject newVarObject = (ICDIVariableObject)it.next();
- if ( var.sameVariableObject( newVarObject ) )
+ if ( var.sameVariable( newVarObject ) )
return newVarObject;
}
return null;
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java
index 5df07418f1d..d50cac38924 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java
@@ -8,13 +8,13 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDICharType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDerivedType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointType;
+import org.eclipse.cdt.debug.core.cdi.model.type.ICDIIntegralType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIReferenceType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIStructType;
@@ -22,61 +22,46 @@ import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType;
import org.eclipse.cdt.debug.core.model.ICType;
/**
- * Enter type comment.
- *
- * @since Jun 10, 2003
+ * The CDI-based implementation of ICType
.
*/
-public class CType implements ICType
-{
+public class CType implements ICType {
+
+ /**
+ * The underlying CDI type.
+ */
private ICDIType fCDIType;
- public CType( ICDIType cdiType )
- {
+ /**
+ * Constructor for CType.
+ */
+ public CType( ICDIType cdiType ) {
setCDIType( cdiType );
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.type.ICType#getName()
+ * @see org.eclipse.cdt.debug.core.model.ICType#getName()
*/
- public String getName()
- {
+ public String getName() {
return ( fCDIType != null ) ? fCDIType.getTypeName() : null;
}
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
- */
- public Object getAdapter( Class adapter )
- {
- if ( ICType.class.equals( adapter ) )
- return this;
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.type.ICType#dispose()
- */
- public void dispose()
- {
+ public void dispose() {
fCDIType = null;
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.type.ICType#getArrayDimensions()
+ * @see org.eclipse.cdt.debug.core.model.ICType#getArrayDimensions()
*/
- public int[] getArrayDimensions()
- {
+ public int[] getArrayDimensions() {
int length = 0;
ICDIType type = getCDIType();
- while( type instanceof ICDIArrayType )
- {
+ while( type instanceof ICDIArrayType ) {
++length;
type = ( type instanceof ICDIDerivedType ) ? ((ICDIDerivedType)type).getComponentType() : null;
}
int[] dims = new int[length];
type = getCDIType();
- for ( int i = length; i > 0; --i )
- {
+ for( int i = length; i > 0; --i ) {
dims[i - 1] = ((ICDIArrayType)type).getDimension();
type = ((ICDIDerivedType)type).getComponentType();
}
@@ -84,69 +69,64 @@ public class CType implements ICType
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.type.ICType#isArray()
+ * @see org.eclipse.cdt.debug.core.model.ICType#isArray()
*/
- public boolean isArray()
- {
+ public boolean isArray() {
return ( getCDIType() instanceof ICDIArrayType );
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.type.ICType#isCharacter()
+ * @see org.eclipse.cdt.debug.core.model.ICType#isCharacter()
*/
- public boolean isCharacter()
- {
+ public boolean isCharacter() {
return ( getCDIType() instanceof ICDICharType );
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.type.ICType#isFloatingPointType()
+ * @see org.eclipse.cdt.debug.core.model.ICType#isFloatingPointType()
*/
- public boolean isFloatingPointType()
- {
+ public boolean isFloatingPointType() {
return ( getCDIType() instanceof ICDIFloatingPointType );
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.type.ICType#isPointer()
+ * @see org.eclipse.cdt.debug.core.model.ICType#isPointer()
*/
- public boolean isPointer()
- {
+ public boolean isPointer() {
return ( getCDIType() instanceof ICDIPointerType );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICType#isReference()
*/
- public boolean isReference()
- {
+ public boolean isReference() {
return ( getCDIType() instanceof ICDIReferenceType );
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.type.ICType#isStructure()
+ * @see org.eclipse.cdt.debug.core.model.ICType#isStructure()
*/
- public boolean isStructure()
- {
+ public boolean isStructure() {
return ( getCDIType() instanceof ICDIStructType );
}
- protected ICDIType getCDIType()
- {
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICType#isUnsigned()
+ */
+ public boolean isUnsigned() {
+ ICDIType cdiType = getCDIType();
+ return ( cdiType instanceof ICDIIntegralType ) ? ((ICDIIntegralType)cdiType).isUnsigned() : false;
+ }
+
+ protected ICDIType getCDIType() {
return fCDIType;
}
- protected void setCDIType( ICDIType type )
- {
+ protected void setCDIType( ICDIType type ) {
fCDIType = type;
}
- protected boolean hasChildren()
- {
- ICDIType type = getCDIType();
- if ( type instanceof ICDIStructType || type instanceof ICDIArrayType ||
- type instanceof ICDIPointerType || type instanceof ICDIReferenceType )
- return true;
- return false;
+ protected boolean isAggregate() {
+ return ( isArray() || isStructure() || isPointer() || isReference() );
}
-}
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java
index 7807c6fd837..702abe2aa31 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java
@@ -8,7 +8,6 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.debug.internal.core.model;
import java.math.BigInteger;
@@ -18,34 +17,30 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.debug.core.cdi.CDIException;
-import org.eclipse.cdt.debug.core.cdi.ICDIFormat;
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.type.ICDICharValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDoubleValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIIntValue;
-import org.eclipse.cdt.debug.core.cdi.model.type.ICDIIntegralType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDILongLongValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDILongValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIReferenceValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIShortValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIWCharValue;
+import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus;
import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator;
-import org.eclipse.cdt.debug.core.model.ICValue;
+import org.eclipse.cdt.debug.core.model.ICType;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IVariable;
/**
- *
- * The value of a variable.
- *
- * @since Aug 9, 2002
+ * Represents the value of a variable in the CDI model.
*/
-public class CValue extends CDebugElement implements ICValue
-{
+public class CValue extends AbstractCValue {
+
/**
* Parent variable.
*/
@@ -68,37 +63,40 @@ public class CValue extends CDebugElement implements ICValue
/**
* Constructor for CValue.
- * @param target
*/
- public CValue( CVariable parent, ICDIValue cdiValue )
- {
+ protected CValue( CVariable parent, ICDIValue cdiValue ) {
super( (CDebugTarget)parent.getDebugTarget() );
fParent = parent;
fCDIValue = cdiValue;
}
+ /**
+ * Constructor for CValue.
+ */
+ protected CValue( CVariable parent, String message ) {
+ super( (CDebugTarget)parent.getDebugTarget() );
+ fParent = parent;
+ setStatus( ICDebugElementStatus.ERROR, message );
+ }
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
*/
- public String getReferenceTypeName() throws DebugException
- {
+ public String getReferenceTypeName() throws DebugException {
return ( getParentVariable() != null ) ? getParentVariable().getReferenceTypeName() : null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#getValueString()
*/
- public String getValueString() throws DebugException
- {
- if ( fValueString == null && getUnderlyingValue() != null )
- {
- try
- {
+ public String getValueString() throws DebugException {
+ if ( fValueString == null && getUnderlyingValue() != null ) {
+ try {
fValueString = processUnderlyingValue( getUnderlyingValue() );
+ resetStatus();
}
- catch( CDIException e )
- {
- fValueString = e.getMessage();
+ catch( CDIException e ) {
+ setStatus( ICDebugElementStatus.ERROR, e.getMessage() );
}
}
return fValueString;
@@ -107,42 +105,33 @@ public class CValue extends CDebugElement implements ICValue
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#isAllocated()
*/
- public boolean isAllocated() throws DebugException
- {
+ public boolean isAllocated() throws DebugException {
return true;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#getVariables()
*/
- public IVariable[] getVariables() throws DebugException
- {
+ public IVariable[] getVariables() throws DebugException {
List list = getVariables0();
return (IVariable[])list.toArray( new IVariable[list.size()] );
}
- protected synchronized List getVariables0() throws DebugException
- {
+ protected synchronized List getVariables0() throws DebugException {
if ( !isAllocated() || !hasVariables() )
return Collections.EMPTY_LIST;
- if ( fVariables.size() == 0 )
- {
- try
- {
- List vars = getCDIVariables();
+ if ( fVariables.size() == 0 ) {
+ try {
+ List vars = getCDIVariables();
fVariables = new ArrayList( vars.size() );
Iterator it = vars.iterator();
- while( it.hasNext() )
- {
- fVariables.add( new CModificationVariable( this, (ICDIVariable)it.next() ) );
+ while( it.hasNext() ) {
+ fVariables.add( CVariableFactory.createVariable( this, (ICDIVariable)it.next() ) );
}
+ resetStatus();
}
- catch( DebugException e )
- {
- fVariables = new ArrayList( 1 );
- CModificationVariable var = new CModificationVariable( this, new CVariable.ErrorVariable( null, e ) );
- var.setStatus( ICDebugElementStatus.ERROR, e.getMessage() );
- fVariables.add( var );
+ catch( DebugException e ) {
+ setStatus( ICDebugElementStatus.ERROR, e.getMessage() );
}
}
return fVariables;
@@ -151,81 +140,65 @@ public class CValue extends CDebugElement implements ICValue
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IValue#hasVariables()
*/
- public boolean hasVariables() throws DebugException
- {
- try
- {
+ public boolean hasVariables() throws DebugException {
+ try {
ICDIValue value = getUnderlyingValue();
if ( value != null )
return value.getChildrenNumber() > 0;
}
- catch( CDIException e )
- {
+ catch( CDIException e ) {
targetRequestFailed( e.getMessage(), null );
}
return false;
}
- public ICDIValue getUnderlyingValue()
- {
+ public ICDIValue getUnderlyingValue() {
return fCDIValue;
}
-
- protected List getCDIVariables() throws DebugException
- {
+
+ protected List getCDIVariables() throws DebugException {
ICDIVariable[] vars = null;
- try
- {
+ try {
ICDIValue value = getUnderlyingValue();
- if ( value != null )
- {
+ if ( value != null ) {
vars = value.getVariables();
- // Quick fix.
+ // Quick fix.
// getVariables should return an empty array instead of null.
- if ( vars == null )
- {
+ if ( vars == null ) {
vars = new ICDIVariable[0];
}
}
}
- catch( CDIException e )
- {
- requestFailed( CoreModelMessages.getString( "CValue.0" ), e ); //$NON-NLS-1$
+ catch( CDIException e ) {
+ requestFailed( e.getMessage(), e ); //$NON-NLS-1$
}
return Arrays.asList( vars );
}
- public synchronized void setChanged( boolean changed ) throws DebugException
- {
- if ( changed )
- {
+ public synchronized void setChanged( boolean changed ) /*throws DebugException*/ {
+ if ( changed ) {
fValueString = null;
+ resetStatus();
}
Iterator it = fVariables.iterator();
- while( it.hasNext() )
- {
+ while( it.hasNext() ) {
((CVariable)it.next()).setChanged( changed );
}
}
- public void dispose()
- {
+ public void dispose() {
Iterator it = fVariables.iterator();
- while( it.hasNext() )
- {
- ((CVariable)it.next()).dispose();
+ while( it.hasNext() ) {
+ ((AbstractCVariable)it.next()).dispose();
}
}
- public CVariable getParentVariable()
- {
+ public CVariable getParentVariable() {
return fParent;
}
- private String processUnderlyingValue( ICDIValue cdiValue ) throws CDIException
- {
- if ( cdiValue != null )
- {
+ private String processUnderlyingValue( ICDIValue cdiValue ) throws CDIException {
+ if ( cdiValue != null ) {
if ( cdiValue instanceof ICDICharValue )
return getCharValueString( (ICDICharValue)cdiValue );
else if ( cdiValue instanceof ICDIShortValue )
@@ -252,259 +225,200 @@ public class CValue extends CDebugElement implements ICValue
return null;
}
- private String getCharValueString( ICDICharValue value ) throws CDIException
- {
- switch( getParentVariable().getFormat() )
- {
- case ICDIFormat.NATURAL:
- {
- byte byteValue = (byte)value.byteValue();
- return ( ( Character.isISOControl( (char)byteValue ) &&
- byteValue != '\b' &&
- byteValue != '\t' &&
- byteValue != '\n' &&
- byteValue != '\f' &&
- byteValue != '\r' ) || byteValue < 0 ) ? "" : new String( new byte[] { '\'', byteValue, '\'' } ); //$NON-NLS-1$
- }
- case ICDIFormat.DECIMAL:
- {
- return ( isUnsigned() ) ? Integer.toString( value.shortValue() ) :
- Integer.toString( (byte)value.byteValue() );
- }
- case ICDIFormat.HEXADECIMAL:
- {
- StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
- String stringValue = ( isUnsigned() ) ? Integer.toHexString( value.shortValue() ) : Integer.toHexString( (byte)value.byteValue() );
- sb.append( ( stringValue.length() > 2 ) ? stringValue.substring( stringValue.length() - 2 ) : stringValue );
- return sb.toString();
- }
+ private String getCharValueString( ICDICharValue value ) throws CDIException {
+ CVariableFormat format = getParentVariable().getFormat();
+ if ( CVariableFormat.NATURAL.equals( format ) ) {
+ byte byteValue = (byte)value.byteValue();
+ return ((Character.isISOControl( (char)byteValue ) && byteValue != '\b' && byteValue != '\t' && byteValue != '\n' && byteValue != '\f' && byteValue != '\r') || byteValue < 0) ? "" : new String( new byte[]{ '\'', byteValue, '\'' } ); //$NON-NLS-1$
+ }
+ else if ( CVariableFormat.DECIMAL.equals( format ) ) {
+ return (isUnsigned()) ? Integer.toString( value.shortValue() ) : Integer.toString( (byte)value.byteValue() );
+ }
+ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
+ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
+ String stringValue = (isUnsigned()) ? Integer.toHexString( value.shortValue() ) : Integer.toHexString( (byte)value.byteValue() );
+ sb.append( (stringValue.length() > 2) ? stringValue.substring( stringValue.length() - 2 ) : stringValue );
+ return sb.toString();
}
return null;
}
- private String getShortValueString( ICDIShortValue value ) throws CDIException
- {
- switch( getParentVariable().getFormat() )
- {
- case ICDIFormat.NATURAL:
- case ICDIFormat.DECIMAL:
- return ( isUnsigned() ) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() );
- case ICDIFormat.HEXADECIMAL:
- {
- StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
- String stringValue = Integer.toHexString( ( isUnsigned() ) ? value.intValue() : value.shortValue() );
- sb.append( ( stringValue.length() > 4 ) ? stringValue.substring( stringValue.length() - 4 ) : stringValue );
- return sb.toString();
- }
+ private String getShortValueString( ICDIShortValue value ) throws CDIException {
+ CVariableFormat format = getParentVariable().getFormat();
+ if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
+ return (isUnsigned()) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() );
+ }
+ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
+ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
+ String stringValue = Integer.toHexString( (isUnsigned()) ? value.intValue() : value.shortValue() );
+ sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue );
+ return sb.toString();
}
return null;
}
- private String getIntValueString( ICDIIntValue value ) throws CDIException
- {
- switch( getParentVariable().getFormat() )
- {
- case ICDIFormat.NATURAL:
- case ICDIFormat.DECIMAL:
- return ( isUnsigned() ) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() );
- case ICDIFormat.HEXADECIMAL:
- {
- StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
- String stringValue = ( isUnsigned() ) ? Long.toHexString( value.longValue() ) : Integer.toHexString( value.intValue() );
- sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
- return sb.toString();
- }
+ private String getIntValueString( ICDIIntValue value ) throws CDIException {
+ CVariableFormat format = getParentVariable().getFormat();
+ if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
+ return (isUnsigned()) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() );
+ }
+ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
+ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
+ String stringValue = (isUnsigned()) ? Long.toHexString( value.longValue() ) : Integer.toHexString( value.intValue() );
+ sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
+ return sb.toString();
}
return null;
}
- private String getLongValueString( ICDILongValue value ) throws CDIException
- {
- switch( getParentVariable().getFormat() )
- {
- case ICDIFormat.NATURAL:
- case ICDIFormat.DECIMAL:
- return ( isUnsigned() ) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() );
- case ICDIFormat.HEXADECIMAL:
- {
- StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
- String stringValue = Long.toHexString( ( isUnsigned() ) ? value.longValue() : value.intValue() );
- sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
- return sb.toString();
- }
+ private String getLongValueString( ICDILongValue value ) throws CDIException {
+ CVariableFormat format = getParentVariable().getFormat();
+ if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
+ return (isUnsigned()) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() );
+ }
+ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
+ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
+ String stringValue = Long.toHexString( (isUnsigned()) ? value.longValue() : value.intValue() );
+ sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
+ return sb.toString();
}
return null;
}
- private String getLongLongValueString( ICDILongLongValue value ) throws CDIException
- {
- switch( getParentVariable().getFormat() )
- {
- case ICDIFormat.NATURAL:
- case ICDIFormat.DECIMAL:
- {
- if ( isUnsigned() )
- {
- BigInteger bigValue = new BigInteger( value.getValueString() );
- return bigValue.toString();
- }
- return Long.toString( value.longValue() );
+ private String getLongLongValueString( ICDILongLongValue value ) throws CDIException {
+ CVariableFormat format = getParentVariable().getFormat();
+ if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
+ if ( isUnsigned() ) {
+ BigInteger bigValue = new BigInteger( value.getValueString() );
+ return bigValue.toString();
}
- case ICDIFormat.HEXADECIMAL:
- {
- StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
-
- if ( isUnsigned() )
- {
- BigInteger bigValue = new BigInteger( value.getValueString() );
- sb.append( bigValue.toString( 16 ) );
- }
- else
- sb.append( Long.toHexString( value.longValue() ) );
- return sb.toString();
+ return Long.toString( value.longValue() );
+ }
+ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
+ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
+ if ( isUnsigned() ) {
+ BigInteger bigValue = new BigInteger( value.getValueString() );
+ sb.append( bigValue.toString( 16 ) );
}
+ else
+ sb.append( Long.toHexString( value.longValue() ) );
+ return sb.toString();
}
return null;
}
- private String getFloatValueString( ICDIFloatValue value ) throws CDIException
- {
+ private String getFloatValueString( ICDIFloatValue value ) throws CDIException {
float floatValue = value.floatValue();
Float flt = new Float( floatValue );
if ( flt.isNaN() || flt.isInfinite() )
return ""; //$NON-NLS-1$
long longValue = flt.longValue();
- switch( getParentVariable().getFormat() )
- {
- case ICDIFormat.NATURAL:
- return Float.toString( floatValue );
- case ICDIFormat.DECIMAL:
- return Long.toString( longValue );
- case ICDIFormat.HEXADECIMAL:
- {
- StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
- String stringValue = Long.toHexString( longValue );
- sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
- return sb.toString();
- }
+ CVariableFormat format = getParentVariable().getFormat();
+ if ( CVariableFormat.NATURAL.equals( format ) ) {
+ return Float.toString( floatValue );
+ }
+ else if ( CVariableFormat.DECIMAL.equals( format ) ) {
+ return Long.toString( longValue );
+ }
+ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
+ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
+ String stringValue = Long.toHexString( longValue );
+ sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
+ return sb.toString();
}
return null;
}
- private String getDoubleValueString( ICDIDoubleValue value ) throws CDIException
- {
+ private String getDoubleValueString( ICDIDoubleValue value ) throws CDIException {
double doubleValue = value.doubleValue();
Double dbl = new Double( doubleValue );
if ( dbl.isNaN() || dbl.isInfinite() )
return ""; //$NON-NLS-1$
long longValue = dbl.longValue();
- switch( getParentVariable().getFormat() )
- {
- case ICDIFormat.NATURAL:
- return dbl.toString();
- case ICDIFormat.DECIMAL:
- return Long.toString( longValue );
- case ICDIFormat.HEXADECIMAL:
- {
- StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
- String stringValue = Long.toHexString( longValue );
- sb.append( ( stringValue.length() > 16 ) ? stringValue.substring( stringValue.length() - 16 ) : stringValue );
- return sb.toString();
- }
+ CVariableFormat format = getParentVariable().getFormat();
+ if ( CVariableFormat.NATURAL.equals( format ) ) {
+ return dbl.toString();
+ }
+ else if ( CVariableFormat.DECIMAL.equals( format ) ) {
+ return Long.toString( longValue );
+ }
+ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
+ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
+ String stringValue = Long.toHexString( longValue );
+ sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue );
+ return sb.toString();
}
return null;
}
- private String getPointerValueString( ICDIPointerValue value ) throws CDIException
- {
+ private String getPointerValueString( ICDIPointerValue value ) throws CDIException {
long longValue = value.pointerValue();
- switch( getParentVariable().getFormat() )
- {
- case ICDIFormat.DECIMAL:
- return Long.toString( longValue );
- case ICDIFormat.NATURAL:
- case ICDIFormat.HEXADECIMAL:
- {
- StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
- String stringValue = Long.toHexString( longValue );
- sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
- return sb.toString();
- }
+ CVariableFormat format = getParentVariable().getFormat();
+ if ( CVariableFormat.DECIMAL.equals( format ) ) {
+ return Long.toString( longValue );
+ }
+ else if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.HEXADECIMAL.equals( format ) ) {
+ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
+ String stringValue = Long.toHexString( longValue );
+ sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
+ return sb.toString();
}
return null;
}
- private String getReferenceValueString( ICDIReferenceValue value ) throws CDIException
- {
+ private String getReferenceValueString( ICDIReferenceValue value ) throws CDIException {
long longValue = value.referenceValue();
- switch( getParentVariable().getFormat() )
- {
- case ICDIFormat.DECIMAL:
- return Long.toString( longValue );
- case ICDIFormat.NATURAL:
- case ICDIFormat.HEXADECIMAL:
- {
- StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
- String stringValue = Long.toHexString( longValue );
- sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
- return sb.toString();
- }
+ CVariableFormat format = getParentVariable().getFormat();
+ if ( CVariableFormat.DECIMAL.equals( format ) ) {
+ return Long.toString( longValue );
+ }
+ else if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.HEXADECIMAL.equals( format ) ) {
+ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
+ String stringValue = Long.toHexString( longValue );
+ sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
+ return sb.toString();
}
return null;
}
- private String getWCharValueString( ICDIWCharValue value ) throws CDIException
- {
- if ( getParentVariable() != null )
- {
+ private String getWCharValueString( ICDIWCharValue value ) throws CDIException {
+ if ( getParentVariable() != null ) {
int size = getParentVariable().sizeof();
- if ( size == 2 )
- {
- switch( getParentVariable().getFormat() )
- {
- case ICDIFormat.NATURAL:
- case ICDIFormat.DECIMAL:
- return ( isUnsigned() ) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() );
- case ICDIFormat.HEXADECIMAL:
- {
- StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
- String stringValue = Integer.toHexString( ( isUnsigned() ) ? value.intValue() : value.shortValue() );
- sb.append( ( stringValue.length() > 4 ) ? stringValue.substring( stringValue.length() - 4 ) : stringValue );
- return sb.toString();
- }
+ if ( size == 2 ) {
+ CVariableFormat format = getParentVariable().getFormat();
+ if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
+ return (isUnsigned()) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() );
+ }
+ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
+ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
+ String stringValue = Integer.toHexString( (isUnsigned()) ? value.intValue() : value.shortValue() );
+ sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue );
+ return sb.toString();
}
}
- if ( size == 4 )
- {
- switch( getParentVariable().getFormat() )
- {
- case ICDIFormat.NATURAL:
- case ICDIFormat.DECIMAL:
- return ( isUnsigned() ) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() );
- case ICDIFormat.HEXADECIMAL:
- {
- StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
- String stringValue = ( isUnsigned() ) ? Long.toHexString( value.longValue() ) : Integer.toHexString( value.intValue() );
- sb.append( ( stringValue.length() > 8 ) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
- return sb.toString();
- }
+ if ( size == 4 ) {
+ CVariableFormat format = getParentVariable().getFormat();
+ if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
+ return (isUnsigned()) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() );
+ }
+ else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
+ StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$
+ String stringValue = (isUnsigned()) ? Long.toHexString( value.longValue() ) : Integer.toHexString( value.intValue() );
+ sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
+ return sb.toString();
}
}
}
return value.getValueString();
}
- private boolean isUnsigned()
- {
+ private boolean isUnsigned() {
boolean result = false;
- try
- {
- if ( getParentVariable().getCDIVariable() != null )
- result = ( getParentVariable().getCDIVariable().getType() instanceof ICDIIntegralType ) ?
- ((ICDIIntegralType)getParentVariable().getCDIVariable().getType()).isUnsigned() : false;
+ try {
+ ICType type = getParentVariable().getType();
+ result = type.isUnsigned();
}
- catch( CDIException e )
- {
+ catch( DebugException e ) {
}
return result;
}
@@ -512,32 +426,29 @@ public class CValue extends CDebugElement implements ICValue
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICValue#evaluateAsExpression()
*/
- public String evaluateAsExpression()
- {
+ public String evaluateAsExpression() {
ICExpressionEvaluator ee = (ICExpressionEvaluator)getDebugTarget().getAdapter( ICExpressionEvaluator.class );
- String valueString = null;
- if ( ee != null && ee.canEvaluate() )
- {
- try
- {
+ String valueString = null;
+ if ( ee != null && ee.canEvaluate() ) {
+ try {
if ( getParentVariable() != null )
- valueString = ee.evaluateExpressionToString( getParentVariable().getQualifiedName() );
+ valueString = ee.evaluateExpressionToString( getParentVariable().getExpressionString() );
}
- catch( DebugException e )
- {
+ catch( DebugException e ) {
valueString = e.getMessage();
}
}
return valueString;
}
- protected void reset() throws DebugException
- {
+ /**
+ * Invalidates the string cache.
+ */
+ protected void reset() {
fValueString = null;
Iterator it = fVariables.iterator();
- while( it.hasNext() )
- {
- ((CVariable)it.next()).reset();
+ while( it.hasNext() ) {
+ ((CVariable)it.next()).resetValue();
}
}
-}
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java
index 5710779c4eb..2e6b96f34a4 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java
@@ -8,37 +8,34 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.debug.internal.core.model;
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.type.ICDIFloatingPointValue;
-import org.eclipse.debug.core.DebugException;
+import org.eclipse.cdt.debug.core.model.ICValue;
/**
- *
- * Generates values for variable and expressions.
- *
- * @since Sep 9, 2002
+ * The value factory for variable and expressions.
*/
-public class CValueFactory
-{
- static public CValue createValue( CVariable parent, ICDIValue cdiValue ) throws DebugException
- {
+public class CValueFactory {
+
+ static public CValue createValue( CVariable parent, ICDIValue cdiValue ) {
if ( cdiValue instanceof ICDIFloatingPointValue ) {
return new CFloatingPointValue( parent, cdiValue );
}
return new CValue( parent, cdiValue );
}
- static public CArrayPartitionValue createArrayValue( CVariable parent, ICDIVariable cdiVariable, int start, int end ) throws DebugException
- {
+ static public CArrayPartitionValue createArrayValue( AbstractCVariable parent, ICDIVariable cdiVariable, int start, int end ) {
return new CArrayPartitionValue( parent, cdiVariable, start, end );
}
- static public CValue createGlobalValue( CVariable parent, ICDIValue cdiValue ) throws DebugException
- {
+ static public CValue createGlobalValue( CVariable parent, ICDIValue cdiValue ) {
return new CGlobalValue( parent, cdiValue );
}
-}
+
+ static public ICValue createValueWithError( CVariable parent, String message ) {
+ return new CValue( parent, message );
+ }
+}
\ No newline at end of file
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 9770ce22d5a..2bc33af10d8 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
@@ -1,323 +1,310 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 QNX Software Systems and others.
- * All rights reserved. This program and the accompanying materials
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
- *
+ *
* Contributors:
- * QNX Software Systems - Initial API and implementation
- *******************************************************************************/
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
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.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.core.ICDebugConstants;
import org.eclipse.cdt.debug.core.cdi.CDIException;
-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.ICDIDestroyedEvent;
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.ICDIResumedEvent;
import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentObject;
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.ICDITarget;
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.ICDIVariableObject;
-import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType;
+import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus;
import org.eclipse.cdt.debug.core.model.ICType;
import org.eclipse.cdt.debug.core.model.ICValue;
-import org.eclipse.cdt.debug.core.model.ICVariable;
-import org.eclipse.cdt.debug.core.model.ICastToArray;
-import org.eclipse.cdt.debug.core.model.ICastToType;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IValue;
-import org.eclipse.debug.core.model.IVariable;
/**
- *
- * A superclass for all variable classes.
- *
- * @since Aug 9, 2002
+ * Represents a variable in the CDI model.
*/
-public abstract class CVariable extends CDebugElement
- implements ICVariable,
- ICDIEventListener,
- ICastToType,
- ICastToArray
-{
+public class CVariable extends AbstractCVariable implements ICDIEventListener {
+
/**
- * The instance of this class is created when the 'getCDIVariable' call throws an exception.
- *
- * @since Jul 22, 2003
+ * Represents a single CDI variable.
*/
- public static class ErrorVariable implements ICDIVariable
- {
- private ICDIVariableObject fVariableObject;
- private Exception fException;
-
- public ErrorVariable( ICDIVariableObject varObject, Exception e )
- {
- fVariableObject = varObject;
- fException = e;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getStackFrame()
+ private class InternalVariable {
+
+ /**
+ * The enclosing CVariable
instance.
*/
- public ICDIStackFrame getStackFrame() throws CDIException
- {
- return null;
- }
+ private CVariable fVariable;
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject#getName()
+ /**
+ * The CDI variable object this variable is based on.
*/
- public String getName()
- {
- return ( fVariableObject != null ) ? fVariableObject.getName() : ""; //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getTypeName()
- */
- public String getTypeName() throws CDIException
- {
- return ( fVariableObject != null ) ? fVariableObject.getTypeName() : ""; //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getType()
- */
- public ICDIType getType() throws CDIException
- {
- return ( fVariableObject != null ) ? fVariableObject.getType() : null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getValue()
- */
- public ICDIValue getValue() throws CDIException
- {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#isEditable()
- */
- public boolean isEditable() throws CDIException
- {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setValue(java.lang.String)
- */
- public void setValue( String expression ) throws CDIException
- {
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setValue(org.eclipse.cdt.debug.core.cdi.model.ICDIValue)
- */
- public void setValue( ICDIValue value ) throws CDIException
- {
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#setFormat(int)
- */
- public void setFormat( int format ) throws CDIException
- {
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIObject#getTarget()
- */
- public ICDITarget getTarget()
- {
- return ( fVariableObject != null ) ? fVariableObject.getTarget() : null;
- }
-
- public Exception getException()
- {
- return fException;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject#sizeof()
- */
- public int sizeof() throws CDIException
- {
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject#getQualifiedName()
- */
- public String getQualifiedName() throws CDIException
- {
- return ( fVariableObject != null ) ? fVariableObject.getQualifiedName() : null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject#equals(org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject)
- */
- public boolean equals( ICDIVariableObject varObject )
- {
- return ( fVariableObject != null ) ? fVariableObject.equals( varObject ) : false;
- }
- }
-
- class InternalVariable
- {
private ICDIVariableObject fCDIVariableObject;
+ /**
+ * The underlying CDI variable.
+ */
private ICDIVariable fCDIVariable;
- private Boolean fEditable = null;
+ /**
+ * The type of this variable.
+ */
+ private CType fType;
- private ICType fType = null;
+ /**
+ * The expression used to eveluate the value of this variable.
+ */
+ private String fQualifiedName;
- private String fQualifiedName = null;
+ /**
+ * The cache of the current value.
+ */
+ private ICValue fValue;
- public InternalVariable( ICDIVariableObject varObject )
- {
+ /**
+ * The change flag.
+ */
+ private boolean fChanged = false;
+
+ /**
+ * Constructor for InternalVariable.
+ */
+ InternalVariable( CVariable var, ICDIVariableObject varObject ) {
+ setVariable( var );
setCDIVariableObject( varObject );
- setCDIVariable( ( varObject instanceof ICDIVariable ) ? (ICDIVariable)varObject : null );
+ setCDIVariable( (varObject instanceof ICDIVariable) ? (ICDIVariable)varObject : null );
}
- protected synchronized ICDIVariable getCDIVariable() throws CDIException
- {
- if ( fCDIVariable == null )
- {
- try
- {
+ InternalVariable createShadow( int start, int length ) throws DebugException {
+ InternalVariable iv = null;
+ try {
+ iv = new InternalVariable( getVariable(), getCDISession().getVariableManager().getVariableObjectAsArray( getCDIVariableObject(), start, length ) );
+ }
+ catch( CDIException e ) {
+ requestFailed( e.getMessage(), null );
+ }
+ return iv;
+ }
+
+ InternalVariable createShadow( String type ) throws DebugException {
+ InternalVariable iv = null;
+ try {
+ iv = new InternalVariable( getVariable(), getCDISession().getVariableManager().getVariableObjectAsType( getCDIVariableObject(), type ) );
+ }
+ catch( CDIException e ) {
+ requestFailed( e.getMessage(), null );
+ }
+ return iv;
+ }
+
+ private synchronized ICDIVariable getCDIVariable() throws DebugException {
+ if ( fCDIVariable == null ) {
+ try {
if ( getCDIVariableObject() instanceof ICDIArgumentObject )
fCDIVariable = getCDISession().getVariableManager().createArgument( (ICDIArgumentObject)getCDIVariableObject() );
else
fCDIVariable = getCDISession().getVariableManager().createVariable( getCDIVariableObject() );
}
- catch( CDIException e )
- {
- fCDIVariable = new ErrorVariable( getCDIVariableObject(), e );
- setStatus( ICDebugElementStatus.ERROR, MessageFormat.format( CoreModelMessages.getString( "CVariable.0" ), new String[] { e.getMessage() } ) ); //$NON-NLS-1$
+ catch( CDIException e ) {
+ requestFailed( e.getMessage(), null );
}
}
return fCDIVariable;
}
- protected ICDIVariableObject getCDIVariableObject()
- {
+ private void setCDIVariable( ICDIVariable variable ) {
+ fCDIVariable = variable;
+ }
+
+ private ICDIVariableObject getCDIVariableObject() {
return fCDIVariableObject;
}
- protected ICType getType() throws CDIException
- {
- if ( fType == null )
- {
+ private void setCDIVariableObject( ICDIVariableObject variableObject ) {
+ fCDIVariableObject = variableObject;
+ }
+
+ String getQualifiedName() throws DebugException {
+ if ( fQualifiedName == null ) {
+ try {
+ fQualifiedName = (fCDIVariableObject != null) ? fCDIVariableObject.getQualifiedName() : null;
+ }
+ catch( CDIException e ) {
+ requestFailed( e.getMessage(), null );
+ }
+ }
+ return fQualifiedName;
+ }
+
+ CType getType() throws DebugException {
+ if ( fType == null ) {
ICDIVariableObject varObject = getCDIVariableObject();
if ( varObject != null )
- fType = new CType( varObject.getType() );
+ try {
+ fType = new CType( varObject.getType() );
+ }
+ catch( CDIException e ) {
+ requestFailed( e.getMessage(), null );
+ }
}
return fType;
}
- protected boolean isEditable() throws CDIException
- {
- if ( fEditable == null )
- {
- ICDIVariableObject varObject = getCDIVariableObject();
- if ( varObject != null && !(varObject instanceof ErrorVariable) )
- fEditable = new Boolean( varObject.isEditable() );
- }
- return ( fEditable != null ) ? fEditable.booleanValue() : false;
- }
-
- protected boolean hasChildren() throws CDIException
- {
- CType type = (CType)getType();
- return ( type != null ) ? type.hasChildren() : false;
- }
-
- private void setCDIVariable( ICDIVariable variable )
- {
- fCDIVariable = variable;
- }
-
- private void setCDIVariableObject( ICDIVariableObject object )
- {
- fCDIVariableObject = object;
- }
-
- protected synchronized void invalidate()
- {
- try
- {
- if ( fCDIVariable != null && !(fCDIVariable instanceof ErrorVariable) )
+ synchronized void invalidate() {
+ try {
+ if ( fCDIVariable != null )
getCDISession().getVariableManager().destroyVariable( fCDIVariable );
}
- catch( CDIException e )
- {
+ catch( CDIException e ) {
logError( e.getMessage() );
}
+ invalidateValue();
setCDIVariable( null );
if ( fType != null )
fType.dispose();
fType = null;
- fEditable = null;
}
- protected void dispose()
- {
+ void dispose() {
invalidate();
- setCDIVariableObject( null );
}
- protected boolean isSameVariable( ICDIVariable cdiVar )
- {
- return ( fCDIVariable != null ) ? fCDIVariable.equals( cdiVar ) : false;
+ boolean isSameVariable( ICDIVariable cdiVar ) {
+ return ( fCDIVariable != null ) ? fCDIVariable.equals( cdiVar ) : false;
}
- protected int sizeof()
- {
- if ( getCDIVariableObject() != null )
- {
- try
- {
+ int sizeof() {
+ if ( getCDIVariableObject() != null ) {
+ try {
return getCDIVariableObject().sizeof();
}
- catch( CDIException e )
- {
+ catch( CDIException e ) {
}
}
return 0;
}
- protected String getQualifiedName() throws CDIException
- {
- if ( fQualifiedName == null )
- {
- fQualifiedName = ( fCDIVariableObject != null ) ? fCDIVariableObject.getQualifiedName() : null;
- }
- return fQualifiedName;
+ boolean isArgument() {
+ return ( getCDIVariableObject() instanceof ICDIArgumentObject );
}
- public boolean hasErrors() {
- return ( fCDIVariable instanceof ErrorVariable );
+ void setValue( String expression ) throws DebugException {
+ ICDIVariable cdiVariable = null;
+ try {
+ cdiVariable = getCDIVariable();
+ if ( cdiVariable != null )
+ cdiVariable.setValue( expression );
+ else
+ requestFailed( CoreModelMessages.getString( "CModificationVariable.0" ), null ); //$NON-NLS-1$
+ }
+ catch( CDIException e ) {
+ targetRequestFailed( e.getMessage(), null );
+ }
+ }
+
+ void setValue( ICValue value ) {
+ fValue = value;
+ }
+
+ synchronized ICValue getValue() throws DebugException {
+ if ( fValue == null ) {
+ ICDIVariable var = getCDIVariable();
+ if ( var != null ) {
+ ICType type = null;
+ try {
+ type = getType();
+ }
+ catch( DebugException e ) {
+ // ignore and use default type
+ }
+ if ( type != null && type.isArray() ) {
+ int[] dims = type.getArrayDimensions();
+ if ( dims.length > 0 && dims[0] > 0 )
+ fValue = CValueFactory.createArrayValue( getVariable(), var, 0, dims[0] - 1 );
+ }
+ else {
+ try {
+ ICDIValue cdiValue = var.getValue();
+ if ( cdiValue != null )
+ fValue = CValueFactory.createValue( getVariable(), cdiValue );
+ }
+ catch( CDIException e ) {
+ requestFailed( e.getMessage(), e );
+ }
+ }
+ }
+ }
+ return fValue;
+ }
+
+ void invalidateValue() {
+ if ( fValue instanceof AbstractCValue ) {
+ ((AbstractCValue)fValue).dispose();
+ fValue = null;
+ }
+ }
+
+ boolean isChanged() {
+ return fChanged;
+ }
+
+ synchronized void setChanged( boolean changed ) {
+ if ( changed ) {
+ invalidateValue();
+ }
+ if ( fValue instanceof CValue ) {
+ ((CValue)fValue).setChanged( changed );
+ }
+ fChanged = changed;
+ }
+
+ CVariable getVariable() {
+ return fVariable;
+ }
+
+ private void setVariable( CVariable variable ) {
+ fVariable = variable;
+ }
+
+ void resetValue() {
+ if ( fValue instanceof CValue ) {
+ ((CValue)fValue).reset();
+ }
+ }
+
+ /**
+ * Compares the underlying variable objects.
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals( Object obj ) {
+ if ( obj instanceof InternalVariable ) {
+ return getCDIVariableObject().equals( ((InternalVariable)obj).getCDIVariableObject() );
+ }
+ return false;
+ }
+
+ boolean sameVariable( ICDIVariableObject vo ) {
+ return getCDIVariableObject().equals( vo );
}
}
+ /**
+ * Whether this variable is currently enabled.
+ */
+ private boolean fIsEnabled = true;
+
/**
* The parent object this variable is contained in.
*/
@@ -327,733 +314,478 @@ public abstract class CVariable extends CDebugElement
* The original internal variable.
*/
private InternalVariable fOriginal;
-
+
/**
* The shadow internal variable used for casting.
*/
- private InternalVariable fShadow = null;
-
- /**
- * Cache of current value - see #getValue().
- */
- protected ICValue fValue;
+ private InternalVariable fShadow;
/**
* The name of this variable.
*/
- private String fName = null;
-
- /**
- * Change flag.
- */
- protected boolean fChanged = false;
+ private String fName;
/**
* The current format of this variable.
*/
- protected int fFormat = ICDIFormat.NATURAL;
+ private CVariableFormat fFormat = CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT ) );
- private boolean fIsEnabled = true;
-
- /*
- * Temporary solution to avoid NPE in VariablesView.
- * This is fixed in the Eclipse 2.1.1 Maintenance Build.
- */
- static protected IValue fDisabledValue = new IValue()
- {
- public String getReferenceTypeName() throws DebugException
- {
- return null;
- }
-
- public String getValueString() throws DebugException
- {
- return null;
- }
-
- public boolean isAllocated() throws DebugException
- {
- return false;
- }
-
- public IVariable[] getVariables() throws DebugException
- {
- return null;
- }
-
- public boolean hasVariables() throws DebugException
- {
- return false;
- }
-
- public String getModelIdentifier()
- {
- return CDebugCorePlugin.getUniqueIdentifier();
- }
-
- public IDebugTarget getDebugTarget()
- {
- return null;
- }
-
- public ILaunch getLaunch()
- {
- return null;
- }
-
- public Object getAdapter( Class adapter )
- {
- return null;
- }
-
- };
/**
* Constructor for CVariable.
- * @param target
*/
- public CVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject )
- {
+ protected CVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject ) {
super( (CDebugTarget)parent.getDebugTarget() );
- fParent = parent;
- fIsEnabled = !enableVariableBookkeeping();
- fOriginal = createOriginal( cdiVariableObject );
- fShadow = null;
- if ( cdiVariableObject instanceof ErrorVariable )
- setStatus( ICDebugElementStatus.ERROR,
- MessageFormat.format( CoreModelMessages.getString( "CVariable.1" ), new String[] { ((ErrorVariable)cdiVariableObject).getException().getMessage() } ) ); //$NON-NLS-1$
- fFormat = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT );
+ setParent( parent );
+ if ( cdiVariableObject != null ) {
+ fName = cdiVariableObject.getName();
+ createOriginal( cdiVariableObject );
+ }
+ fIsEnabled = !isBookkeepingEnabled();
getCDISession().getEventManager().addEventListener( this );
}
- private InternalVariable createOriginal( ICDIVariableObject varObject )
- {
- return new InternalVariable( varObject );
+ /**
+ * Constructor for CVariable.
+ */
+ protected CVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject, String errorMessage ) {
+ super( (CDebugTarget)parent.getDebugTarget() );
+ setParent( parent );
+ if ( cdiVariableObject != null ) {
+ fName = cdiVariableObject.getName();
+ createOriginal( cdiVariableObject );
+ }
+ fIsEnabled = !isBookkeepingEnabled();
+ setStatus( ICDebugElementStatus.ERROR, MessageFormat.format( CoreModelMessages.getString( "CVariable.1" ), new String[]{ errorMessage } ) ); //$NON-NLS-1$
+ getCDISession().getEventManager().addEventListener( this );
}
- /**
- * Returns the current value of this variable. The value
- * is cached, but on each access we see if the value has changed
- * and update if required.
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.ICVariable#getType()
+ */
+ public ICType getType() throws DebugException {
+ InternalVariable iv = getCurrentInternalVariable();
+ return ( iv != null ) ? iv.getType() : null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled()
+ */
+ public boolean isEnabled() {
+ return fIsEnabled;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.ICVariable#setEnabled(boolean)
+ */
+ public void setEnabled( boolean enabled ) throws DebugException {
+ InternalVariable iv = getOriginal();
+ if ( iv != null )
+ iv.invalidate();
+ iv = getShadow();
+ if ( iv != null )
+ iv.invalidate();
+ fIsEnabled = enabled;
+ fireChangeEvent( DebugEvent.STATE );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable()
+ */
+ public boolean canEnableDisable() {
+ return !( getParent() instanceof IValue );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.ICVariable#isArgument()
+ */
+ public boolean isArgument() {
+ InternalVariable iv = getOriginal();
+ return ( iv != null ) ? iv.isArgument() : false;
+ }
+
+ /*
+ * (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IVariable#getValue()
*/
- public IValue getValue() throws DebugException
- {
- if ( !isEnabled() )
- return fDisabledValue;
- if ( fValue == null )
- {
- ICType type = null;
- try
- {
- type = getType();
- }
- catch( DebugException e )
- {
- // ignore and use default type
- }
- if ( type != null && type.isArray() )
- {
- ICDIVariable var = null;
- try
- {
- var = getInternalVariable().getCDIVariable();
+ public IValue getValue() throws DebugException {
+ if ( isEnabled() ) {
+ InternalVariable iv = getCurrentInternalVariable();
+ if ( iv != null ) {
+ try {
+ return iv.getValue();
}
- catch( CDIException e )
- {
- requestFailed( "", e ); //$NON-NLS-1$
+ catch( DebugException e ) {
+ setStatus( ICDebugElementStatus.ERROR, e.getMessage() );
}
- int[] dims = type.getArrayDimensions();
- if ( dims.length > 0 && dims[0] > 0 )
- fValue = CValueFactory.createArrayValue( this, var, 0, dims[0] - 1 );
}
- else
- {
- ICDIValue cdiValue = getCurrentValue();
- if ( cdiValue != null )
- fValue = CValueFactory.createValue( this, cdiValue );
- }
- }
- return fValue;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
- */
- public boolean hasValueChanged() throws DebugException
- {
- return fChanged;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.IValueModification#setValue(String)
- */
- public void setValue( String expression ) throws DebugException
- {
- notSupported( CoreModelMessages.getString( "CVariable.2" ) ); //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.IValueModification#setValue(IValue)
- */
- public void setValue( IValue value ) throws DebugException
- {
- notSupported( CoreModelMessages.getString( "CVariable.3" ) ); //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
- */
- public boolean supportsValueModification()
- {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.IValueModification#verifyValue(String)
- */
- public boolean verifyValue( String expression ) throws DebugException
- {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.IValueModification#verifyValue(IValue)
- */
- public boolean verifyValue( IValue value ) throws DebugException
- {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
- */
- public Object getAdapter( Class adapter )
- {
- if ( adapter.equals( ICastToType.class ) )
- return this;
- if ( adapter.equals( IVariable.class ) )
- return this;
- if ( adapter.equals( ICVariable.class ) )
- return this;
- return super.getAdapter( adapter );
- }
-
- /**
- * Returns this variable's current underlying CDI value.
- * Subclasses must implement #retrieveValue() and do not
- * need to guard against CDIException, as this method
- * handles them.
- *
- * @exception DebugException if unable to access the value
- */
- protected final ICDIValue getCurrentValue() throws DebugException
- {
- try
- {
- return retrieveValue();
- }
- catch( CDIException e )
- {
- targetRequestFailed( e.getMessage(), null );
}
return null;
}
- /**
- * Returns the last known value for this variable
- */
- protected ICDIValue getLastKnownValue()
- {
- return ( fValue instanceof CValue ) ? ((CValue)fValue).getUnderlyingValue() : null;
- }
-
- public void dispose()
- {
- if ( fValue != null )
- {
- fValue.dispose();
- }
- getCDISession().getEventManager().removeEventListener( this );
- if ( getShadow() != null )
- getShadow().dispose();
- }
-
- protected synchronized void setChanged( boolean changed ) throws DebugException
- {
- if ( getValue() != null && getValue() instanceof CValue )
- {
- fChanged = changed;
- ((CValue)getValue()).setChanged( changed );
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(ICDIEvent)
- */
- public void handleDebugEvents( ICDIEvent[] events )
- {
- for (int i = 0; i < events.length; i++)
- {
- ICDIEvent event = events[i];
- ICDIObject source = event.getSource();
- if (source == null)
- continue;
-
- if ( source.getTarget().equals( getCDITarget() ) )
- {
- if ( event instanceof ICDIChangedEvent )
- {
- if ( source instanceof ICDIVariable && isSameVariable( (ICDIVariable)source ) )
- {
- handleChangedEvent( (ICDIChangedEvent)event );
- }
- }
- else if ( event instanceof ICDIDestroyedEvent )
- {
- if ( source instanceof ICDIVariable && isSameVariable( (ICDIVariable)source ) )
- {
- handleDestroyedEvent( (ICDIDestroyedEvent)event );
- }
- }
- else if ( event instanceof ICDIResumedEvent )
- {
- handleResumedEvent( (ICDIResumedEvent)event );
- }
- }
- }
- }
-
- private void handleResumedEvent( ICDIResumedEvent event )
- {
- try
- {
- if ( getCDIVariable() instanceof ErrorVariable )
- {
- getInternalVariable().invalidate();
- setStatus( ICDebugElementStatus.OK, null );
- }
- }
- catch( CDIException e )
- {
- }
- }
-
- private void handleChangedEvent( ICDIChangedEvent event )
- {
- try
- {
- setChanged( true );
- fireChangeEvent( DebugEvent.STATE );
- }
- catch( DebugException e )
- {
- logError( e );
- }
- }
-
- private void handleDestroyedEvent( ICDIDestroyedEvent event )
- {
- if ( fOriginal != null )
- fOriginal.invalidate();
- if ( getShadow() != null )
- getShadow().invalidate();
- invalidateValue();
- }
-
- /**
- * Returns the stack frame this variable is contained in.
+ /*
+ * (non-Javadoc)
*
- * @return the stack frame
- */
- protected CDebugElement getParent()
- {
- return fParent;
- }
-
- /**
- * Returns the underlying CDI variable.
- *
- * @return the underlying CDI variable
- */
- protected ICDIVariable getCDIVariable() throws CDIException
- {
- if ( getShadow() != null )
- return getShadow().getCDIVariable();
- return getOriginalCDIVariable();
- }
-
- /**
- * Returns this variable's underlying CDI value.
- */
- protected ICDIValue retrieveValue() throws DebugException, CDIException
- {
- return ( getParent().getDebugTarget().isSuspended() && getCDIVariable() != null ) ?
- getCDIVariable().getValue() : getLastKnownValue();
- }
-
- /* (non-Javadoc)
* @see org.eclipse.debug.core.model.IVariable#getName()
*/
- public String getName() throws DebugException
- {
- if ( fName == null )
- {
- fName = ( fOriginal != null ) ? fOriginal.getCDIVariableObject().getName() : null;
- }
+ public String getName() throws DebugException {
return fName;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
*/
- public String getReferenceTypeName() throws DebugException
- {
- return ( getType() != null ) ? getType().getName() : null;
+ public String getReferenceTypeName() throws DebugException {
+ ICType type = getType();
+ return ( type != null ) ? type.getName() : null;
}
- protected void updateParentVariable( CValue parentValue ) throws DebugException
- {
- parentValue.getParentVariable().setChanged( true );
- parentValue.getParentVariable().fireChangeEvent( DebugEvent.STATE );
- }
-
- /**
- * @see org.eclipse.cdt.debug.core.model.ICVariable#getFormat()
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
*/
- public int getFormat()
- {
+ public boolean hasValueChanged() throws DebugException {
+ InternalVariable iv = getCurrentInternalVariable();
+ return ( iv != null ) ? iv.isChanged() : false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.IFormatSupport#supportsFormatting()
+ */
+ public boolean supportsFormatting() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.IFormatSupport#getFormat()
+ */
+ public CVariableFormat getFormat() {
return fFormat;
}
- /**
- * @see org.eclipse.cdt.debug.core.model.ICVariable#setFormat(int)
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.IFormatSupport#changeFormat(org.eclipse.cdt.debug.core.model.CVariableFormat)
*/
- public void setFormat( int format ) throws DebugException
- {
- doSetFormat( format );
- reset();
+ public void changeFormat( CVariableFormat format ) throws DebugException {
+ setFormat( format );
+ resetValue();
}
- protected void doSetFormat( int format )
- {
- fFormat = format;
- }
-
- protected void reset() throws DebugException
- {
- IValue value = getValue();
- if ( value instanceof CValue )
- {
- ((CValue)getValue()).reset();
- fireChangeEvent( DebugEvent.STATE );
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICastToType#cast(java.lang.String)
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.ICastToArray#canCastToArray()
*/
- public void cast( String type ) throws DebugException
- {
- try
- {
- InternalVariable newVar = createShadow( getOriginalCDIVariable().getStackFrame(), type );
- if ( getShadow() != null )
- getShadow().dispose();
- setShadow( newVar );
- }
- catch( CDIException e )
- {
- targetRequestFailed( e.getMessage(), null );
- }
- finally
- {
- invalidateValue();
- fireChangeEvent( DebugEvent.STATE );
+ public boolean canCastToArray() {
+ return ( getOriginal() != null && isEnabled() );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.ICastToArray#castToArray(int, int)
+ */
+ public void castToArray( int startIndex, int length ) throws DebugException {
+ InternalVariable newVar = getOriginal().createShadow( startIndex, length );
+ if ( getShadow() != null )
+ getShadow().dispose();
+ setShadow( newVar );
+ fireChangeEvent( DebugEvent.STATE );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
+ */
+ public void setValue( String expression ) throws DebugException {
+ InternalVariable iv = getCurrentInternalVariable();
+ if ( iv != null ) {
+ String newExpression = processExpression( expression );
+ iv.setValue( newExpression );
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
+ */
+ public void setValue( IValue value ) throws DebugException {
+ notSupported( CoreModelMessages.getString( "CVariable.3" ) ); //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
+ */
+ public boolean supportsValueModification() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
+ */
+ public boolean verifyValue( String expression ) throws DebugException {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
+ */
+ public boolean verifyValue( IValue value ) throws DebugException {
+ return value.getDebugTarget().equals( getDebugTarget() );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.ICastToType#canCast()
+ */
+ public boolean canCast() {
+ return ( getOriginal() != null && isEnabled() );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.cdt.debug.core.model.ICastToType#getCurrentType()
*/
- public String getCurrentType()
- {
- try
- {
- return getReferenceTypeName();
+ public String getCurrentType() {
+ String typeName = ""; //$NON-NLS-1$
+ try {
+ typeName = getReferenceTypeName();
}
- catch( DebugException e )
- {
- logError( e );
+ catch( DebugException e ) {
}
- return ""; //$NON-NLS-1$
+ return typeName;
}
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICastToType#restoreDefault()
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.ICastToType#cast(java.lang.String)
*/
- public void restoreDefault() throws DebugException
- {
+ public void cast( String type ) throws DebugException {
+ InternalVariable newVar = getOriginal().createShadow( type );
+ if ( getShadow() != null )
+ getShadow().dispose();
+ setShadow( newVar );
+ fireChangeEvent( DebugEvent.STATE );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.model.ICastToType#restoreOriginal()
+ */
+ public void restoreOriginal() throws DebugException {
InternalVariable oldVar = getShadow();
setShadow( null );
if ( oldVar != null )
oldVar.dispose();
- invalidateValue();
+ InternalVariable iv = getOriginal();
+ if ( iv != null )
+ iv.invalidateValue();
fireChangeEvent( DebugEvent.STATE );
}
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICastToType#supportsCasting()
- */
- public boolean supportsCasting()
- {
- CDebugTarget target = (CDebugTarget)getDebugTarget().getAdapter( CDebugTarget.class );
- return ( target != null && isEditable() );
- }
-
- protected ICDIVariable getOriginalCDIVariable() throws CDIException
- {
- return ( fOriginal != null ) ? fOriginal.getCDIVariable() : null;
- }
- protected InternalVariable getShadow()
- {
- return fShadow;
- }
-
- private void setShadow( InternalVariable shadow )
- {
- fShadow = shadow;
- }
-
- private InternalVariable createShadow( ICDIStackFrame cdiFrame, String type ) throws DebugException
- {
- try
- {
- return new InternalVariable( getCDISession().getVariableManager().getVariableObjectAsType( getOriginalCDIVariable(), type ) );
- }
- catch( CDIException e )
- {
- targetRequestFailed( e.getMessage(), null );
- }
- return null;
- }
-
- private InternalVariable createShadow( ICDIStackFrame cdiFrame, int start, int length ) throws DebugException
- {
- try
- {
- return new InternalVariable( getCDISession().getVariableManager().getVariableObjectAsArray( getCDIVariable(), start, length ) );
- }
- catch( CDIException e )
- {
- targetRequestFailed( e.getMessage(), null );
- }
- return null;
- }
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.cdt.debug.core.model.ICastToType#isCasted()
*/
- public boolean isCasted()
- {
+ public boolean isCasted() {
return ( getShadow() != null );
}
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICastToArray#castToArray(int, int)
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[])
*/
- public void castToArray( int startIndex, int length ) throws DebugException
- {
- try
- {
- InternalVariable newVar = createShadow( getOriginalCDIVariable().getStackFrame(), startIndex, length );
- if ( getShadow() != null )
- getShadow().dispose();
- setShadow( newVar );
+ public void handleDebugEvents( ICDIEvent[] events ) {
+ InternalVariable iv = getCurrentInternalVariable();
+ if ( iv == null )
+ return;
+ for( int i = 0; i < events.length; i++ ) {
+ ICDIEvent event = events[i];
+ ICDIObject source = event.getSource();
+ if ( source == null )
+ continue;
+ if ( source instanceof ICDIVariable && iv.isSameVariable( (ICDIVariable)source ) ) {
+ if ( source.getTarget().equals( getCDITarget() ) ) {
+ if ( event instanceof ICDIChangedEvent ) {
+ if ( source instanceof ICDIVariable ) {
+ handleChangedEvent( (ICDIChangedEvent)event );
+ }
+ }
+ else if ( event instanceof ICDIResumedEvent ) {
+ handleResumedEvent( (ICDIResumedEvent)event );
+ }
+ }
+ }
}
- catch( CDIException e )
- {
- targetRequestFailed( e.getMessage(), null );
+ }
+
+ private void handleResumedEvent( ICDIResumedEvent event ) {
+ boolean changed = false;
+ if ( hasErrors() ) {
+ resetStatus();
+ changed = true;
+ InternalVariable iv = getCurrentInternalVariable();
+ if ( iv != null )
+ iv.invalidateValue();
}
- finally
- {
- invalidateValue();
+ if ( changed )
+ fireChangeEvent( DebugEvent.STATE );
+ }
+
+ private void handleChangedEvent( ICDIChangedEvent event ) {
+ InternalVariable iv = getCurrentInternalVariable();
+ if ( iv != null ) {
+ iv.setChanged( true );
fireChangeEvent( DebugEvent.STATE );
}
}
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICastToArray#supportsCastToArray()
- */
- public boolean supportsCastToArray()
- {
- CDebugTarget target = (CDebugTarget)getDebugTarget().getAdapter( CDebugTarget.class );
- return ( target != null && isEditable() && hasChildren() );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICVariable#hasChildren()
- */
- public boolean hasChildren()
- {
- if ( !isEnabled() )
- return false;
- boolean result = false;
- try
- {
- InternalVariable var = getInternalVariable();
- if ( var != null )
- result = var.hasChildren();
- }
- catch( CDIException e )
- {
- logError( e );
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICVariable#isEditable()
- */
- public boolean isEditable()
- {
- if ( !isEnabled() )
- return false;
- boolean result = false;
- try
- {
- InternalVariable var = getInternalVariable();
- if ( var != null )
- result = var.isEditable();
- }
- catch( CDIException e )
- {
- logError( e );
- }
- return result;
- }
-
- protected String getQualifiedName() throws DebugException
- {
- String result = null;
- try
- {
- result = getInternalVariable().getQualifiedName();
- }
- catch( CDIException e )
- {
- requestFailed( CoreModelMessages.getString( "CVariable.4" ), e ); //$NON-NLS-1$
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICVariable#getType()
- */
- public ICType getType() throws DebugException
- {
- ICType type = null;
- if ( isEnabled() )
- {
- try
- {
- InternalVariable iv = getInternalVariable();
- if ( iv != null )
- type = iv.getType();
- }
- catch( CDIException e )
- {
- requestFailed( CoreModelMessages.getString( "CVariable.5" ), e ); //$NON-NLS-1$
- }
- }
- return type;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled()
- */
- public boolean isEnabled()
- {
- return ( canEnableDisable() ) ? fIsEnabled : true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICVariable#setEnabled(boolean)
- */
- public void setEnabled( boolean enabled ) throws DebugException
- {
- setEnabled0( enabled );
- fireChangeEvent( DebugEvent.STATE );
- }
-
- private synchronized void setEnabled0( boolean enabled )
- {
- if ( fOriginal != null )
- fOriginal.invalidate();
+ private InternalVariable getCurrentInternalVariable() {
if ( getShadow() != null )
- getShadow().invalidate();
- fIsEnabled = enabled;
- invalidateValue();
+ return getShadow();
+ return getOriginal();
}
- private void invalidateValue()
- {
- if ( fValue != null )
- {
- fValue.dispose();
- fValue = null;
- }
+ private InternalVariable getOriginal() {
+ return fOriginal;
}
- public boolean isArgument()
- {
- return ( fOriginal != null ) ? ( fOriginal.getCDIVariableObject() instanceof ICDIArgumentObject ) : false;
+ private void setOriginal( InternalVariable original ) {
+ fOriginal = original;
}
- protected boolean sameVariableObject( ICDIVariableObject object )
- {
- return ( object != null && fOriginal != null ) ? ( object.equals( fOriginal.getCDIVariableObject() ) ) : false;
+ protected CDebugElement getParent() {
+ return fParent;
}
- private boolean enableVariableBookkeeping()
- {
+ private void setParent( CDebugElement parent ) {
+ fParent = parent;
+ }
+
+ private InternalVariable getShadow() {
+ return fShadow;
+ }
+
+ private void setShadow( InternalVariable shadow ) {
+ fShadow = shadow;
+ }
+
+ private boolean isBookkeepingEnabled() {
boolean result = false;
- try
- {
+ try {
result = getLaunch().getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ENABLE_VARIABLE_BOOKKEEPING, false );
}
- catch( CoreException e )
- {
+ catch( CoreException e ) {
}
return result;
}
+ private void createOriginal( ICDIVariableObject vo ) {
+ if ( vo != null )
+ fName = vo.getName();
+ setOriginal( new InternalVariable( this, vo ) );
+ }
+
+ protected boolean hasErrors() {
+ return !isOK();
+ }
+
+ protected void setChanged( boolean changed ) {
+ InternalVariable iv = getCurrentInternalVariable();
+ if ( iv != null ) {
+ iv.setChanged( changed );
+ }
+ }
+
+ protected void resetValue() {
+ InternalVariable iv = getCurrentInternalVariable();
+ if ( iv != null ) {
+ iv.resetValue();
+ fireChangeEvent( DebugEvent.STATE );
+ }
+ }
+
+ private String processExpression( String oldExpression ) throws DebugException {
+ return oldExpression;
+ }
+
/* (non-Javadoc)
- * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable()
+ * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#dispose()
*/
- public boolean canEnableDisable()
- {
- return ( getParent() instanceof CStackFrame );
+ public void dispose() {
+ getCDISession().getEventManager().removeEventListener( this );
+ InternalVariable iv = getOriginal();
+ if ( iv != null )
+ iv.dispose();
+ iv = getShadow();
+ if ( iv != null )
+ iv.dispose();
}
- protected boolean isSameVariable( ICDIVariable cdiVar )
- {
- return ( ( getShadow() != null && getShadow().isSameVariable( cdiVar ) ) ||
- ( fOriginal != null && fOriginal.isSameVariable( cdiVar ) ) );
+ protected int sizeof() {
+ InternalVariable iv = getCurrentInternalVariable();
+ return ( iv != null ) ? iv.sizeof() : -1;
}
- private InternalVariable getInternalVariable()
- {
- return ( getShadow() != null ) ? getShadow() : fOriginal;
+ /**
+ * Compares the original internal variables.
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals( Object obj ) {
+ if ( obj instanceof CVariable ) {
+ InternalVariable iv = getOriginal();
+ return ( iv != null ) ? iv.equals( ((CVariable)obj).getOriginal() ) : false;
+ }
+ return false;
}
- protected int sizeof()
- {
- return getInternalVariable().sizeof();
+ protected boolean sameVariable( ICDIVariableObject vo ) {
+ InternalVariable iv = getOriginal();
+ return ( iv != null && iv.sameVariable( vo ) );
}
- public boolean hasErrors() {
- return ( getShadow() != null ) ? getShadow().hasErrors() : fOriginal.hasErrors();
+ protected void setFormat( CVariableFormat format ) {
+ fFormat = format;
}
-}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.model.ICVariable#getExpressionString()
+ */
+ public String getExpressionString() throws DebugException {
+ InternalVariable iv = getCurrentInternalVariable();
+ return ( iv != null ) ? iv.getQualifiedName() : null;
+ }
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariableFactory.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariableFactory.java
new file mode 100644
index 00000000000..eff9ac19218
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariableFactory.java
@@ -0,0 +1,31 @@
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.internal.core.model;
+
+import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject;
+
+/**
+ * Provides factory methods for the variable types.
+ */
+public class CVariableFactory {
+
+ public static CVariable createVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject ) {
+ return new CVariable( parent, cdiVariableObject );
+ }
+
+ public static CVariable createVariableWithError( CDebugElement parent, ICDIVariableObject cdiVariableObject, String message ) {
+ return new CVariable( parent, cdiVariableObject, message );
+ }
+
+ public static CGlobalVariable createGlobalVariable( CDebugElement parent, ICDIVariableObject cdiVariableObject ) {
+ return new CGlobalVariable( parent, cdiVariableObject );
+ }
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CoreModelMessages.properties b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CoreModelMessages.properties
index 6a523f9b673..176010dff6e 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CoreModelMessages.properties
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CoreModelMessages.properties
@@ -23,7 +23,7 @@ CThread.3=Suspend failed.
CThread.4=Step failed.
CThread.5=Step failed.
CThread.6=Step failed.
-CValue.0=not available:
+CValue.0=not available: {0}
CVariable.0=not available: {0}
CVariable.1=not available: {0}
CVariable.2=Variable does not support value modification.
diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog
index 971512d4ab6..776c7132498 100644
--- a/debug/org.eclipse.cdt.debug.ui/ChangeLog
+++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog
@@ -1,3 +1,14 @@
+2004-08-04 Mikhail Khodjaiants
+ New implementation of the variable types.
+ * CDTDebugModelPresentation.java
+ * CastToArrayActionDelegate.java
+ * CastToTypeActionDelegate.java
+ * DecVariableFormatActionDelegate.java
+ * HexVariableFormatActionDelegate.java
+ * NaturalVariableFormatActionDelegate.java
+ * RestoreDefaultTypeActionDelegate.java
+ * VariableFormatActionDelegate.java
+
2004-07-30 Mikhail Khodjaiants
Display the error message in the variable's label if the value of variable can not be retrieved.
* CDebugUIMessages.properties
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 4136a2a8619..80297716c10 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
@@ -478,6 +478,16 @@ public class CDTDebugModelPresentation extends LabelProvider implements IDebugMo
if ( valueString.length() > 0 ) {
result.append( " = " ).append( valueString ); //$NON-NLS-1$
}
+ if ( isShowVariableTypeNames() ) {
+ String type = null;
+ try {
+ type = value.getReferenceTypeName();
+ }
+ catch( DebugException e ) {
+ }
+ if ( !isEmpty( type ) )
+ result.insert( 0, type + ' ' );
+ }
}
}
if ( !expression.isEnabled() ) {
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionDelegate.java
index 62a5f10ef96..32e8d7a9683 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionDelegate.java
@@ -280,7 +280,7 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
if ( selection instanceof IStructuredSelection ) {
Object element = ((IStructuredSelection)selection).getFirstElement();
if ( element instanceof ICastToArray ) {
- boolean enabled = ((ICastToArray)element).supportsCastToArray();
+ boolean enabled = ((ICastToArray)element).canCastToArray();
action.setEnabled( enabled );
if ( enabled ) {
setCastToArray( (ICastToArray)element );
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionDelegate.java
index b5f9a891ab6..730c98e8193 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionDelegate.java
@@ -129,7 +129,7 @@ public class CastToTypeActionDelegate extends ActionDelegate implements IObjectA
if ( selection instanceof IStructuredSelection ) {
Object element = ((IStructuredSelection)selection).getFirstElement();
if ( element instanceof ICastToType ) {
- boolean enabled = ((ICastToType)element).supportsCasting();
+ boolean enabled = ((ICastToType)element).canCast();
action.setEnabled( enabled );
if ( enabled ) {
setCastToType( (ICastToType)element );
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/DecVariableFormatActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/DecVariableFormatActionDelegate.java
index dd3d7145065..c7dec1a3b09 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/DecVariableFormatActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/DecVariableFormatActionDelegate.java
@@ -10,23 +10,17 @@
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
-import org.eclipse.cdt.debug.core.cdi.ICDIFormat;
+import org.eclipse.cdt.debug.core.model.CVariableFormat;
/**
- *
- * Enter type comment.
- *
- * @since Dec 16, 2002
+ * The delegate of the "Decimal Format" action.
*/
-public class DecVariableFormatActionDelegate extends VariableFormatActionDelegate
-{
+public class DecVariableFormatActionDelegate extends VariableFormatActionDelegate {
/**
* Constructor for DecVariableFormatActionDelegate.
- * @param format
*/
- public DecVariableFormatActionDelegate()
- {
- super( ICDIFormat.DECIMAL );
+ public DecVariableFormatActionDelegate() {
+ super( CVariableFormat.DECIMAL );
}
-}
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/HexVariableFormatActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/HexVariableFormatActionDelegate.java
index ee2796fca24..d89d3df4c3e 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/HexVariableFormatActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/HexVariableFormatActionDelegate.java
@@ -10,22 +10,17 @@
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
-import org.eclipse.cdt.debug.core.cdi.ICDIFormat;
+import org.eclipse.cdt.debug.core.model.CVariableFormat;
/**
- *
- * Enter type comment.
- *
- * @since Dec 16, 2002
+ * The delegate of the "Hexadecimal Format" action.
*/
-public class HexVariableFormatActionDelegate extends VariableFormatActionDelegate
-{
+public class HexVariableFormatActionDelegate extends VariableFormatActionDelegate {
+
/**
* Constructor for HexVariableFormatActionDelegate.
- * @param format
*/
- public HexVariableFormatActionDelegate()
- {
- super( ICDIFormat.HEXADECIMAL );
+ public HexVariableFormatActionDelegate() {
+ super( CVariableFormat.HEXADECIMAL );
}
-}
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/NaturalVariableFormatActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/NaturalVariableFormatActionDelegate.java
index 7542a8a5e64..9c8e377e28a 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/NaturalVariableFormatActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/NaturalVariableFormatActionDelegate.java
@@ -10,23 +10,17 @@
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
-import org.eclipse.cdt.debug.core.cdi.ICDIFormat;
+import org.eclipse.cdt.debug.core.model.CVariableFormat;
/**
- *
- * Enter type comment.
- *
- * @since Dec 16, 2002
+ * The delegate of the "Natural Format" action.
*/
-public class NaturalVariableFormatActionDelegate extends VariableFormatActionDelegate
-{
+public class NaturalVariableFormatActionDelegate extends VariableFormatActionDelegate {
+
/**
* Constructor for NaturalVariableFormatActionDelegate.
- * @param format
*/
- public NaturalVariableFormatActionDelegate()
- {
- super( ICDIFormat.NATURAL );
+ public NaturalVariableFormatActionDelegate() {
+ super( CVariableFormat.NATURAL );
}
-
-}
+}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionDelegate.java
index c3907cac6a8..c452e53cd26 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionDelegate.java
@@ -110,6 +110,6 @@ public class RestoreDefaultTypeActionDelegate extends ActionDelegate implements
}
protected void doAction( ICastToType castToType ) throws DebugException {
- castToType.restoreDefault();
+ castToType.restoreOriginal();
}
}
\ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java
index ab33dd77dfc..213361f39c4 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java
@@ -13,7 +13,7 @@ package org.eclipse.cdt.debug.internal.ui.actions;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.cdt.debug.core.cdi.ICDIFormat;
+import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.cdt.debug.core.model.ICVariable;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.runtime.MultiStatus;
@@ -28,18 +28,18 @@ import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
/**
- * The delegate of the "Format" action.
+ * The superclass of the all format action delegates.
*/
-public class VariableFormatActionDelegate implements IObjectActionDelegate {
+public abstract class VariableFormatActionDelegate implements IObjectActionDelegate {
- private int fFormat = ICDIFormat.NATURAL;
+ private CVariableFormat fFormat = CVariableFormat.NATURAL;
private ICVariable[] fVariables = null;
/**
* Constructor for VariableFormatActionDelegate.
*/
- public VariableFormatActionDelegate( int format ) {
+ public VariableFormatActionDelegate( CVariableFormat format ) {
fFormat = format;
}
@@ -91,7 +91,7 @@ public class VariableFormatActionDelegate implements IObjectActionDelegate {
Object o = i.next();
if ( o instanceof ICVariable ) {
ICVariable var = (ICVariable)o;
- boolean enabled = var.isEditable();
+ boolean enabled = var.supportsFormatting();
action.setEnabled( enabled );
if ( enabled ) {
action.setChecked( var.getFormat() == fFormat );
@@ -109,7 +109,7 @@ public class VariableFormatActionDelegate implements IObjectActionDelegate {
protected void doAction( ICVariable[] vars ) throws DebugException {
for( int i = 0; i < vars.length; i++ ) {
- vars[i].setFormat( fFormat );
+ vars[i].changeFormat( fFormat );
}
}