diff --git a/src/main/java/io/kaitai/struct/visualizer/DataNode.java b/src/main/java/io/kaitai/struct/visualizer/DataNode.java index 5a5cde9..def2cd3 100644 --- a/src/main/java/io/kaitai/struct/visualizer/DataNode.java +++ b/src/main/java/io/kaitai/struct/visualizer/DataNode.java @@ -26,6 +26,10 @@ public DataNode(int depth, Object value, String name) { this(depth, value, null, name, null, null); } + private DataNode(int depth, Object value, String name, Integer posStart, Integer posEnd) { + this(depth, value, null, name, posStart, posEnd); + } + private DataNode(int depth, Object value, Method method, Integer posStart, Integer posEnd) { this(depth, value, method, null, posStart, posEnd); } @@ -134,7 +138,16 @@ protected List doInBackground() throws Exception { Object el = list.get(i); String arrayIdxStr = String.format("%04d", i); - children.add(new DataNode(depth + 1, el, arrayIdxStr)); + DataNode parentNode = (DataNode) parent; + if (parentNode.value instanceof KaitaiStruct) { + KaitaiStruct parentKaitaiStruct = (KaitaiStruct) parentNode.value; + DebugAids debug = DebugAids.fromStruct(parentKaitaiStruct); + Integer posStart = debug.getArrayStart(name, i); + Integer posEnd = debug.getArrayEnd(name, i); + children.add(new DataNode(depth + 1, el, arrayIdxStr, posStart, posEnd)); + } else { + children.add(new DataNode(depth + 1, el, arrayIdxStr)); + } } } else if (value instanceof KaitaiStruct) { DebugAids debug = DebugAids.fromStruct((KaitaiStruct) value); @@ -155,8 +168,8 @@ protected List doInBackground() throws Exception { field.setAccessible(true); Object curValue = field.get(value); - Integer posStart = debug.getStart(methodName); - Integer posEnd = debug.getEnd(methodName); + Integer posStart = debug.getAttrStart(methodName); + Integer posEnd = debug.getAttrEnd(methodName); DataNode dn = new DataNode(depth + 1, curValue, m, posStart, posEnd); children.add(dn); diff --git a/src/main/java/io/kaitai/struct/visualizer/DebugAids.java b/src/main/java/io/kaitai/struct/visualizer/DebugAids.java index 3da451a..934d1b6 100644 --- a/src/main/java/io/kaitai/struct/visualizer/DebugAids.java +++ b/src/main/java/io/kaitai/struct/visualizer/DebugAids.java @@ -24,21 +24,21 @@ private DebugAids( this.arrEnd = arrEnd; } - public Integer getStart(String attrName) { + public Integer getAttrStart(String attrName) { return attrStart.get(attrName); } - public Integer getEnd(String attrName) { + public Integer getAttrEnd(String attrName) { return attrEnd.get(attrName); } - public Integer getStart(String attrName, int idx) { - ArrayList positions = arrStart.get(attrName); + public Integer getArrayStart(String arrName, int idx) { + ArrayList positions = arrStart.get(arrName); return (positions != null) ? positions.get(idx) : null; } - public Integer getEnd(String attrName, int idx) { - ArrayList positions = arrEnd.get(attrName); + public Integer getArrayEnd(String arrName, int idx) { + ArrayList positions = arrEnd.get(arrName); return (positions != null) ? positions.get(idx) : null; }