mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Bug 315677: The getNumChildren() method was not actually used and was causing some inefficiency, so we deprecate it in favor of hasChildren() and getSubExpressionCount(). Also fix the JUnit tests accordingly.
This commit is contained in:
parent
566aba5c1d
commit
ba0437069d
4 changed files with 54 additions and 90 deletions
|
@ -325,7 +325,17 @@ public class MIExpressions extends AbstractDsfService implements IExpressions3,
|
|||
// which refers to the full name, including parent structure.
|
||||
private final String relativeExpression;
|
||||
private final String exprType;
|
||||
private final int numChildren;
|
||||
|
||||
/**
|
||||
* A hint at the number of children.
|
||||
* In the case of C++ complex structures, this number will not be the
|
||||
* actual number of children. This is because GDB considers
|
||||
* 'private/protected/public' as an actual level of children, but
|
||||
* we do not. This number is meant to be used to know if the expression
|
||||
* has children at all.
|
||||
*/
|
||||
private final int numChildrenHint;
|
||||
|
||||
private final boolean editable;
|
||||
private final BasicType fBasicType;
|
||||
|
||||
|
@ -343,7 +353,7 @@ public class MIExpressions extends AbstractDsfService implements IExpressions3,
|
|||
public ExpressionDMData(String expr, String type, int num, boolean edit, BasicType basicType) {
|
||||
relativeExpression = expr;
|
||||
exprType = type;
|
||||
numChildren = num;
|
||||
numChildrenHint = num;
|
||||
editable = edit;
|
||||
fBasicType = basicType;
|
||||
}
|
||||
|
@ -381,8 +391,25 @@ public class MIExpressions extends AbstractDsfService implements IExpressions3,
|
|||
return exprType;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method only returns a 'hint' to the number of children.
|
||||
* In the case of C++ complex structures, this number will not be the
|
||||
* actual number of children. This is because GDB considers
|
||||
* 'private/protected/public' as an actual level of children, but
|
||||
* we do not.
|
||||
*
|
||||
* This method can be used reliably to know if the expression
|
||||
* does have children or not. However, for this particular use,
|
||||
* the new {@link IExpressionDMDataExtension#hasChildren()} method should be used instead.
|
||||
*
|
||||
* To get the correct number of children of an expression, a call
|
||||
* to {@link IExpressions#getSubExpressionCount} should be used.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public int getNumChildren() {
|
||||
return numChildren;
|
||||
return numChildrenHint;
|
||||
}
|
||||
|
||||
public boolean isEditable() {
|
||||
|
@ -393,14 +420,14 @@ public class MIExpressions extends AbstractDsfService implements IExpressions3,
|
|||
* @since 3.1
|
||||
*/
|
||||
public boolean hasChildren() {
|
||||
return getNumChildren() > 0;
|
||||
return numChildrenHint > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof ExpressionDMData) {
|
||||
ExpressionDMData otherData = (ExpressionDMData) other;
|
||||
return (getNumChildren() == otherData.getNumChildren()) &&
|
||||
return (numChildrenHint == otherData.numChildrenHint) &&
|
||||
(getTypeName() == null ? otherData.getTypeName() == null : getTypeName().equals(otherData.getTypeName())) &&
|
||||
(getName() == null ? otherData.getName() == null : getName().equals(otherData.getName()));
|
||||
}
|
||||
|
@ -410,12 +437,12 @@ public class MIExpressions extends AbstractDsfService implements IExpressions3,
|
|||
@Override
|
||||
public int hashCode() {
|
||||
return relativeExpression == null ? 0 : relativeExpression.hashCode() +
|
||||
exprType == null ? 0 : exprType.hashCode() + numChildren;
|
||||
exprType == null ? 0 : exprType.hashCode() + numChildrenHint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "relExpr=" + relativeExpression + ", type=" + exprType + ", numchildren=" + numChildren; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
|
||||
return "relExpr=" + relativeExpression + ", type=" + exprType + ", numchildren=" + numChildrenHint; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1655,6 +1655,9 @@ public class MIVariableManager implements ICommandControl {
|
|||
drm.setData(
|
||||
new ExprMetaGetVarInfo(
|
||||
exprCtx.getRelativeExpression(),
|
||||
// We only provide the hint here. It will be used for hasChildren()
|
||||
// To obtain the correct number of children, the user should use
|
||||
// IExpressions#getSubExpressionCount()
|
||||
getData().getNumChildrenHint(),
|
||||
getData().getType(),
|
||||
getData().getGDBType(),
|
||||
|
|
|
@ -10,13 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.dsf.mi.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
|
||||
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMData;
|
||||
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMData.BasicType;
|
||||
import org.eclipse.cdt.dsf.debug.service.IRegisters.IRegisterDMContext;
|
||||
import org.eclipse.cdt.dsf.mi.service.MIExpressions.ExpressionDMData;
|
||||
import org.eclipse.cdt.dsf.mi.service.MIExpressions.MIExpressionDMC;
|
||||
|
||||
public class ClassAccessor {
|
||||
|
@ -51,69 +45,4 @@ public class ClassAccessor {
|
|||
return miExprDmc.getRelativeExpression();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExpressionDMDataAccessor {
|
||||
private ExpressionDMData miExprData;
|
||||
|
||||
public ExpressionDMDataAccessor(IExpressionDMData data) {
|
||||
miExprData = (ExpressionDMData) data;
|
||||
}
|
||||
|
||||
public BasicType getBasicType() {
|
||||
return miExprData.getBasicType();
|
||||
}
|
||||
|
||||
public String getEncoding() {
|
||||
return miExprData.getEncoding();
|
||||
}
|
||||
|
||||
public Map<String, Integer> getEnumerations() {
|
||||
return miExprData.getEnumerations();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return miExprData.getName();
|
||||
}
|
||||
|
||||
public IRegisterDMContext getRegister() {
|
||||
return miExprData.getRegister();
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return miExprData.getStringValue();
|
||||
}
|
||||
|
||||
public String getTypeId() {
|
||||
return miExprData.getTypeId();
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return miExprData.getTypeName();
|
||||
}
|
||||
|
||||
public int getNumChildren() {
|
||||
return miExprData.getNumChildren();
|
||||
}
|
||||
|
||||
public boolean isEditable() {
|
||||
return miExprData.isEditable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return miExprData.equals(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return miExprData.hashCode();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return miExprData.toString();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,18 +22,18 @@ import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
|
|||
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
|
||||
import org.eclipse.cdt.dsf.datamodel.IDMContext;
|
||||
import org.eclipse.cdt.dsf.debug.service.IExpressions;
|
||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
|
||||
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionChangedDMEvent;
|
||||
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMAddress;
|
||||
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
|
||||
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMData;
|
||||
import org.eclipse.cdt.dsf.debug.service.IExpressions3.IExpressionDMDataExtension;
|
||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
|
||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext;
|
||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData;
|
||||
import org.eclipse.cdt.dsf.debug.service.IRunControl.StepType;
|
||||
import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext;
|
||||
import org.eclipse.cdt.dsf.mi.service.MIExpressions;
|
||||
import org.eclipse.cdt.dsf.mi.service.ClassAccessor.ExpressionDMDataAccessor;
|
||||
import org.eclipse.cdt.dsf.mi.service.ClassAccessor.MIExpressionDMCAccessor;
|
||||
import org.eclipse.cdt.dsf.mi.service.MIExpressions;
|
||||
import org.eclipse.cdt.dsf.mi.service.command.events.MIStoppedEvent;
|
||||
import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
|
||||
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
|
||||
|
@ -341,13 +341,11 @@ public class MIExpressionsTest extends BaseTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* This test makes sure we get the right number of children.
|
||||
* This test makes sure we get can tell if an expression has children
|
||||
* based on the expression data.
|
||||
*/
|
||||
@Test
|
||||
public void testChildrenCountInExpressionData() throws Throwable {
|
||||
// Next we test that we can retrieve children count while reading the
|
||||
// value and vice-versa
|
||||
|
||||
public void testHasChildrenInExpressionData() throws Throwable {
|
||||
SyncUtil.runToLocation("testChildren");
|
||||
MIStoppedEvent stoppedEvent = SyncUtil.step(1, StepType.STEP_OVER);
|
||||
|
||||
|
@ -368,11 +366,18 @@ public class MIExpressionsTest extends BaseTestCase {
|
|||
if (!isSuccess()) {
|
||||
wait.waitFinished(getStatus());
|
||||
} else {
|
||||
ExpressionDMDataAccessor data = new ExpressionDMDataAccessor(getData());
|
||||
int count = data.getNumChildren();
|
||||
if (count != 5) {
|
||||
if ((getData() instanceof IExpressionDMDataExtension) == false) {
|
||||
wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID,
|
||||
"Failed getting count for children. Got " + count + " instead of 5", null));
|
||||
"Did not a receive an IExpressionDMDataExtension", null));
|
||||
return;
|
||||
}
|
||||
|
||||
IExpressionDMDataExtension data = (IExpressionDMDataExtension)getData();
|
||||
|
||||
boolean hasChildren = data.hasChildren();
|
||||
if (!hasChildren) {
|
||||
wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID,
|
||||
"No children were found, when we expected to find some", null));
|
||||
} else {
|
||||
wait.waitFinished();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue