1 19 20 package org.netbeans.modules.junit.output; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.List ; 25 import org.openide.nodes.Children; 26 import org.openide.nodes.Node; 27 import static org.netbeans.modules.junit.output.RegexpUtils.NESTED_EXCEPTION_PREFIX; 28 29 33 final class TestMethodNodeChildren extends Children.Array { 34 35 36 private final Report.Testcase testcase; 37 38 39 public TestMethodNodeChildren(final Report.Testcase testcase) { 40 this.testcase = testcase; 41 } 42 43 45 protected void addNotify() { 46 Report.Trouble trouble = testcase.trouble; 47 48 int nodesCount = 1; if (trouble.message != null) { 50 nodesCount++; 51 } 52 if (trouble.stackTrace != null) { 53 nodesCount += trouble.stackTrace.length; 54 } 55 56 String topFrameInfo = (trouble.stackTrace != null) 57 && (trouble.stackTrace.length != 0) 58 ? trouble.stackTrace[0] 59 : null; 60 61 Node[] children = new Node[nodesCount]; 62 int index = 0; 63 if (trouble.message != null) { 64 children[index++] = new CallstackFrameNode(topFrameInfo, 65 trouble.message); 66 } 67 children[index++] = new CallstackFrameNode(topFrameInfo, 68 trouble.exceptionClsName); 69 for (int i = 0; index < nodesCount; i++) { 70 children[index++] = new CallstackFrameNode(trouble.stackTrace[i]); 71 } 72 73 if (trouble.nestedTrouble != null) { 74 List <Node> childrenList = new ArrayList <Node>(nodesCount * 3); 75 childrenList.addAll(Arrays.asList(children)); 76 77 trouble = trouble.nestedTrouble; 78 do { 79 String [] stackTrace = trouble.stackTrace; 80 topFrameInfo = (stackTrace != null) && (stackTrace.length != 0) 81 ? stackTrace[0] 82 : null; 83 StringBuilder topNodeDispName = new StringBuilder (200); 84 topNodeDispName.append(NESTED_EXCEPTION_PREFIX); 85 topNodeDispName.append(trouble.exceptionClsName); 86 if (trouble.message != null) { 87 topNodeDispName.append(": ") .append(trouble.message); 89 } 90 childrenList.add(new CallstackFrameNode(topFrameInfo, 91 topNodeDispName.toString())); 92 if (stackTrace != null) { 93 for (String frameInfo : stackTrace) { 94 childrenList.add(new CallstackFrameNode(frameInfo)); 95 } 96 } 97 } while ((trouble = trouble.nestedTrouble) != null); 98 99 children = childrenList.toArray(new Node[childrenList.size()]); 100 } 101 102 add(children); 103 } 104 105 107 protected void removeNotify() { 108 remove(getNodes()); 109 } 110 111 } 112 | Popular Tags |