diff options
| author | Ovidiu Buligan | 2013-04-18 11:44:49 +0000 |
|---|---|---|
| committer | Johan Compagner | 2013-04-25 11:56:03 +0000 |
| commit | 4a3985e5a691ff4ffc17b9a548b20baa212e5c1b (patch) | |
| tree | f7fa99c7268325e983e1cdb7d9684e50eac69782 | |
| parent | fb1490666ba02fc4174c31027bd5c82df112f035 (diff) | |
| download | org.eclipse.dltk.javascript-4a3985e5a691ff4ffc17b9a548b20baa212e5c1b.tar.gz org.eclipse.dltk.javascript-4a3985e5a691ff4ffc17b9a548b20baa212e5c1b.tar.xz org.eclipse.dltk.javascript-4a3985e5a691ff4ffc17b9a548b20baa212e5c1b.zip | |
nicer formatting of IScriptType when the value of a IVariable is a
IScriptValue (nested toString)
| -rw-r--r-- | plugins/org.eclipse.dltk.javascript.debug/src/org/eclipse/dltk/javascript/internal/debug/JavaScriptTypeFactory.java | 60 |
1 files changed, 52 insertions, 8 deletions
diff --git a/plugins/org.eclipse.dltk.javascript.debug/src/org/eclipse/dltk/javascript/internal/debug/JavaScriptTypeFactory.java b/plugins/org.eclipse.dltk.javascript.debug/src/org/eclipse/dltk/javascript/internal/debug/JavaScriptTypeFactory.java index 4d8eb76b..a7975bfd 100644 --- a/plugins/org.eclipse.dltk.javascript.debug/src/org/eclipse/dltk/javascript/internal/debug/JavaScriptTypeFactory.java +++ b/plugins/org.eclipse.dltk.javascript.debug/src/org/eclipse/dltk/javascript/internal/debug/JavaScriptTypeFactory.java @@ -14,6 +14,12 @@ import org.eclipse.dltk.debug.core.model.StringScriptType; public class JavaScriptTypeFactory implements IScriptTypeFactory { private static final String[] atomicTypes = { "number", "boolean", "date" }; + private static final ThreadLocal<Integer> detailsLevel = new ThreadLocal<Integer>() { + protected Integer initialValue() { + return Integer.valueOf(0); + } + }; + public JavaScriptTypeFactory() { } @@ -26,7 +32,28 @@ public class JavaScriptTypeFactory implements IScriptTypeFactory { } if ("javaarray".equals(type) || "array".equals(type)) { - return new ArrayScriptType(); + return new ArrayScriptType() { + protected String buildDetailString(IVariable variable) + throws DebugException { + Integer currentLevel = detailsLevel.get(); + detailsLevel + .set(Integer.valueOf(currentLevel.intValue() + 1)); + try { + if (variable.getValue() instanceof IScriptValue + && currentLevel.intValue() < 2) { + IScriptValue value = (IScriptValue) variable + .getValue(); + return value.getType().formatDetails(value); + } + return super.buildDetailString(variable); + } finally { + currentLevel = detailsLevel.get(); + detailsLevel.set(Integer.valueOf(currentLevel + .intValue() - 1)); + } + + } + }; } if ("string".equals(type)) { @@ -49,27 +76,44 @@ public class JavaScriptTypeFactory implements IScriptTypeFactory { */ public String formatDetails(IScriptValue value) { StringBuffer sb = new StringBuffer(); - sb.append(value.getRawValue()); - String id = value.getInstanceId(); - if (id != null) { - sb.append(" (id = " + id + ")"); - } + Integer currentLevel = detailsLevel.get(); + detailsLevel.set(Integer.valueOf(currentLevel.intValue() + 1)); try { IVariable[] variables = value.getVariables(); if (variables.length > 0) { - sb.append(" {"); + sb.append("{"); for (int i = 0; i < variables.length; i++) { sb.append(variables[i].getName()); sb.append(":"); - sb.append(variables[i].getValue().getValueString()); + if (variables[i].getValue() instanceof IScriptValue) { + if (currentLevel.intValue() < 2) { + IScriptValue sv = (IScriptValue) variables[i] + .getValue(); + sb.append(sv.getType().formatDetails(sv)); + } else + sb.append("{...}"); + } else { + sb.append(variables[i].getValue() + .getValueString()); + } sb.append(","); } sb.setLength(sb.length() - 1); sb.append("}"); + } else { + sb.append(value.getRawValue()); + String id = value.getInstanceId(); + if (id != null) { + sb.append(" (id = " + id + ")"); + } } } catch (DebugException ex) { DLTKDebugPlugin.logWarning( "error creating variable details", ex); + } finally { + currentLevel = detailsLevel.get(); + detailsLevel + .set(Integer.valueOf(currentLevel.intValue() - 1)); } return sb.toString(); } |
