1 19 20 21 22 package org.netbeans.modules.debugger.jpda.expr; 23 24 import java.util.*; 25 26 class SimpleNode implements Node { 27 protected Node parent; 28 protected Node[] children; 29 protected int id; 30 31 public SimpleNode(int i) { 32 id = i; 33 } 34 35 public void jjtOpen() { 36 } 37 38 public void jjtClose() { 39 } 40 41 public void jjtSetParent(Node n) { parent = n; } 42 public Node jjtGetParent() { return parent; } 43 44 public void jjtAddChild(Node n, int i) { 45 if (children == null) { 46 children = new Node[i + 1]; 47 } else if (i >= children.length) { 48 Node c[] = new Node[i + 1]; 49 System.arraycopy(children, 0, c, 0, children.length); 50 children = c; 51 } 52 children[i] = n; 53 } 54 55 public Node jjtGetChild(int i) { 56 return children[i]; 57 } 58 59 public int jjtGetNumChildren() { 60 return (children == null) ? 0 : children.length; 61 } 62 63 64 public Object jjtAccept(JavaParserVisitor visitor, Object data) { 65 return visitor.visit(this, data); 66 } 67 68 73 74 public String toString() { return JavaParserTreeConstants.jjtNodeName[id]; } 75 public String toString(String prefix) { return prefix + toString(); } 76 77 79 80 public void dump(String prefix) { 81 System.out.println(toString(prefix)); 82 if (children != null) { 83 for (int i = 0; i < children.length; ++i) { 84 SimpleNode n = (SimpleNode)children[i]; 85 if (n != null) { 86 n.dump(prefix + " "); 87 } 88 } 89 } 90 } 91 92 95 private Map<String , Object > attributes; 96 98 public Object [] getAttributes(String name) { 99 if (attributes == null) return null; 100 List attrs = getAttributeList(name); 101 return attrs.toArray(); 102 } 103 104 public void addAttribute(String name, Object value) { 105 getAttributeList(name).add(value); 106 } 107 108 public void setAttribute(String name, Object value) { 109 getAttributeMap().put(name, value); 110 } 111 112 public Object getAttribute(String name) { 113 return (attributes == null) ? null : attributes.get(name); 114 } 115 116 private Map<String , Object > getAttributeMap() { 117 if (attributes == null) { 118 attributes = new HashMap<String , Object >(); 119 } 120 return attributes; 121 } 122 123 private List<Object > getAttributeList(String name) { 124 getAttributeMap(); 125 List<Object > list = (List<Object >) attributes.get(name); 126 if (list == null) { 127 list = new ArrayList<Object >(); 128 attributes.put(name, list); 129 } 130 return list; 131 } 132 133 public int jjtGetID() { 134 return id; 135 } 136 } 137 138 | Popular Tags |