1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 453920: Remove code duplication between MIVar and MIVarCreateInfo.

Change-Id: I1c291fa235fe77910b6bea7ad98f269d8949fc5c
Signed-off-by: Vladimir Prus <vladimir@codesourcery.com>
Reviewed-on: https://git.eclipse.org/r/37475
Tested-by: Hudson CI
This commit is contained in:
Vladimir Prus 2014-12-02 21:01:06 +03:00
parent 84add6a4bd
commit 7aa9cf6efc
3 changed files with 32 additions and 50 deletions

View file

@ -8,13 +8,16 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Wind River Systems - Modified for new DSF Reference Implementation * Wind River Systems - Modified for new DSF Reference Implementation
* Vladimir Prus (Mentor Graphics) - Add getMIValue. * Vladimir Prus (Mentor Graphics) - Add getMIFields/getMIField.
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.output; package org.eclipse.cdt.dsf.mi.service.command.output;
/** /**
* GDB/MI ResultRecord. * GDB/MI ResultRecord.
*
* Effectively, it's an result class (a string), plus token (also a string),
* plus MI tuple with actual response.
*/ */
public class MIResultRecord { public class MIResultRecord {
@ -46,6 +49,13 @@ public class MIResultRecord {
resultClass = type; resultClass = type;
} }
/** Return all data fields of this record as MITuple
* @since 4.6
*/
public MITuple getFields() {
return value;
}
public MIResult[] getMIResults() { public MIResult[] getMIResults() {
return value.getMIResults(); return value.getMIResults();
} }

View file

@ -28,6 +28,7 @@ public class MIVar {
String name = ""; //$NON-NLS-1$ String name = ""; //$NON-NLS-1$
String type = ""; //$NON-NLS-1$ String type = ""; //$NON-NLS-1$
String value = ""; //$NON-NLS-1$
String exp = ""; //$NON-NLS-1$ String exp = ""; //$NON-NLS-1$
private boolean isDynamic = false; private boolean isDynamic = false;
int numchild; int numchild;
@ -89,6 +90,13 @@ public class MIVar {
return type; return type;
} }
/**
* @since 4.6
*/
public String getValue() {
return value;
}
/** /**
* @return Whether the value and children of this variable are provided * @return Whether the value and children of this variable are provided
* by a pretty printer. * by a pretty printer.
@ -142,7 +150,7 @@ public class MIVar {
MIValue value = results[i].getMIValue(); MIValue value = results[i].getMIValue();
String str = ""; //$NON-NLS-1$ String str = ""; //$NON-NLS-1$
if (value != null && value instanceof MIConst) { if (value != null && value instanceof MIConst) {
str = ((MIConst)value).getCString(); str = ((MIConst)value).getString();
} }
if (var.equals("numchild")) { //$NON-NLS-1$ if (var.equals("numchild")) { //$NON-NLS-1$
@ -154,6 +162,8 @@ public class MIVar {
name = str; name = str;
} else if (var.equals("type")) { //$NON-NLS-1$ } else if (var.equals("type")) { //$NON-NLS-1$
type = str; type = str;
} else if (var.equals("value")) { //$NON-NLS-1$
this.value = str;
} else if (var.equals("exp")) { //$NON-NLS-1$ } else if (var.equals("exp")) { //$NON-NLS-1$
exp = str; exp = str;
} else if (var.equals("dynamic") && str.trim().equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$ } else if (var.equals("dynamic") && str.trim().equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -25,56 +25,21 @@ package org.eclipse.cdt.dsf.mi.service.command.output;
*/ */
public class MIVarCreateInfo extends MIInfo { public class MIVarCreateInfo extends MIInfo {
String name = ""; //$NON-NLS-1$ private MIVar child;
int numChild;
String type = ""; //$NON-NLS-1$
MIVar child;
String value = null;
private boolean isDynamic = false;
private boolean hasMore = false;
private MIDisplayHint displayHint = MIDisplayHint.NONE;
public MIVarCreateInfo(MIOutput record) { public MIVarCreateInfo(MIOutput record) {
super(record); super(record);
if (isDone()) { if (isDone()) {
MIOutput out = getMIOutput(); MIResultRecord rr = getMIOutput().getMIResultRecord();
MIResultRecord rr = out.getMIResultRecord();
if (rr != null) { if (rr != null) {
MIResult[] results = rr.getMIResults(); child = new MIVar(rr.getFields());
for (int i = 0; i < results.length; i++) {
String var = results[i].getVariable();
MIValue resultVal = results[i].getMIValue();
String str = ""; //$NON-NLS-1$
if (resultVal instanceof MIConst) {
str = ((MIConst)resultVal).getString();
}
if (var.equals("name")) { //$NON-NLS-1$
name = str;
} else if (var.equals("numchild")) { //$NON-NLS-1$
try {
numChild = Integer.parseInt(str.trim());
} catch (NumberFormatException e) {
}
} else if (var.equals("type")) { //$NON-NLS-1$
type = str;
} else if (var.equals("value")) { //$NON-NLS-1$
value = str;
} else if (var.equals("dynamic") && str.trim().equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$
isDynamic = true;
} else if (var.equals("has_more") && str.trim().equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$
hasMore = true;
} else if (var.equals("displayhint")) { //$NON-NLS-1$
displayHint = new MIDisplayHint(str);
}
}
} }
} }
} }
public String getType() public String getType()
{ {
return type; return child.getType();
} }
/** /**
@ -84,7 +49,7 @@ public class MIVarCreateInfo extends MIInfo {
* @since 4.0 * @since 4.0
*/ */
public boolean isDynamic() { public boolean isDynamic() {
return isDynamic; return child.isDynamic();
} }
/** /**
@ -95,7 +60,7 @@ public class MIVarCreateInfo extends MIInfo {
*/ */
public int getNumChildren() public int getNumChildren()
{ {
return numChild; return child.getNumChild();
} }
/** /**
@ -107,17 +72,17 @@ public class MIVarCreateInfo extends MIInfo {
* @since 4.0 * @since 4.0
*/ */
public boolean hasMore() { public boolean hasMore() {
return hasMore; return child.hasMore();
} }
public String getName() public String getName()
{ {
return name; return child.getVarName();
} }
public String getValue() public String getValue()
{ {
return value; return child.getValue();
} }
/** /**
@ -127,13 +92,10 @@ public class MIVarCreateInfo extends MIInfo {
* @since 4.0 * @since 4.0
*/ */
public MIDisplayHint getDisplayHint() { public MIDisplayHint getDisplayHint() {
return displayHint; return child.getDisplayHint();
} }
public MIVar getMIVar() { public MIVar getMIVar() {
if (child == null) {
child = new MIVar(name, isDynamic, numChild, hasMore, type, displayHint);
}
return child; return child;
} }
} }