| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
| 3 * | 3 * |
| 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
| 5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
| 6 * | 6 * |
| 7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
| 8 * | 8 * |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 public Node(String label) { | 34 public Node(String label) { |
| 35 this.label = label; | 35 this.label = label; |
| 36 } | 36 } |
| 37 | 37 |
| 38 public void addChild(Node child) { | 38 public void addChild(Node child) { |
| 39 child.setParent(this); | 39 child.setParent(this); |
| 40 | 40 |
| 41 children.add(child); | 41 children.add(child); |
| 42 } | 42 } |
| 43 | 43 |
| 44 @Override | |
| 45 public boolean equals(Object obj) { | |
| 46 if (obj == null) { | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 if (this.getClass().isAssignableFrom(obj.getClass())) { | |
| 51 Node other = (Node) obj; | |
| 52 | |
| 53 return safeEquals(getId(), other.getId()); | |
| 54 } else { | |
| 55 return false; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 public List<Node> getChildren() { | 44 public List<Node> getChildren() { |
| 60 return children; | 45 return children; |
| 61 } | 46 } |
| 62 | 47 |
| 63 public Token getEndToken() { | 48 public Token getEndToken() { |
| 64 return endToken; | 49 return endToken; |
| 65 } | 50 } |
| 66 | 51 |
| 67 public String getId() { | |
| 68 if (parent == null) { | |
| 69 return label; | |
| 70 } else { | |
| 71 return parent.getId() + "." + label; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 public String getLabel() { | 52 public String getLabel() { |
| 76 return label; | 53 return label; |
| 77 } | 54 } |
| 78 | 55 |
| 79 public Node getParent() { | 56 public Node getParent() { |
| 80 return parent; | 57 return parent; |
| 81 } | 58 } |
| 82 | 59 |
| 83 public Token getStartToken() { | 60 public Token getStartToken() { |
| 84 return startToken; | 61 return startToken; |
| 85 } | 62 } |
| 86 | 63 |
| 87 @Override | |
| 88 public int hashCode() { | |
| 89 return getId().hashCode(); | |
| 90 } | |
| 91 | |
| 92 public void setEnd(Token t) { | 64 public void setEnd(Token t) { |
| 93 this.endToken = t; | 65 this.endToken = t; |
| 94 } | 66 } |
| 95 | 67 |
| 96 public void setParent(Node parent) { | 68 public void setParent(Node parent) { |
| 97 this.parent = parent; | 69 this.parent = parent; |
| 98 } | 70 } |
| 99 | 71 |
| 100 public void setStart(Token t) { | 72 public void setStart(Token t) { |
| 101 this.startToken = t; | 73 this.startToken = t; |
| 102 } | 74 } |
| 103 | 75 |
| 104 @Override | 76 @Override |
| 105 public String toString() { | 77 public String toString() { |
| 106 return getLabel(); | 78 return getLabel(); |
| 107 } | 79 } |
| 108 | 80 |
| 109 private boolean safeEquals(String id, String id2) { | |
| 110 if (id == id2) { | |
| 111 return true; | |
| 112 } | |
| 113 | |
| 114 if (id == null) { | |
| 115 return false; | |
| 116 } | |
| 117 | |
| 118 return id.equals(id2); | |
| 119 } | |
| 120 | |
| 121 } | 81 } |
| OLD | NEW |