1 2 25 26 package org.aspectj.asm; 27 28 import java.util.*; 29 import java.io.*; 30 31 37 public abstract class StructureNode implements Serializable, Comparable { 38 39 protected StructureNode parent = null; 40 protected String name = ""; 41 protected String kind = ""; 42 protected List children = new ArrayList(); 43 protected StructureMessage message = null; 44 protected SourceLocation sourceLocation = null; 45 46 49 public StructureNode() { } 50 51 public StructureNode(String name, String kind, List children) { 52 this.name = name; 53 this.kind = kind; 54 if (children != null) { 55 this.children = children; 56 } 57 setParents(); 58 } 59 60 public StructureNode(String name, String kind) { 61 this.name = name; 62 this.kind = kind; 63 } 64 65 public String toString() { 66 return name; 67 } 68 69 public String getKind() { 70 return kind; 71 } 72 73 public List getChildren() { 74 return children; 75 } 76 77 public void addChild(StructureNode child) { 78 if (children == null) { 79 children = new ArrayList(); 80 } 81 children.add(child); 82 child.setParent(this); 83 } 84 85 public boolean removeChild(StructureNode child) { 86 child.setParent(null); 87 return children.remove(child); 88 } 89 90 public StructureNode walk(ModelWalker walker) { 91 for (Iterator it = children.iterator(); it.hasNext(); ) { 92 StructureNode child = (StructureNode)it.next(); 93 walker.process(child); 94 } 95 return this; 96 } 97 98 110 113 public int compareTo(Object o) throws ClassCastException { 114 if (this == o) { 115 return 0; 116 } else { 117 StructureNode sn = (StructureNode)o; 118 return this.getName().compareTo(sn.getName()); 119 } 120 } 121 122 public String getName() { 123 return name; 124 } 125 126 public SourceLocation getSourceLocation() { 127 return sourceLocation; 128 } 129 130 public void setSourceLocation(SourceLocation sourceLocation) { 131 this.sourceLocation = sourceLocation; 132 } 133 134 public StructureMessage getMessage() { 135 return message; 136 } 137 138 public void setMessage(StructureMessage message) { 139 this.message = message; 140 } 141 142 public StructureNode getParent() { 143 return parent; 144 } 145 146 public void setParent(StructureNode parent) { 147 this.parent = parent; 148 } 149 150 private void setParents() { 151 if (children == null) return; 152 for (Iterator it = children.iterator(); it.hasNext(); ) { 153 ((StructureNode)it.next()).setParent(this); 154 } 155 } 156 } 169 170 171 183 237 238 | Popular Tags |